diff --git a/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.spec.js index ae63de1..9ee1fa6 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/compareVersions.spec.js @@ -1,23 +1,25 @@ +const assert = require('node:assert'); +const { test } = require('node:test'); const compareVersions = require('./compareVersions'); test('equal', () => { - expect(compareVersions('1.2.3', '1.2.3')).toBe(0); + assert.strictEqual(compareVersions('1.2.3', '1.2.3'), 0); }); test('smaller', () => { - expect(compareVersions('1.2.0', '1.2.3')).toBe(-1); - expect(compareVersions('1.2', '1.3')).toBe(-1); + assert.strictEqual(compareVersions('1.2.0', '1.2.3'), -1); + assert.strictEqual(compareVersions('1.2', '1.3'), -1); }); test('larger', () => { - expect(compareVersions('1.2.3', '1.2.0')).toBe(1); + assert.strictEqual(compareVersions('1.2.3', '1.2.0'), 1); }); test('partial on one side', () => { - expect(compareVersions('1.1', '1.2.3')).toBe(-1); - expect(compareVersions('1.1.1', '1.2')).toBe(-1); + 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', () => { - expect(compareVersions('9', '10')).toBe(-1); + assert.strictEqual(compareVersions('9', '10'), -1); }); diff --git a/packages/eslint-plugin-ecmascript-compat/lib/compatibility.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/compatibility.spec.js index 246da18..7fcc958 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/compatibility.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/compatibility.spec.js @@ -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'); @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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', () => { @@ -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+(?\.\d+(?\.\d+)?)?/u ); } diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.spec.js index b36540d..353f162 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2016.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.spec.js index a99a318..2dccf83 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2017.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.spec.js index 165e392..b69d4a7 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2018.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.spec.js index fbf0bb3..78240f0 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2019.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.spec.js index d590e45..b24d386 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2020.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.spec.js index d728392..a507fba 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2021.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.spec.js index e5b78db..9f24d7e 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2022.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.spec.js index 162136a..7000294 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/features/es2023.spec.js @@ -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: { diff --git a/packages/eslint-plugin-ecmascript-compat/lib/rule.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/rule.spec.js index 12240cf..3c757cd 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/rule.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/rule.spec.js @@ -1,3 +1,5 @@ +const assert = require('node:assert'); +const { test } = require('node:test'); const features = require('./features'); const rule = require('./rule'); @@ -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()); }); diff --git a/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.spec.js b/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.spec.js index 0df93b1..f9dbe20 100644 --- a/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.spec.js +++ b/packages/eslint-plugin-ecmascript-compat/lib/targetRuntimes.spec.js @@ -1,3 +1,5 @@ +const assert = require('node:assert'); +const { beforeEach, it } = require('node:test'); const browserslist = require('browserslist'); const targetRuntimes = require('./targetRuntimes'); @@ -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' }, ]); @@ -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' }]); });