Skip to content

Commit

Permalink
Replace Jest with Node test framework (#97)
Browse files Browse the repository at this point in the history
* Convert tests to Node test framework

* Make the tests run (despite nodejs/node#50287)

* Remove Jest

* Drop old Node 14
  • Loading branch information
robatwilliams authored Jan 30, 2024
1 parent ca10780 commit 15b259f
Show file tree
Hide file tree
Showing 22 changed files with 1,184 additions and 10,008 deletions.
19 changes: 1 addition & 18 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
"parserOptions": {
"ecmaVersion": 2022
},
"settings": {
"jest": {
// Auto-detection not working in monorepo structure
// https://github.com/jest-community/eslint-plugin-jest/issues/686#issuecomment-706452934
"version": 27
}
},
"env": {
"es2021": true,
"node": true
Expand Down Expand Up @@ -80,15 +73,5 @@
// eslint-plugin-import - Selection from the ones that are compatible with CommonJS
"import/no-extraneous-dependencies": "error",
"import/order": ["error", { "newlines-between": "never" }]
},
"overrides": [
{
"files": "*.spec.js",
"extends": ["plugin:jest/recommended", "plugin:jest/style"],
"plugins": ["jest"],
"rules": {
// TODO more jest plugin rules - https://github.com/jest-community/eslint-plugin-jest
}
}
]
}
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"eslint": "^8.56.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jest": "^25.3.4",
"eslint-plugin-n": "^15.7.0",
"lerna": "^4.0.0",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/check-es-compat/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/check-es-compat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"eslint-plugin-ecmascript-compat": "^3.2.0"
},
"engines": {
"node": "^14.18.0 || >=16.0.0"
"node": ">=16.0.0"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const assert = require('node:assert');
const { test } = require('node:test');
const compareVersions = require('./compareVersions');

test('equal', () => {
assert.strictEqual(compareVersions('1.2.3', '1.2.3'), 0);
});

test('smaller', () => {
assert.strictEqual(compareVersions('1.2.0', '1.2.3'), -1);
assert.strictEqual(compareVersions('1.2', '1.3'), -1);
});

test('larger', () => {
assert.strictEqual(compareVersions('1.2.3', '1.2.0'), 1);
});

test('partial on one side', () => {
assert.strictEqual(compareVersions('1.1', '1.2.3'), -1);
assert.strictEqual(compareVersions('1.1.1', '1.2'), -1);
});

test('when it matters to treat parts as numbers', () => {
assert.strictEqual(compareVersions('9', '10'), -1);
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable camelcase */
const assert = require('node:assert');
const { it } = require('node:test');
const { unsupportedFeatures } = require('./compatibility');
const features = require('./features');

Expand All @@ -16,7 +18,7 @@ it('supports feature in version introduced', () => {
};

const unsupported = unsupportedFeatures([feature], [{ name: 'chrome', version: '73' }]);
expect(unsupported).toHaveLength(0);
assert.deepStrictEqual(unsupported, []);
});

it('supports feature in version later than introduced, treating versions as numbers', () => {
Expand All @@ -36,7 +38,7 @@ it('supports feature in version later than introduced, treating versions as numb
[feature],
[{ name: 'safari', version: '14.0' }]
);
expect(unsupported).toHaveLength(0);
assert.deepStrictEqual(unsupported, []);
});

it('doesnt support feature in version before introduced', () => {
Expand All @@ -53,7 +55,7 @@ it('doesnt support feature in version before introduced', () => {
};

const unsupported = unsupportedFeatures([feature], [{ name: 'chrome', version: '72' }]);
expect(unsupported[0]).toBe(feature);
assert.strictEqual(unsupported[0], feature);
});

it('supports feature supported by family in unknown version', () => {
Expand All @@ -70,7 +72,7 @@ it('supports feature supported by family in unknown version', () => {
};

const unsupported = unsupportedFeatures([feature], [{ name: 'chrome', version: '73' }]);
expect(unsupported).toHaveLength(0);
assert.deepStrictEqual(unsupported, []);
});

it('doesnt support feature not supported in any version of family', () => {
Expand All @@ -87,7 +89,7 @@ it('doesnt support feature not supported in any version of family', () => {
};

const unsupported = unsupportedFeatures([feature], [{ name: 'chrome', version: '73' }]);
expect(unsupported[0]).toBe(feature);
assert.strictEqual(unsupported[0], feature);
});

it('supports feature with unknown support by family', () => {
Expand All @@ -104,7 +106,7 @@ it('supports feature with unknown support by family', () => {
};

const unsupported = unsupportedFeatures([feature], [{ name: 'chrome', version: '73' }]);
expect(unsupported).toHaveLength(0);
assert.deepStrictEqual(unsupported, []);
});

it('supports feature with omitted support entry for mobile target', () => {
Expand All @@ -124,7 +126,7 @@ it('supports feature with omitted support entry for mobile target', () => {
[feature],
[{ name: 'chrome_android', version: '73' }]
);
expect(unsupported).toHaveLength(0);
assert.deepStrictEqual(unsupported, []);
});

it('doesnt support feature supported by one target but not another', () => {
Expand All @@ -148,7 +150,7 @@ it('doesnt support feature supported by one target but not another', () => {
{ name: 'firefox', version: '50' },
]
);
expect(unsupported[0]).toBe(feature);
assert.strictEqual(unsupported[0], feature);
});

it('uses primary support record where multiple ones exist', () => {
Expand Down Expand Up @@ -179,13 +181,13 @@ it('uses primary support record where multiple ones exist', () => {
[feature],
[{ name: 'nodejs', version: '7.0.0' }]
);
expect(primaryUnsupported).toHaveLength(0);
assert.deepStrictEqual(primaryUnsupported, []);

const secondaryUnsupported = unsupportedFeatures(
[feature],
[{ name: 'nodejs', version: '6.7.0' }]
);
expect(secondaryUnsupported[0]).toBe(feature);
assert.deepStrictEqual(secondaryUnsupported[0], feature);
});

it('explains what the problem is when compat feature not found in MDN data', () => {
Expand All @@ -211,9 +213,10 @@ it('explains what the problem is when compat feature not found in MDN data', ()
],
};

expect(() => {
unsupportedFeatures([feature], [{ name: 'chrome', version: '73' }]);
}).toThrow("Sparse compatFeatures for rule 'some rule': object,undefined");
assert.throws(
() => unsupportedFeatures([feature], [{ name: 'chrome', version: '73' }]),
{ message: "Sparse compatFeatures for rule 'some rule': object,undefined" }
);
});

it('can rely on all the versions in the compatibility data used being semver or partial semver', () => {
Expand All @@ -229,8 +232,8 @@ it('can rely on all the versions in the compatibility data used being semver or
: supportStatement;

if (simpleSupportStatement.version_added !== false) {
// eslint-disable-next-line jest/no-conditional-expect
expect(simpleSupportStatement.version_added).toMatch(
assert.match(
simpleSupportStatement.version_added,
/\d+(?<minor>\.\d+(?<patch>\.\d+)?)?/u
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 46';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 53';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 59';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 65';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 62';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 74';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 71';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { RuleTester } = require('eslint');

// Browser that doesn't support any features of this version - see es-versions.md
process.env.BROWSERSLIST = 'Chrome >= 73';
jest.resetModules();

const ruleTester = new RuleTester({
parserOptions: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const assert = require('node:assert');
const { test } = require('node:test');
const features = require('./features');
const rule = require('./rule');

Expand All @@ -7,5 +9,5 @@ test('polyfills accepted in the schema exactly match those supported', () => {
feature.polyfill ? [feature.polyfill] : []
);

expect(schemaPolyfills.sort()).toEqual(supportedPolyfills.sort());
assert.deepStrictEqual(schemaPolyfills.sort(), supportedPolyfills.sort());
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const assert = require('node:assert');
const { beforeEach, it } = require('node:test');
const browserslist = require('browserslist');
const targetRuntimes = require('./targetRuntimes');

Expand All @@ -9,38 +11,38 @@ beforeEach(() => {
it('targets the oldest version of each family', () => {
process.env.BROWSERSLIST = 'Chrome >= 50';

expect(targetRuntimes()).toEqual([{ name: 'chrome', version: '50' }]);
assert.deepStrictEqual(targetRuntimes(), [{ name: 'chrome', version: '50' }]);
});

it('targets the oldest version of each family, treating versions as numbers', () => {
process.env.BROWSERSLIST = 'chrome 9-10';

expect(targetRuntimes()).toEqual([{ name: 'chrome', version: '9' }]);
assert.deepStrictEqual(targetRuntimes(), [{ name: 'chrome', version: '9' }]);
});

it('maps browserslist names to mdn names where necessary', () => {
process.env.BROWSERSLIST = 'Android >= 0';

expect(targetRuntimes()).toEqual([{ name: 'webview_android', version: '2.1' }]);
assert.deepStrictEqual(targetRuntimes(), [{ name: 'webview_android', version: '2.1' }]);
});

it('discards families unknown to mdn', () => {
process.env.BROWSERSLIST = 'kaios >= 0';

expect(targetRuntimes()).toEqual([]);
assert.deepStrictEqual(targetRuntimes(), []);
});

it('handles multiple families', () => {
process.env.BROWSERSLIST = 'Firefox >= 55,IE >= 10';

expect(targetRuntimes()).toEqual([
assert.deepStrictEqual(targetRuntimes(), [
{ name: 'firefox', version: '55' },
{ name: 'ie', version: '10' },
]);
});

it('accepts a override', () => {
expect(targetRuntimes('Firefox >= 55,IE >= 10')).toEqual([
assert.deepStrictEqual(targetRuntimes('Firefox >= 55,IE >= 10'), [
{ name: 'firefox', version: '55' },
{ name: 'ie', version: '10' },
]);
Expand All @@ -49,13 +51,13 @@ it('accepts a override', () => {
it('preserves versions as strings to allow semver', () => {
process.env.BROWSERSLIST = 'Node >= 0';

expect(targetRuntimes()).toEqual([{ name: 'nodejs', version: '0.2.0' }]);
assert.deepStrictEqual(targetRuntimes(), [{ name: 'nodejs', version: '0.2.0' }]);
});

it('simplifies version ranges to the start of the range', () => {
expect(browserslist('iOS 15')).toEqual(['ios_saf 15.0-15.1']);
assert.deepStrictEqual(browserslist('iOS 15'), ['ios_saf 15.0-15.1']);

process.env.BROWSERSLIST = 'iOS 15';

expect(targetRuntimes()).toEqual([{ name: 'safari_ios', version: '15.0' }]);
assert.deepStrictEqual(targetRuntimes(), [{ name: 'safari_ios', version: '15.0' }]);
});
Loading

0 comments on commit 15b259f

Please sign in to comment.