Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix test and pin exact versions
  • Loading branch information
mark-wiemer committed Jul 28, 2025
commit 67b7e8553d1d105f4b9ecbe768baa2425a7ae629
6 changes: 3 additions & 3 deletions .github/workflows/mocha.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
62 changes: 60 additions & 2 deletions test/integration/plugins/root-hooks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/;
Expand All @@ -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
Expand All @@ -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
);
});
});
});
});

Expand Down