Skip to content

Commit 1173da0

Browse files
authoredOct 2, 2024··
test: fix npm scripts on windows (#5219)
* Fix npm scripts on Windows * Add prettier to Knip's ignore list * use double quotes instead of removing quotes * Fix tests for compatibility with Node ^22.7 --experimental-detect-module is default in Node 22.7 and later * At least they pass... * Format and cleanup new test * Cleanup for fun * Add newline for style
1 parent 7563e59 commit 1173da0

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed
 

‎.knip.jsonc

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"karma-mocha-reporter",
2626
"karma-mocha",
2727
"karma-sauce-launcher",
28-
"non-existent-package"
28+
"non-existent-package",
29+
"prettier"
2930
],
3031
"mocha": {
3132
"entry": ["test/**/*.{js,ts,mjs,cjs}"]

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
"docs:api": "jsdoc -c jsdoc.conf.json",
5151
"docs:site": "eleventy",
5252
"docs": "run-s docs-clean docs:*",
53-
"format:eslint": "eslint --fix . 'bin/*'",
54-
"format:prettier": "prettier --write '!(package*).json' '.*.json' 'lib/**/*.json' '*.yml'",
53+
"format:eslint": "eslint --fix . \"bin/*\"",
54+
"format:prettier": "prettier --write \"!(package*).json\" \".*.json\" \"lib/**/*.json\" \"*.yml\"",
5555
"format": "run-s format:*",
5656
"lint:knip": "knip --cache",
57-
"lint:code": "eslint . 'bin/*' --max-warnings 0",
58-
"lint:markdown": "markdownlint '*.md' 'docs/**/*.md' '.github/*.md' 'lib/**/*.md' 'test/**/*.md' 'example/**/*.md' -i CHANGELOG.md",
57+
"lint:code": "eslint . \"bin/*\" --max-warnings 0",
58+
"lint:markdown": "markdownlint \"*.md\" \"docs/**/*.md\" \".github/*.md\" \"lib/**/*.md\" \"test/**/*.md\" \"example/**/*.md\" -i CHANGELOG.md",
5959
"lint": "run-p lint:*",
6060
"prepublishOnly": "run-s clean build",
6161
"test-browser-run": "cross-env NODE_PATH=. karma start ./karma.conf.js --single-run",
@@ -70,7 +70,7 @@
7070
"test-coverage-generate": "nyc report --reporter=lcov --reporter=text",
7171
"test-node-run-only": "nyc --no-clean --reporter=json node bin/mocha.js",
7272
"test-node-run": "nyc --no-clean --reporter=json node bin/mocha.js --forbid-only",
73-
"test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 'test/integration/**/*.spec.js'",
73+
"test-node:integration": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/**/*.spec.js\"",
7474
"test-node:interfaces:bdd": "npm run -s test-node-run -- --ui bdd test/interfaces/bdd.spec",
7575
"test-node:interfaces:exports": "npm run -s test-node-run -- --ui exports test/interfaces/exports.spec",
7676
"test-node:interfaces:qunit": "npm run -s test-node-run -- --ui qunit test/interfaces/qunit.spec",
@@ -82,9 +82,9 @@
8282
"test-node:only:globalQunit": "npm run -s test-node-run-only -- --ui qunit test/only/global/qunit.spec --no-parallel",
8383
"test-node:only:globalTdd": "npm run -s test-node-run-only -- --ui tdd test/only/global/tdd.spec --no-parallel",
8484
"test-node:only": "run-p test-node:only:*",
85-
"test-node:reporters": "npm run -s test-node-run -- 'test/reporters/*.spec.js'",
85+
"test-node:reporters": "npm run -s test-node-run -- \"test/reporters/*.spec.js\"",
8686
"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",
87-
"test-node:unit": "npm run -s test-node-run -- 'test/unit/*.spec.js' 'test/node-unit/**/*.spec.js'",
87+
"test-node:unit": "npm run -s test-node-run -- \"test/unit/*.spec.js\" \"test/node-unit/**/*.spec.js\"",
8888
"test-node": "run-s test-coverage-clean test-node:* test-coverage-generate",
8989
"test-smoke": "node ./bin/mocha --no-config test/smoke/smoke.spec.js",
9090
"test": "run-s lint test-node test-browser",

‎test/integration/plugins/root-hooks.spec.js

+40-16
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,46 @@ describe('root hooks', function () {
136136
});
137137

138138
describe('support ESM via .js extension w/o type=module', function () {
139-
it('should fail due to ambiguous file type', function () {
140-
return expect(
141-
invokeMochaAsync(
142-
[
143-
'--require=' +
144-
require.resolve(
145-
// as object
146-
'../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js'
147-
)
148-
],
149-
'pipe'
150-
)[1],
151-
'when fulfilled',
152-
'to contain output',
153-
/SyntaxError: Unexpected token/
154-
);
139+
describe('should fail due to ambiguous file type', function () {
140+
const filename =
141+
'../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js';
142+
const noDetectModuleRegex = /SyntaxError: Unexpected token/;
143+
const detectModuleRegex = /Cannot require\(\) ES Module/;
144+
145+
it('with --no-experimental-detect-module', function () {
146+
return expect(
147+
invokeMochaAsync(
148+
[
149+
'--require=' + require.resolve(filename), // as object
150+
'--no-experimental-detect-module'
151+
],
152+
'pipe'
153+
)[1],
154+
'when fulfilled',
155+
'to contain output',
156+
noDetectModuleRegex
157+
);
158+
});
159+
160+
it('with --experimental-detect-module', function () {
161+
// --experimental-detect-module was introduced in Node 21.1.0
162+
const expectedRegex =
163+
process.version >= 'v21.1.0'
164+
? detectModuleRegex
165+
: noDetectModuleRegex;
166+
return expect(
167+
invokeMochaAsync(
168+
[
169+
'--require=' + require.resolve(filename), // as object
170+
'--experimental-detect-module'
171+
],
172+
'pipe'
173+
)[1],
174+
'when fulfilled',
175+
'to contain output',
176+
expectedRegex
177+
);
178+
});
155179
});
156180
});
157181
});

0 commit comments

Comments
 (0)
Please sign in to comment.