From 846d5a30c5950d2ce77197e768b45e4dbfe39937 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 09:26:41 -0700 Subject: [PATCH 1/8] Fix npm scripts on Windows --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index ad8cf1fa3f..7ad4ce69f1 100644 --- a/package.json +++ b/package.json @@ -50,12 +50,12 @@ "docs:api": "jsdoc -c jsdoc.conf.json", "docs:site": "eleventy", "docs": "run-s docs-clean docs:*", - "format:eslint": "eslint --fix . 'bin/*'", - "format:prettier": "prettier --write '!(package*).json' '.*.json' 'lib/**/*.json' '*.yml'", + "format:eslint": "eslint --fix . bin/*", + "format:prettier": "prettier --write !(package*).json .*.json lib/**/*.json *.yml", "format": "run-s format:*", "lint:knip": "knip --cache", - "lint:code": "eslint . 'bin/*' --max-warnings 0", - "lint:markdown": "markdownlint '*.md' 'docs/**/*.md' '.github/*.md' 'lib/**/*.md' 'test/**/*.md' 'example/**/*.md' -i CHANGELOG.md", + "lint:code": "eslint . bin/* --max-warnings 0", + "lint:markdown": "markdownlint *.md docs/**/*.md .github/*.md lib/**/*.md test/**/*.md example/**/*.md -i CHANGELOG.md", "lint": "run-p lint:*", "prepublishOnly": "run-s clean build", "test-browser-run": "cross-env NODE_PATH=. karma start ./karma.conf.js --single-run", @@ -70,7 +70,7 @@ "test-coverage-generate": "nyc report --reporter=lcov --reporter=text", "test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js", "test-node-run": "nyc --no-clean --reporter=json node bin/mocha.js --forbid-only", - "test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 'test/integration/**/*.spec.js'", + "test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 test/integration/**/*.spec.js", "test-node:interfaces:bdd": "npm run -s test-node-run -- --ui bdd test/interfaces/bdd.spec", "test-node:interfaces:exports": "npm run -s test-node-run -- --ui exports test/interfaces/exports.spec", "test-node:interfaces:qunit": "npm run -s test-node-run -- --ui qunit test/interfaces/qunit.spec", @@ -82,9 +82,9 @@ "test-node:only:globalQunit": "npm run -s test-node-run-only -- --ui qunit test/only/global/qunit.spec --no-parallel", "test-node:only:globalTdd": "npm run -s test-node-run-only -- --ui tdd test/only/global/tdd.spec --no-parallel", "test-node:only": "run-p test-node:only:*", - "test-node:reporters": "npm run -s test-node-run -- 'test/reporters/*.spec.js'", + "test-node:reporters": "npm run -s test-node-run -- test/reporters/*.spec.js", "test-node:requires": "npm run -s test-node-run -- --require coffeescript/register --require test/require/a.js --require test/require/b.coffee --require test/require/c.js --require test/require/d.coffee test/require/require.spec.js", - "test-node:unit": "npm run -s test-node-run -- 'test/unit/*.spec.js' 'test/node-unit/**/*.spec.js'", + "test-node:unit": "npm run -s test-node-run -- test/unit/*.spec.js test/node-unit/**/*.spec.js", "test-node": "run-s test-coverage-clean test-node:* test-coverage-generate", "test-smoke": "node ./bin/mocha --no-config test/smoke/smoke.spec.js", "test": "run-s lint test-node test-browser", From 68665e667ca3276dd87bb978cec32803bd87ab26 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 09:37:31 -0700 Subject: [PATCH 2/8] Add prettier to Knip's ignore list --- .knip.jsonc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.knip.jsonc b/.knip.jsonc index a9f3b98c46..3b19b3e651 100644 --- a/.knip.jsonc +++ b/.knip.jsonc @@ -25,7 +25,8 @@ "karma-mocha-reporter", "karma-mocha", "karma-sauce-launcher", - "non-existent-package" + "non-existent-package", + "prettier" ], "mocha": { "entry": ["test/**/*.{js,ts,mjs,cjs}"] From 2cfa3e32d3f85271ec6d2cf395a16a6610527b6f Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 09:59:45 -0700 Subject: [PATCH 3/8] use double quotes instead of removing quotes --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7ad4ce69f1..a33296b93c 100644 --- a/package.json +++ b/package.json @@ -50,12 +50,12 @@ "docs:api": "jsdoc -c jsdoc.conf.json", "docs:site": "eleventy", "docs": "run-s docs-clean docs:*", - "format:eslint": "eslint --fix . bin/*", - "format:prettier": "prettier --write !(package*).json .*.json lib/**/*.json *.yml", + "format:eslint": "eslint --fix . \"bin/*\"", + "format:prettier": "prettier --write \"!(package*).json\" \".*.json\" \"lib/**/*.json\" \"*.yml\"", "format": "run-s format:*", "lint:knip": "knip --cache", - "lint:code": "eslint . bin/* --max-warnings 0", - "lint:markdown": "markdownlint *.md docs/**/*.md .github/*.md lib/**/*.md test/**/*.md example/**/*.md -i CHANGELOG.md", + "lint:code": "eslint . \"bin/*\" --max-warnings 0", + "lint:markdown": "markdownlint \"*.md\" \"docs/**/*.md\" \".github/*.md\" \"lib/**/*.md\" \"test/**/*.md\" \"example/**/*.md\" -i CHANGELOG.md", "lint": "run-p lint:*", "prepublishOnly": "run-s clean build", "test-browser-run": "cross-env NODE_PATH=. karma start ./karma.conf.js --single-run", @@ -70,7 +70,7 @@ "test-coverage-generate": "nyc report --reporter=lcov --reporter=text", "test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js", "test-node-run": "nyc --no-clean --reporter=json node bin/mocha.js --forbid-only", - "test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 test/integration/**/*.spec.js", + "test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/**/*.spec.js\"", "test-node:interfaces:bdd": "npm run -s test-node-run -- --ui bdd test/interfaces/bdd.spec", "test-node:interfaces:exports": "npm run -s test-node-run -- --ui exports test/interfaces/exports.spec", "test-node:interfaces:qunit": "npm run -s test-node-run -- --ui qunit test/interfaces/qunit.spec", @@ -82,9 +82,9 @@ "test-node:only:globalQunit": "npm run -s test-node-run-only -- --ui qunit test/only/global/qunit.spec --no-parallel", "test-node:only:globalTdd": "npm run -s test-node-run-only -- --ui tdd test/only/global/tdd.spec --no-parallel", "test-node:only": "run-p test-node:only:*", - "test-node:reporters": "npm run -s test-node-run -- test/reporters/*.spec.js", + "test-node:reporters": "npm run -s test-node-run -- \"test/reporters/*.spec.js\"", "test-node:requires": "npm run -s test-node-run -- --require coffeescript/register --require test/require/a.js --require test/require/b.coffee --require test/require/c.js --require test/require/d.coffee test/require/require.spec.js", - "test-node:unit": "npm run -s test-node-run -- test/unit/*.spec.js test/node-unit/**/*.spec.js", + "test-node:unit": "npm run -s test-node-run -- \"test/unit/*.spec.js\" \"test/node-unit/**/*.spec.js\"", "test-node": "run-s test-coverage-clean test-node:* test-coverage-generate", "test-smoke": "node ./bin/mocha --no-config test/smoke/smoke.spec.js", "test": "run-s lint test-node test-browser", From 1f774dcad13d4b86bad6373c1228d0addae70cef Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 10:47:48 -0700 Subject: [PATCH 4/8] Fix tests for compatibility with Node ^22.7 --experimental-detect-module is default in Node 22.7 and later --- test/integration/plugins/root-hooks.spec.js | 48 +++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index 4de08b93cb..ce8a060368 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -136,22 +136,44 @@ describe('root hooks', function () { }); describe('support ESM via .js extension w/o type=module', function () { - it('should fail due to ambiguous file type', function () { - return expect( - invokeMochaAsync( - [ - '--require=' + + describe('should fail due to ambiguous file type', function () { + it('with --no-experimental-detect-module', function () { + return expect( + invokeMochaAsync( + [ + '--require=' + require.resolve( // as object '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' - ) - ], - 'pipe' - )[1], - 'when fulfilled', - 'to contain output', - /SyntaxError: Unexpected token/ - ); + ), + "--no-experimental-detect-module", + ], + 'pipe' + )[1], + 'when fulfilled', + 'to contain output', + /SyntaxError: Unexpected token/ + ); + }); + + it('with --experimental-detect-module', function () { + return expect( + invokeMochaAsync( + [ + '--require=' + + require.resolve( + // as object + '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' + ), + "--experimental-detect-module", + ], + 'pipe' + )[1], + 'when fulfilled', + 'to contain output', + /Cannot require\(\) ES Module/ + ); + }); }); }); }); From b38d5311d10db09db86a05e93d37cbcd6215d7aa Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 10:55:11 -0700 Subject: [PATCH 5/8] At least they pass... --- test/integration/plugins/root-hooks.spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index ce8a060368..8712450a15 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -171,7 +171,8 @@ describe('root hooks', function () { )[1], 'when fulfilled', 'to contain output', - /Cannot require\(\) ES Module/ + // todo fix based on what version of Node is being used + /(Cannot require\(\) ES Module)|(SyntaxError: Unexpected token)/ ); }); }); From 491ba2bfbb1b8728e6d8105d956c79e8a8b82fdb Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 12:07:37 -0700 Subject: [PATCH 6/8] Format and cleanup new test --- test/integration/plugins/root-hooks.spec.js | 34 ++++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index 8712450a15..e1f1142623 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -137,16 +137,16 @@ describe('root hooks', function () { describe('support ESM via .js extension w/o type=module', function () { describe('should fail due to ambiguous file type', function () { - it('with --no-experimental-detect-module', function () { + it('with --no-experimental-detect-module', function () { return expect( invokeMochaAsync( [ '--require=' + - require.resolve( - // as object - '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' - ), - "--no-experimental-detect-module", + require.resolve( + // as object + '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' + ), + '--no-experimental-detect-module' ], 'pipe' )[1], @@ -155,24 +155,28 @@ describe('root hooks', function () { /SyntaxError: Unexpected token/ ); }); - - it('with --experimental-detect-module', function () { + + it('with --experimental-detect-module', function () { + // flag was introduced in Node 21.1.0 + const expectedRegex = + process.version >= 'v21.1.0' + ? /Cannot require\(\) ES Module/ + : /SyntaxError: Unexpected token/; return expect( invokeMochaAsync( [ '--require=' + - require.resolve( - // as object - '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' - ), - "--experimental-detect-module", + require.resolve( + // as object + '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' + ), + '--experimental-detect-module' ], 'pipe' )[1], 'when fulfilled', 'to contain output', - // todo fix based on what version of Node is being used - /(Cannot require\(\) ES Module)|(SyntaxError: Unexpected token)/ + expectedRegex ); }); }); From bf7d28adb01236dcb808b9caa9e31fe6abe8663b Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 12:10:56 -0700 Subject: [PATCH 7/8] Cleanup for fun --- test/integration/plugins/root-hooks.spec.js | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index e1f1142623..4890a40c3e 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -137,39 +137,35 @@ describe('root hooks', function () { describe('support ESM via .js extension w/o type=module', function () { describe('should fail due to ambiguous file type', function () { + const filename = + '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js'; + const noDetectModuleRegex = /SyntaxError: Unexpected token/; + const detectModuleRegex = /Cannot require\(\) ES Module/; it('with --no-experimental-detect-module', function () { return expect( invokeMochaAsync( [ - '--require=' + - require.resolve( - // as object - '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' - ), + '--require=' + require.resolve(filename), // as object '--no-experimental-detect-module' ], 'pipe' )[1], 'when fulfilled', 'to contain output', - /SyntaxError: Unexpected token/ + noDetectModuleRegex ); }); it('with --experimental-detect-module', function () { - // flag was introduced in Node 21.1.0 + // --experimental-detect-module was introduced in Node 21.1.0 const expectedRegex = process.version >= 'v21.1.0' - ? /Cannot require\(\) ES Module/ - : /SyntaxError: Unexpected token/; + ? detectModuleRegex + : noDetectModuleRegex; return expect( invokeMochaAsync( [ - '--require=' + - require.resolve( - // as object - '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js' - ), + '--require=' + require.resolve(filename), // as object '--experimental-detect-module' ], 'pipe' From 7feec9e8ce50d5b5bf3c274b13d5643da0299204 Mon Sep 17 00:00:00 2001 From: Mark Wiemer Date: Sun, 29 Sep 2024 12:13:13 -0700 Subject: [PATCH 8/8] Add newline for style --- test/integration/plugins/root-hooks.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js index 4890a40c3e..597575b474 100644 --- a/test/integration/plugins/root-hooks.spec.js +++ b/test/integration/plugins/root-hooks.spec.js @@ -141,6 +141,7 @@ describe('root hooks', function () { '../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js'; const noDetectModuleRegex = /SyntaxError: Unexpected token/; const detectModuleRegex = /Cannot require\(\) ES Module/; + it('with --no-experimental-detect-module', function () { return expect( invokeMochaAsync(