From 67b7e8553d1d105f4b9ecbe768baa2425a7ae629 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Mon, 28 Jul 2025 11:45:06 -0700 Subject: [PATCH 1/6] Fix test and pin exact versions --- .github/workflows/mocha.yml | 6 +- test/integration/plugins/root-hooks.spec.js | 62 ++++++++++++++++++++- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/.github/workflows/mocha.yml b/.github/workflows/mocha.yml index 02e9d2770a..78d6663460 100644 --- a/.github/workflows/mocha.yml +++ b/.github/workflows/mocha.yml @@ -66,9 +66,9 @@ jobs: coverage: false with: os: 'ubuntu-latest,windows-latest' - # The 20.18.3 is instead of 20 per https://github.com/mochajs/mocha/issues/5052 - # The 22.11.0 is instead of 22 per https://github.com/mochajs/mocha/issues/5278 - node-versions: '18,20.18.3,22.11.0' + # We pin exact versions per https://github.com/mochajs/mocha/issues/5052 + # Ref https://nodejs.org/en/about/previous-releases + node-versions: '18.20.8,20.19.4,22.17.1,24.4.1' npm-script: test-node:${{ matrix.test-part }} coverage: ${{ matrix.coverage }} diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index 597575b474..69adf98e45 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -136,7 +136,23 @@ describe('root hooks', function () { }); describe('support ESM via .js extension w/o type=module', function () { - describe('should fail due to ambiguous file type', function () { + // --(no-)experimental-detect-module was experimental when these tests were written + // https://nodejs.org/api/cli.html#--no-experimental-detect-module + // https://nodejs.org/api/packages.html#syntax-detection + // (introduced in Node 21.1.0, 20.10.0) + // newer versions of Node no longer fail :) + function isNewerVersion(vString) { + return (vString > 'v20.18.3' || vString > 'v22.11.0' || vString >= 'v24.0.0'); + } + + describe('on older versions, should fail due to ambiguous file type', function () { + // --(no-)experimental-detect-module was experimental when these tests were written + // (introduced in Node 21.1.0, 20.10.0) + // newer versions of Node no longer fail :) + if (isNewerVersion(process.version)) { + return true; // skip test on newer Node versions + } + const filename = '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js'; const noDetectModuleRegex = /SyntaxError: Unexpected token/; @@ -158,7 +174,8 @@ describe('root hooks', function () { }); it('with --experimental-detect-module', function () { - // --experimental-detect-module was introduced in Node 21.1.0 + // --experimental-detect-module was introduced in Node 21.1.0, 20.10.0 + // adding the flag to older versions of Node does nothing const expectedRegex = process.version >= 'v21.1.0' ? detectModuleRegex @@ -177,6 +194,47 @@ describe('root hooks', function () { ); }); }); + + describe('on newer versions, should work', function () { + if (!isNewerVersion(process.version)) { + return true; // skip test on older Node versions + } + + const filename = + '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js'; + const runSuccessRegex = /0 passing/; + + it('with --no-experimental-detect-module', function () { + return expect( + invokeMochaAsync( + [ + '--require=' + require.resolve(filename), // as object + '--no-experimental-detect-module' + ], + 'pipe' + )[1], + 'when fulfilled', + 'to contain output', + runSuccessRegex + ); + }); + + it('with --experimental-detect-module', function () { + return expect( + invokeMochaAsync( + [ + '--require=' + require.resolve(filename), // as object + // enabled by default in these newer versions, but clearer to use it explicitly + '--experimental-detect-module' + ], + 'pipe' + )[1], + 'when fulfilled', + 'to contain output', + runSuccessRegex + ); + }); + }); }); }); From 26e7056eb5a37f7384b4816118ad3de5b44bd130 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Mon, 28 Jul 2025 12:05:08 -0700 Subject: [PATCH 2/6] Fix version detection function --- .github/workflows/mocha.yml | 6 +++--- test/integration/plugins/root-hooks.spec.js | 12 +++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mocha.yml b/.github/workflows/mocha.yml index aefe25dad6..0d2e1fad4c 100644 --- a/.github/workflows/mocha.yml +++ b/.github/workflows/mocha.yml @@ -23,8 +23,7 @@ jobs: smoke: uses: ./.github/workflows/npm-script.yml with: - # The 22.11.0 is instead of lts per https://github.com/mochajs/mocha/issues/5278 - node-versions: '18,20,22.11.0,24' + node-versions: '18,20,22,24' npm-script: test-smoke test-node-lts: @@ -66,7 +65,8 @@ jobs: coverage: false with: os: 'ubuntu-latest,windows-latest' - # We pin exact versions per https://github.com/mochajs/mocha/issues/5052 + # We pin exact versions here per https://github.com/mochajs/mocha/issues/5052 + # LTS is tested in a previous step # Ref https://nodejs.org/en/about/previous-releases node-versions: '18.20.8,20.19.4,22.17.1,24.4.1' npm-script: test-node:${{ matrix.test-part }} diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index 69adf98e45..a23bd95e18 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -142,14 +142,20 @@ describe('root hooks', function () { // (introduced in Node 21.1.0, 20.10.0) // newer versions of Node no longer fail :) function isNewerVersion(vString) { - return (vString > 'v20.18.3' || vString > 'v22.11.0' || vString >= 'v24.0.0'); + // Latest versions considered "older": 22.11.0, 20.18.3, 18.20.8 + // (May update after writing) + return ( + (vString.startsWith('20') && vString > '20.18.3') || + (vString.startsWith('22') && vString > '22.11.0') || + (vString.startsWith('24')) + ); } describe('on older versions, should fail due to ambiguous file type', function () { // --(no-)experimental-detect-module was experimental when these tests were written // (introduced in Node 21.1.0, 20.10.0) // newer versions of Node no longer fail :) - if (isNewerVersion(process.version)) { + if (isNewerVersion(process.versions.node)) { return true; // skip test on newer Node versions } @@ -196,7 +202,7 @@ describe('root hooks', function () { }); describe('on newer versions, should work', function () { - if (!isNewerVersion(process.version)) { + if (!isNewerVersion(process.versions.node)) { return true; // skip test on older Node versions } From 512388fe84e2e92e98e025164af0e9f765b235e6 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Mon, 28 Jul 2025 14:33:41 -0700 Subject: [PATCH 3/6] Pin Node 22 to 22.11.0 --- .github/workflows/mocha.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mocha.yml b/.github/workflows/mocha.yml index 0d2e1fad4c..dab978b653 100644 --- a/.github/workflows/mocha.yml +++ b/.github/workflows/mocha.yml @@ -23,7 +23,8 @@ jobs: smoke: uses: ./.github/workflows/npm-script.yml with: - node-versions: '18,20,22,24' + # The 22.11.0 is instead of 22 per https://github.com/mochajs/mocha/issues/5278 + node-versions: '18,20,22.11.0,24' npm-script: test-smoke test-node-lts: @@ -66,9 +67,10 @@ jobs: with: os: 'ubuntu-latest,windows-latest' # We pin exact versions here per https://github.com/mochajs/mocha/issues/5052 + # The 22.11.0 is instead of 22 per https://github.com/mochajs/mocha/issues/5278 # LTS is tested in a previous step # Ref https://nodejs.org/en/about/previous-releases - node-versions: '18.20.8,20.19.4,22.17.1,24.4.1' + node-versions: '18.20.8,20.19.4,22.11.0,24.4.1' npm-script: test-node:${{ matrix.test-part }} coverage: ${{ matrix.coverage }} From cc85e0cd3386ef2a1a644a391ab973fd5935ea50 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Mon, 28 Jul 2025 15:48:40 -0700 Subject: [PATCH 4/6] Downgrade Node 20, unpin Node 22 --- .github/workflows/mocha.yml | 8 +++----- .github/workflows/npm-script.yml | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/mocha.yml b/.github/workflows/mocha.yml index dab978b653..ff515df11d 100644 --- a/.github/workflows/mocha.yml +++ b/.github/workflows/mocha.yml @@ -23,8 +23,7 @@ jobs: smoke: uses: ./.github/workflows/npm-script.yml with: - # The 22.11.0 is instead of 22 per https://github.com/mochajs/mocha/issues/5278 - node-versions: '18,20,22.11.0,24' + node-versions: '18,20,22,24' npm-script: test-smoke test-node-lts: @@ -67,10 +66,9 @@ jobs: with: os: 'ubuntu-latest,windows-latest' # We pin exact versions here per https://github.com/mochajs/mocha/issues/5052 - # The 22.11.0 is instead of 22 per https://github.com/mochajs/mocha/issues/5278 - # LTS is tested in a previous step + # Use 20.18.3 per https://github.com/mochajs/mocha/issues/5278 # Ref https://nodejs.org/en/about/previous-releases - node-versions: '18.20.8,20.19.4,22.11.0,24.4.1' + node-versions: '18.20.8,20.18.3,22.17.1,24.4.1' npm-script: test-node:${{ matrix.test-part }} coverage: ${{ matrix.coverage }} diff --git a/.github/workflows/npm-script.yml b/.github/workflows/npm-script.yml index 8409b870f4..941a01f24e 100644 --- a/.github/workflows/npm-script.yml +++ b/.github/workflows/npm-script.yml @@ -54,8 +54,7 @@ jobs: strategy: fail-fast: false matrix: - # The 22.11.0 is instead of "lts/*" per https://github.com/mochajs/mocha/issues/5278 - node_version: ${{ fromJson(needs.resolve-inputs.outputs.nodeVersions || '["22.11.0"]') }} + node_version: ${{ fromJson(needs.resolve-inputs.outputs.nodeVersions || '["22"]') }} os: ${{ fromJson(needs.resolve-inputs.outputs.os || '["ubuntu-latest"]') }} browser: ${{ fromJson(needs.resolve-inputs.outputs.browsers || '[""]') }} steps: From 197649928c8acdabaf2572d91181ee6bd23dcf6f Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Tue, 5 Aug 2025 17:23:31 -0700 Subject: [PATCH 5/6] Use semver for Node version detecting --- package-lock.json | 13 +++++++------ package.json | 1 + test/integration/plugins/root-hooks.spec.js | 7 ++----- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 28166dd90a..34d95f0232 100644 --- a/package-lock.json +++ b/package-lock.json @@ -83,6 +83,7 @@ "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-polyfill-node": "^0.8.0", "rollup-plugin-visualizer": "^5.6.0", + "semver": "^7.7.2", "sinon": "^9.0.3", "unexpected": "^11.14.0", "unexpected-eventemitter": "^2.2.0", @@ -14194,9 +14195,9 @@ } }, "node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", "dev": true, "license": "ISC", "bin": { @@ -27632,9 +27633,9 @@ } }, "semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", + "integrity": "sha512-RF0Fw+rO5AMf9MAyaRXI4AV0Ulj5lMHqVxxdSgiVbixSCXoEmmX/jk0CuJw4+3SqroYO9VoUh+HcuJivvtJemA==", "dev": true }, "semver-compare": { diff --git a/package.json b/package.json index 76a48bdf35..79d402c418 100644 --- a/package.json +++ b/package.json @@ -166,6 +166,7 @@ "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-polyfill-node": "^0.8.0", "rollup-plugin-visualizer": "^5.6.0", + "semver": "^7.7.2", "sinon": "^9.0.3", "unexpected": "^11.14.0", "unexpected-eventemitter": "^2.2.0", diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index a23bd95e18..708921080a 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -1,6 +1,7 @@ 'use strict'; var invokeMochaAsync = require('../helpers').invokeMochaAsync; +const semver = require('semver'); /** * Extracts root hook log messages from run results @@ -144,11 +145,7 @@ describe('root hooks', function () { function isNewerVersion(vString) { // Latest versions considered "older": 22.11.0, 20.18.3, 18.20.8 // (May update after writing) - return ( - (vString.startsWith('20') && vString > '20.18.3') || - (vString.startsWith('22') && vString > '22.11.0') || - (vString.startsWith('24')) - ); + return semver.satisfies(vString, '^20.19.0 || ^22.12.0 || ^24.0.0'); } describe('on older versions, should fail due to ambiguous file type', function () { From f320d6189082adf9932aec2e0c2246c3e28c05d3 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Mon, 11 Aug 2025 18:53:22 -0700 Subject: [PATCH 6/6] Clarify comments to be in ascending Node version order --- test/integration/plugins/root-hooks.spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index 708921080a..e9dd1fd9f7 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -140,17 +140,17 @@ describe('root hooks', function () { // --(no-)experimental-detect-module was experimental when these tests were written // https://nodejs.org/api/cli.html#--no-experimental-detect-module // https://nodejs.org/api/packages.html#syntax-detection - // (introduced in Node 21.1.0, 20.10.0) + // (introduced in Node 20.10.0, 21.1.0) // newer versions of Node no longer fail :) function isNewerVersion(vString) { - // Latest versions considered "older": 22.11.0, 20.18.3, 18.20.8 + // Latest versions considered "older": 18.20.8, 20.18.3, 22.11.0 // (May update after writing) return semver.satisfies(vString, '^20.19.0 || ^22.12.0 || ^24.0.0'); } describe('on older versions, should fail due to ambiguous file type', function () { // --(no-)experimental-detect-module was experimental when these tests were written - // (introduced in Node 21.1.0, 20.10.0) + // (introduced in Node 20.10.0, 21.1.0) // newer versions of Node no longer fail :) if (isNewerVersion(process.versions.node)) { return true; // skip test on newer Node versions @@ -177,7 +177,7 @@ describe('root hooks', function () { }); it('with --experimental-detect-module', function () { - // --experimental-detect-module was introduced in Node 21.1.0, 20.10.0 + // --experimental-detect-module was introduced in Node 20.10.0, 21.1.0 // adding the flag to older versions of Node does nothing const expectedRegex = process.version >= 'v21.1.0'