Skip to content

Commit

Permalink
switch source to ESM, migrate off Jest to UVU, drop Node 16
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek committed Jan 21, 2024
1 parent e3a3540 commit a55fa11
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 2,756 deletions.
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"plugins": ["jest", "prettier"],
"extends": [
"eslint:recommended",
"plugin:jest/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
pull-requests: write
steps:
- name: '🚚 Checkout'
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: '🔏 Yarn Lock Changes'
uses: ./
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [16, 18, 20]
node: [18, 20, 21]
name: Testing on Node ${{ matrix.node }}
steps:
- name: '🚚 Checkout'
Expand Down
3 changes: 0 additions & 3 deletions babel.config.js

This file was deleted.

6 changes: 3 additions & 3 deletions dist/index.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions jest.config.js

This file was deleted.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "ncc build ./src/action.js -m --target es2021",
"lint": "eslint .",
"optimize": "svgo -f ./assets",
"test": "jest"
"test": "uvu tests -i .cjs -i testUtils"
},
"dependencies": {
"@actions/core": "^1.10.1",
Expand All @@ -19,17 +19,14 @@
"semver": "^7.5.4"
},
"devDependencies": {
"@babel/core": "^7.23.7",
"@babel/preset-env": "^7.23.8",
"@vercel/ncc": "^0.38.1",
"@yarnpkg/lockfile": "^1.1.0",
"babel-jest": "^29.7.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.4",
"svgo": "^3.2.0"
"svgo": "^3.2.0",
"uvu": "^0.5.6"
}
}
16 changes: 8 additions & 8 deletions src/action.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { debug, getBooleanInput, getInput, setFailed, warning } = require('@actions/core');
const { context, getOctokit } = require('@actions/github');
const fs = require('fs');
const { Base64 } = require('js-base64');
const path = require('path');

const { STATUS, countStatuses, diffLocks, parseLock } = require('./utils');
const { createTable, createSummary } = require('./comment');
import { debug, getBooleanInput, getInput, setFailed, warning } from '@actions/core';
import { context, getOctokit } from '@actions/github';
import { Base64 } from 'js-base64';
import fs from 'node:fs';
import path from 'node:path';

import { createTable, createSummary } from './comment.mjs';
import { STATUS, countStatuses, diffLocks, parseLock } from './utils.mjs';

const getCommentId = async (octokit, oktokitParams, issueNumber, commentHeader) => {
const currentComments = await octokit.rest.issues.listComments({
Expand Down
4 changes: 2 additions & 2 deletions src/comment.js → src/comment.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { markdownTable } = require('markdown-table');
import { markdownTable }from 'markdown-table';

const { STATUS_ORDER, countStatuses } = require('./utils');
import { STATUS_ORDER, countStatuses } from './utils.mjs';

const ASSETS_URL = {
ADDED: 'https://git.io/J38HP',
Expand Down
8 changes: 4 additions & 4 deletions src/utils.js → src/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { warning } = require('@actions/core');
import { warning } from '@actions/core';

const semverCompare = require('semver/functions/compare');
const semverCoerce = require('semver/functions/coerce');
const semverValid = require('semver/functions/valid');
import semverCompare from 'semver/functions/compare.js';
import semverCoerce from 'semver/functions/coerce.js';
import semverValid from 'semver/functions/valid.js';

export const STATUS = {
ADDED: 'ADDED',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const lockfile = require('@yarnpkg/lockfile');
import lockfile from '@yarnpkg/lockfile';
import { test } from 'uvu';
import { is } from 'uvu/assert';

const { getTestLockContent } = require('../testUtils');
const { parseLock } = require('../../src/utils');
import { getTestLockContent } from '../testUtils.mjs';
import { parseLock }from '../../src/utils.mjs';

test('naive performance test', () => {
const contentA = getTestLockContent('classic-downgrade', 'a.lock');
Expand All @@ -25,5 +27,7 @@ test('naive performance test', () => {
const internalEnd = performance.now();
console.timeEnd('Internal parser');

expect(end - start).toBeGreaterThan(internalEnd - internalStart);
is((end - start) > (internalEnd - internalStart), true);
});

test.run();
File renamed without changes.
62 changes: 0 additions & 62 deletions tests/unit/unit.test.js

This file was deleted.

63 changes: 63 additions & 0 deletions tests/unit/unit.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { test } from 'uvu';
import { is } from 'uvu/assert';

import { diffLocks, STATUS, countStatuses, parseLock } from '../../src/utils.mjs';
import { getTestLockContent } from '../testUtils.mjs';

test('Yarn Classic - detect changes', () => {
const contentA = getTestLockContent('classic-downgrade', 'a.lock');
const contentB = getTestLockContent('classic-downgrade', 'b.lock');

const result = diffLocks(parseLock(contentA), parseLock(contentB));

is(Object.keys(result).length, 52);

is(countStatuses(result, STATUS.ADDED), 3);
is(countStatuses(result, STATUS.UPDATED), 49);
is(countStatuses(result, STATUS.DOWNGRADED), 0);
is(countStatuses(result, STATUS.REMOVED), 0);
});

test('Yarn Classic - no downgrade detected, multiple cases', () => {
const contentA = getTestLockContent('classic-downgrade-complex', 'a.lock');
const contentB = getTestLockContent('classic-downgrade-complex', 'b.lock');

const result = diffLocks(parseLock(contentA), parseLock(contentB));

is(Object.keys(result).length, 389);

is(countStatuses(result, STATUS.ADDED), 357);
is(countStatuses(result, STATUS.UPDATED), 32);
is(countStatuses(result, STATUS.DOWNGRADED), 0);
is(countStatuses(result, STATUS.REMOVED), 0);
});

test('Yarn Berry (v2) - detect changes', () => {
const contentA = getTestLockContent('berry-v2', 'a.lock');
const contentB = getTestLockContent('berry-v2', 'b.lock');

const result = diffLocks(parseLock(contentA), parseLock(contentB));

is(Object.keys(result).length, 6);

is(countStatuses(result, STATUS.ADDED), 1);
is(countStatuses(result, STATUS.UPDATED), 4);
is(countStatuses(result, STATUS.DOWNGRADED), 0);
is(countStatuses(result, STATUS.REMOVED), 1);
});

test('Yarn Berry (v3) - detect changes', () => {
const contentA = getTestLockContent('berry-v3', 'a.lock');
const contentB = getTestLockContent('berry-v3', 'b.lock');

const result = diffLocks(parseLock(contentA), parseLock(contentB));

is(Object.keys(result).length, 7);

is(countStatuses(result, STATUS.ADDED), 1);
is(countStatuses(result, STATUS.UPDATED), 5);
is(countStatuses(result, STATUS.DOWNGRADED), 0);
is(countStatuses(result, STATUS.REMOVED), 1);
});

test.run();
Loading

0 comments on commit a55fa11

Please sign in to comment.