Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

test: fix npm scripts on windows (#5219)

Mark Wiemer1173da0bf614
diff --git a/.knip.jsonc b/.knip.jsonc
index a9f3b98c..3b19b3e6 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}"]
diff --git a/package.json b/package.json
index ad8cf1fa..a33296b9 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",
diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.js
index 4de08b93..597575b4 100644
--- a/test/integration/plugins/root-hooks.spec.js
+++ b/test/integration/plugins/root-hooks.spec.js
@@ -136,22 +136,46 @@ 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=' +
- 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/
- );
+ 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(filename), // as object
+ '--no-experimental-detect-module'
+ ],
+ 'pipe'
+ )[1],
+ 'when fulfilled',
+ 'to contain output',
+ noDetectModuleRegex
+ );
+ });
+
+ it('with --experimental-detect-module', function () {
+ // --experimental-detect-module was introduced in Node 21.1.0
+ const expectedRegex =
+ process.version >= 'v21.1.0'
+ ? detectModuleRegex
+ : noDetectModuleRegex;
+ return expect(
+ invokeMochaAsync(
+ [
+ '--require=' + require.resolve(filename), // as object
+ '--experimental-detect-module'
+ ],
+ 'pipe'
+ )[1],
+ 'when fulfilled',
+ 'to contain output',
+ expectedRegex
+ );
+ });
});
});
});