Skip to content

armgit / mocha

Public Imported from GitHub
0

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

chore: fix esm-utils tests when run without coverage (#6160)

Mostafa Nazaric54539f570c0
diff --git a/test/node-unit/esm-utils.spec.cjs b/test/node-unit/esm-utils.spec.cjs
index 1b855f71..f5d31843 100644
--- a/test/node-unit/esm-utils.spec.cjs
+++ b/test/node-unit/esm-utils.spec.cjs
@@ -53,7 +53,7 @@ describe("esm-utils", function () {
return expect(
() =>
esmUtils.requireOrImport(
- "../../test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts",
+ "../../test/node-unit/fixtures/commonjs/mock-mocha-forbidden-exclusivity-err.ts",
),
"to be rejected with error satisfying",
{
diff --git a/test/node-unit/fixtures/commonjs/mock-mocha-forbidden-exclusivity-err.ts b/test/node-unit/fixtures/commonjs/mock-mocha-forbidden-exclusivity-err.ts
new file mode 100644
index 00000000..860caedb
--- /dev/null
+++ b/test/node-unit/fixtures/commonjs/mock-mocha-forbidden-exclusivity-err.ts
@@ -0,0 +1,13 @@
+/*
+ Mock file that simulates a Mocha FORBIDDEN_EXCLUSIVITY error
+ This error is thrown when .only is used in parallel mode
+
+ This fixture uses require(), so it lives in a folder with a "commonjs" package.json.
+ The root package.json is "type": "module" which would otherwise make Node load this
+ .ts file as ESM and leave "require" undefined.
+ */
+const { createForbiddenExclusivityError } = require('../../../../lib/errors.js');
+
+const mockMocha = { isWorker: true };
+
+throw createForbiddenExclusivityError(mockMocha);
diff --git a/test/node-unit/fixtures/commonjs/package.json b/test/node-unit/fixtures/commonjs/package.json
new file mode 100644
index 00000000..5bbefffb
--- /dev/null
+++ b/test/node-unit/fixtures/commonjs/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts b/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts
deleted file mode 100644
index 9898ba3c..00000000
--- a/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- Mock file that simulates a Mocha FORBIDDEN_EXCLUSIVITY error
- This error is thrown when .only is used in parallel mode
- */
-const { createForbiddenExclusivityError } = require('../../../lib/errors.js');
-
-// Simulate a mocha instance in worker mode
-const mockMocha = { isWorker: true };
-
-throw createForbiddenExclusivityError(mockMocha);