☕️ Classic, reliable, trusted test framework for Node.js and the browser
chore: Update experimental module detection test and pin exact Node versions (#5417)
Mark Wiemer2489090223f2
diff --git a/.github/workflows/mocha.yml b/.github/workflows/mocha.ymlindex 52ba0703..ff515df1 100644--- a/.github/workflows/mocha.yml+++ b/.github/workflows/mocha.yml@@ -23,8 +23,7 @@ jobs:smoke:uses: ./.github/workflows/npm-script.ymlwith:- # 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-smoketest-node-lts:@@ -66,9 +65,10 @@ jobs:coverage: falsewith: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,24'+ # We pin exact versions here per https://github.com/mochajs/mocha/issues/5052+ # 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.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.ymlindex 76b5ac14..ed163371 100644--- a/.github/workflows/npm-script.yml+++ b/.github/workflows/npm-script.yml@@ -54,8 +54,7 @@ jobs:strategy:fail-fast: falsematrix:- # 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:diff --git a/package-lock.json b/package-lock.jsonindex 28166dd9..34d95f02 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.jsonindex 76a48bdf..79d402c4 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.jsindex 597575b4..e9dd1fd9 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@@ -136,7 +137,25 @@ 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 20.10.0, 21.1.0)+ // newer versions of Node no longer fail :)+ function isNewerVersion(vString) {+ // 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 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+ }+const filename ='../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js';const noDetectModuleRegex = /SyntaxError: Unexpected token/;@@ -158,7 +177,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 20.10.0, 21.1.0+ // adding the flag to older versions of Node does nothingconst expectedRegex =process.version >= 'v21.1.0'? detectModuleRegex@@ -177,6 +197,47 @@ describe('root hooks', function () {);});});++ describe('on newer versions, should work', function () {+ if (!isNewerVersion(process.versions.node)) {+ 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+ );+ });+ });});});