Skip to content

armgit / mocha

Public Imported from GitHub
0

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

feat!: change root package.json type to module (#6078)

Mark Wiemerda015de4493f
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 3263a816..76bcfe4d 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -98,7 +98,7 @@ Feel free to open PRs for changes you think are trivial. If a maintainer believe
1. Make sure the issue is labeled with [`status: accepting prs`](https://github.com/mochajs/mocha/issues?q=is%3Aissue+is%3Aopen+label%3A%22status%3A+accepting+prs%22) (or your change is [trivial](#trivial-changes))
1. Create a new branch in your working copy.
1. Make your changes and add them via `git add`.
- - Your changes will likely be somewhere in `lib/`, `bin/`, or (if your changes are browser-specific) `browser-entry.mjs`.
+ - Your changes will likely be somewhere in `lib/`, `bin/`, or (if your changes are browser-specific) `browser-entry.js`.
- Unit and/or integration **tests are required** for any code change.
These live in `test/`.
- **Do not modify** the root `mocha.js` file directly; it is automatically generated.
diff --git a/.github/ISSUE_TEMPLATE/01-bug.yml b/.github/ISSUE_TEMPLATE/01-bug.yml
index a6408e3f..f4d4094a 100644
--- a/.github/ISSUE_TEMPLATE/01-bug.yml
+++ b/.github/ISSUE_TEMPLATE/01-bug.yml
@@ -32,7 +32,7 @@ body:
validations:
required: true
- attributes:
- description: What do `mocha --version`, `node_modules/.bin/mocha.mjs --version`, and `node --version` output? What name and version of browser/environment, shell, and any other related modules such as transpilers are you using?
+ description: What do `mocha --version`, `node_modules/.bin/mocha.js --version`, and `node --version` output? What name and version of browser/environment, shell, and any other related modules such as transpilers are you using?
label: Versions
type: textarea
validations:
diff --git a/.knip.jsonc b/.knip.jsonc
index 01baefbc..08da3044 100644
--- a/.knip.jsonc
+++ b/.knip.jsonc
@@ -1,10 +1,10 @@
{
"$schema": "https://unpkg.com/knip@6/schema-jsonc.json",
- "entry": ["docs/_data/supporters.cjs", "index.mjs!", "lib/cli/index.js!"],
+ "entry": ["docs/_data/supporters.cjs", "index.js!", "lib/cli/index.cjs!"],
"project": ["{bin,lib,scripts,test}/**/*.{js,ts,mjs,cjs}"],
"ignore": [
"test/integration/fixtures/esm/type-module/test-that-imports-non-existing-module.fixture.js",
- "test/integration/fixtures/options/watch/test-with-dependency.fixture.js",
+ "test/integration/fixtures/options/watch/test-with-dependency.fixture.cjs",
],
"ignoreDependencies": [
"@test/esm-only-loader",
@@ -16,7 +16,7 @@
"entry": ["test/**/*.{js,ts,mjs,cjs}"],
},
"webpack": {
- "config": "test/browser-specific/fixtures/webpack/webpack.config.js",
+ "config": "test/browser-specific/fixtures/webpack/webpack.config.cjs",
},
"rules": {
"exports": "off",
diff --git a/.mocharc.yml b/.mocharc.yml
index dda702d0..13a80323 100644
--- a/.mocharc.yml
+++ b/.mocharc.yml
@@ -1,4 +1,4 @@
-require: "test/setup"
+require: "./test/setup.cjs"
ui: "bdd"
global:
- "okGlobalA,okGlobalB"
diff --git a/.nycrc b/.nycrc
index 2d79bed7..f0779c11 100644
--- a/.nycrc
+++ b/.nycrc
@@ -19,6 +19,6 @@
"**/package-lock.json",
"node_modules/**",
"scripts/**",
- "!test/integration/fixtures/stack-trace.fixture.js"
+ "!test/integration/fixtures/stack-trace.fixture.cjs"
]
}
diff --git a/.wallaby.js b/.wallaby.cjs
similarity index 90%
rename from .wallaby.js
rename to .wallaby.cjs
index a9692061..bddd4912 100644
--- a/.wallaby.js
+++ b/.wallaby.cjs
@@ -5,8 +5,8 @@ module.exports = () => {
files: [
"index.js",
"lib/**/*.{js,json}",
- "test/setup.js",
- "test/assertions.js",
+ "test/setup.cjs",
+ "test/assertions.cjs",
{
pattern: "test/node-unit/**/*.fixture.js",
instrument: false,
@@ -21,8 +21,8 @@ module.exports = () => {
],
filesWithNoCoverageCalculated: [
"test/**/*.fixture.js",
- "test/setup.js",
- "test/assertions.js",
+ "test/setup.cjs",
+ "test/assertions.cjs",
"lib/browser/**/*.js",
],
tests: ["test/unit/**/*.spec.js", "test/node-unit/**/*.spec.js"],
@@ -46,7 +46,7 @@ module.exports = () => {
"",
mochaUnderTest,
);
- require("./test/setup");
+ require("./test/setup.cjs");
},
debug: true,
runMode: "onsave",
diff --git a/bin/mocha.mjs b/bin/mocha.js
similarity index 93%
rename from bin/mocha.mjs
rename to bin/mocha.js
index a21e989e..a1b86afd 100755
--- a/bin/mocha.mjs
+++ b/bin/mocha.js
@@ -2,7 +2,7 @@
/**
* This wrapper executable checks for known node flags and appends them when found,
- * before invoking the "real" executable (`lib/cli/cli.mjs`)
+ * before invoking the "real" executable (`lib/cli/cli.js`)
*
* @module bin/mocha
* @private
@@ -13,14 +13,14 @@ import { spawn } from "node:child_process";
import os from "node:os";
import unparse from "yargs-unparser";
-import { main } from "../lib/cli/cli.mjs";
-import { loadOptions } from "../lib/cli/options.mjs";
+import { main } from "../lib/cli/cli.js";
+import { loadOptions } from "../lib/cli/options.cjs";
import {
unparseNodeFlags,
isNodeFlag,
impliesNoTimeouts,
-} from "../lib/cli/node-flags.mjs";
-import { aliases } from "../lib/cli/run-option-metadata.mjs";
+} from "../lib/cli/node-flags.cjs";
+import { aliases } from "../lib/cli/run-option-metadata.cjs";
import { fileURLToPath } from "node:url";
const debug = d.debug("mocha:cli:mocha");
@@ -84,7 +84,7 @@ if (mochaArgs._) {
}
if (mochaArgs["node-option"] || Object.keys(nodeArgs).length || hasInspect) {
- const mochaPath = fileURLToPath(import.meta.resolve("../lib/cli/cli.mjs"));
+ const mochaPath = fileURLToPath(import.meta.resolve("../lib/cli/cli.js"));
const nodeArgv =
(mochaArgs["node-option"] &&
diff --git a/browser-entry.mjs b/browser-entry.js
similarity index 96%
rename from browser-entry.mjs
rename to browser-entry.js
index 92628f34..2ca3f409 100644
--- a/browser-entry.mjs
+++ b/browser-entry.js
@@ -1,8 +1,8 @@
import BrowserStdout from "browser-stdout";
-import { parseQuery } from "./lib/browser/parse-query.mjs";
-import { highlightTags } from "./lib/browser/highlight-tags.mjs";
-import Mocha from "./lib/mocha.js";
+import { parseQuery } from "./lib/browser/parse-query.js";
+import { highlightTags } from "./lib/browser/highlight-tags.js";
+import Mocha from "./lib/mocha.cjs";
/**
* Shim process.stdout.
diff --git a/docs/.knip.jsonc b/docs/.knip.jsonc
index 1581a911..ac31c279 100644
--- a/docs/.knip.jsonc
+++ b/docs/.knip.jsonc
@@ -1,7 +1,6 @@
{
"$schema": "https://unpkg.com/knip@6/schema-jsonc.json",
- // Entry points marked with ! are analyzed but not reported as unused
- "entry": ["src/content/**/*.{mdx,ts}!", "src/content.config.ts"],
+ "entry": ["src/content/**/*.{mdx,ts}!"],
"project": ["src/**/*.{ts,js,mjs,cjs,astro}"],
"astro": {
"config": "astro.config.ts",
diff --git a/docs/package-lock.json b/docs/package-lock.json
index d478d758..31cf5e60 100644
--- a/docs/package-lock.json
+++ b/docs/package-lock.json
@@ -1535,9 +1535,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1555,9 +1552,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1575,9 +1569,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1595,9 +1586,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1615,9 +1603,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1635,9 +1620,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1655,9 +1637,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1675,9 +1654,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1890,9 +1866,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1907,9 +1880,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1924,9 +1894,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1941,9 +1908,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1958,9 +1922,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1975,9 +1936,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1992,9 +1950,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2009,9 +1964,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
diff --git a/docs/public/example/Array.js b/docs/public/example/Array.js
index cc9ab7da..c3820c6a 100644
--- a/docs/public/example/Array.js
+++ b/docs/public/example/Array.js
@@ -1,5 +1,3 @@
-"use strict";
-
describe("Array", function () {
describe(".push()", function () {
it("should append a value", function () {
diff --git a/docs/src/content/docs/explainers/detecting-multiple-calls-to-done.mdx b/docs/src/content/docs/explainers/detecting-multiple-calls-to-done.mdx
index 144091e7..90efe59f 100644
--- a/docs/src/content/docs/explainers/detecting-multiple-calls-to-done.mdx
+++ b/docs/src/content/docs/explainers/detecting-multiple-calls-to-done.mdx
@@ -17,7 +17,7 @@ it("double done", function (done) {
Running the above test will give you the below error message:
```bash
-$ ./node_modules/.bin/mocha.mjs mocha.test.js
+$ ./node_modules/.bin/mocha.js mocha.test.js
✓ double done
diff --git a/docs/src/content/docs/explainers/programmatic-usage.mdx b/docs/src/content/docs/explainers/programmatic-usage.mdx
index c1a99aa3..7285f856 100644
--- a/docs/src/content/docs/explainers/programmatic-usage.mdx
+++ b/docs/src/content/docs/explainers/programmatic-usage.mdx
@@ -33,7 +33,7 @@ mocha.run(function (failures) {
});
```
-`mocha.run()` returns a `Runner` instance which emits many [events](https://github.com/mochajs/mocha/blob/main/lib/runner.js) of interest, exposed as `Mocha.Runner.constants` (e.g. `EVENT_TEST_PASS`, `EVENT_TEST_FAIL`, `EVENT_RUN_END`).
+`mocha.run()` returns a `Runner` instance which emits many [events](https://github.com/mochajs/mocha/blob/main/lib/runner.cjs) of interest, exposed as `Mocha.Runner.constants` (e.g. `EVENT_TEST_PASS`, `EVENT_TEST_FAIL`, `EVENT_RUN_END`).
Note that `run` (via `loadFiles`, which it calls) relies on Node's `require` to execute the test interface functions. Thus, files loaded by Mocha will be stored in Node's `require` cache and therefore tests in these files will not be re-run if `mocha.run()` is called again. If you want to run tests multiple times, you may need to clear Node's `require` cache before subsequent calls in whichever manner best suits your needs. `Mocha#unloadFiles` is also available and will remove all files loaded by `Mocha#loadFiles`.
diff --git a/docs/src/content/docs/explainers/third-party-uis.mdx b/docs/src/content/docs/explainers/third-party-uis.mdx
index cda10aa5..fa404b73 100644
--- a/docs/src/content/docs/explainers/third-party-uis.mdx
+++ b/docs/src/content/docs/explainers/third-party-uis.mdx
@@ -11,7 +11,7 @@ In this first brief example, we'll create an interface with only a single functi
```javascript
import Mocha from "mocha";
-import { createCommon as MochaInterface } from "mocha/lib/interfaces/common.mjs";
+import { createCommon as MochaInterface } from "mocha/lib/interfaces/common.js";
const Test = Mocha.Test;
/**
@@ -74,7 +74,7 @@ In this next example, we'll be extending the [TDD interface](https://github.com/
```javascript
import Mocha from "mocha";
-import { createCommon as MochaInterface } from "mocha/lib/interfaces/common.mjs";
+import { createCommon as MochaInterface } from "mocha/lib/interfaces/common.js";
import escapeStringRegexp from "escape-string-regexp";
const Test = Mocha.Test;
diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx
index 0bd0c07c..d2bc2758 100644
--- a/docs/src/content/docs/index.mdx
+++ b/docs/src/content/docs/index.mdx
@@ -56,6 +56,6 @@ In addition to chatting with us on [our Discord](https://discord.gg/KeDn2uXhER),
spies, mocking, and shared behaviours be sure to check out the [Mocha Wiki](https://github.com/mochajs/mocha/wiki) on GitHub.
For a running example of Mocha, view [example/tests.html](example/tests.html).
-For the JavaScript API, view the [API documentation](/api) or the [source](https://github.com/mochajs/mocha/blob/main/lib/mocha.js).
+For the JavaScript API, view the [API documentation](/api) or the [source](https://github.com/mochajs/mocha/blob/main/lib/mocha.cjs).
<ClientRedirects />
diff --git a/docs/src/content/docs/running/cli.mdx b/docs/src/content/docs/running/cli.mdx
index 4bf2443f..6ad0bdec 100644
--- a/docs/src/content/docs/running/cli.mdx
+++ b/docs/src/content/docs/running/cli.mdx
@@ -5,7 +5,7 @@ description: Running Mocha in your terminal.
Running `npx mocha --help` will show the full list of available commands:
-{/* This output is defined in lib/cli/run.js */}
+{/* This output is defined in lib/cli/run.cjs */}
```plaintext
mocha [spec..]
diff --git a/eslint.config.js b/eslint.config.cjs
similarity index 87%
rename from eslint.config.js
rename to eslint.config.cjs
index d6c68a60..ad3e3f86 100644
--- a/eslint.config.js
+++ b/eslint.config.cjs
@@ -31,25 +31,25 @@ module.exports = defineConfig(
strict: ["error", "global"],
},
settings: {
- "import/extensions": [".js", ".mjs"],
+ "import/extensions": [".cjs", ".js", ".mjs"],
"import/resolver": {
node: {
- extensions: [".js", ".mjs"],
+ extensions: [".cjs", ".js", ".mjs"],
},
},
node: {
- tryExtensions: [".js", ".json", ".node", ".mjs"],
+ tryExtensions: [".cjs", ".js", ".json", ".node", ".mjs"],
},
},
},
{
files: [
- ".wallaby.js",
+ ".wallaby.cjs",
"package-scripts.js",
"bin/*",
"lib/cli/**/*.js",
"lib/nodejs/**/*.js",
- "scripts/**/*.{js,mjs}",
+ "scripts/**/*.{js,cjs}",
"test/**/*.{js,mjs}",
],
languageOptions: {
@@ -57,20 +57,14 @@ module.exports = defineConfig(
},
},
{
- files: [
- "**/*.mjs",
- "lib/nodejs/esm-utils.js",
- "scripts/pick-from-package-json.js",
- "test/compiler-cjs/test.js",
- "test/compiler-esm/*.js",
- ],
+ files: ["**/*.js", "**/*.mjs", "lib/nodejs/esm-utils.cjs"],
languageOptions: {
sourceType: "module",
ecmaVersion: 2025,
},
},
{
- files: ["test/**/*.{js,mjs}"],
+ files: ["test/**/*.{js,mjs,cjs}"],
languageOptions: {
globals: {
...globals.browser,
@@ -81,7 +75,8 @@ module.exports = defineConfig(
},
},
{
- files: ["bin/*", "lib/**/*.js"],
+ files: ["bin/*", "lib/**/*.{js,cjs}"],
+ ignores: ["lib/stats-collector.js"],
rules: {
"no-restricted-globals": [
"error",
@@ -139,7 +134,7 @@ module.exports = defineConfig(
},
},
{
- files: ["lib/reporters/*.js"],
+ files: ["lib/reporters/*.{js,cjs}"],
rules: {
"no-restricted-syntax": [
"error",
@@ -167,13 +162,13 @@ module.exports = defineConfig(
},
},
globalIgnores([
- "**/*.{fixture,min}.{js,mjs}",
+ "**/*.{fixture,min}.{js,mjs,cjs}",
"coverage/**",
"docs/{.astro,dist}/**",
"mocha.js",
"out/**",
"test/browser/.generated/**",
"test/integration/fixtures/**",
- "scripts/pick-from-package-json.mjs",
+ "scripts/pick-from-package-json.js",
]),
);
diff --git a/example/config/.mocharc.js b/example/config/.mocharc.cjs
similarity index 100%
rename from example/config/.mocharc.js
rename to example/config/.mocharc.cjs
diff --git a/index.js b/index.js
new file mode 100644
index 00000000..5a5d9a2e
--- /dev/null
+++ b/index.js
@@ -0,0 +1,2 @@
+export { default } from "./lib/mocha.cjs";
+export * from "./lib/mocha.cjs";
diff --git a/index.mjs b/index.mjs
deleted file mode 100644
index 9a71216f..00000000
--- a/index.mjs
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./lib/mocha.js";
-export * from "./lib/mocha.js";
diff --git a/lib/browser/highlight-tags.mjs b/lib/browser/highlight-tags.js
similarity index 100%
rename from lib/browser/highlight-tags.mjs
rename to lib/browser/highlight-tags.js
diff --git a/lib/browser/parse-query.mjs b/lib/browser/parse-query.js
similarity index 100%
rename from lib/browser/parse-query.mjs
rename to lib/browser/parse-query.js
diff --git a/lib/cli/cli.mjs b/lib/cli/cli.js
similarity index 94%
rename from lib/cli/cli.mjs
rename to lib/cli/cli.js
index 37e9e609..f52216fd 100755
--- a/lib/cli/cli.mjs
+++ b/lib/cli/cli.js
@@ -10,10 +10,10 @@ import debugModule from "debug";
import yargs from "yargs";
import { fileURLToPath } from "node:url";
-import { loadOptions, YARGS_PARSER_CONFIG } from "./options.mjs";
-import { run, init } from "./commands.mjs";
+import { loadOptions, YARGS_PARSER_CONFIG } from "./options.cjs";
+import { run, init } from "./commands.js";
import pc from "picocolors";
-import { logSymbols } from "../utils.js";
+import { logSymbols } from "../utils.cjs";
import packageJson from "../../package.json" with { type: "json" };
diff --git a/lib/cli/collect-files.js b/lib/cli/collect-files.cjs
similarity index 94%
rename from lib/cli/collect-files.js
rename to lib/cli/collect-files.cjs
index 592b7234..0440fbfb 100644
--- a/lib/cli/collect-files.js
+++ b/lib/cli/collect-files.cjs
@@ -4,9 +4,9 @@ const path = require("node:path");
const pc = require("picocolors");
const debug = require("debug")("mocha:cli:run:helpers");
const { minimatch } = require("minimatch");
-const { NO_FILES_MATCH_PATTERN } = require("../error-constants.mjs").constants;
-const { lookupFiles } = require("./lookup-files.mjs");
-const { castArray } = require("../utils");
+const { NO_FILES_MATCH_PATTERN } = require("../error-constants.js").constants;
+const { lookupFiles } = require("./lookup-files.js");
+const { castArray } = require("../utils.cjs");
/**
* Exports a function that collects test files from CLI parameters.
diff --git a/lib/cli/commands.mjs b/lib/cli/commands.js
similarity index 64%
rename from lib/cli/commands.mjs
rename to lib/cli/commands.js
index 2db1f91f..549e9b09 100644
--- a/lib/cli/commands.mjs
+++ b/lib/cli/commands.js
@@ -5,6 +5,6 @@
* @module
*/
-export * as init from "./init.mjs";
+export * as init from "./init.js";
// default command
-export { default as run } from "./run.js";
+export { default as run } from "./run.cjs";
diff --git a/lib/cli/config.js b/lib/cli/config.cjs
similarity index 96%
rename from lib/cli/config.js
rename to lib/cli/config.cjs
index 678e06c7..03b68c92 100644
--- a/lib/cli/config.js
+++ b/lib/cli/config.cjs
@@ -11,8 +11,8 @@ const fs = require("node:fs");
const path = require("node:path");
const debug = require("debug")("mocha:cli:config");
const findUp = require("find-up");
-const { createUnparsableFileError } = require("../errors.mjs");
-const utils = require("../utils");
+const { createUnparsableFileError } = require("../errors.js");
+const utils = require("../utils.cjs");
/**
* These are the valid config files, in order of precedence;
diff --git a/lib/cli/index.cjs b/lib/cli/index.cjs
new file mode 100644
index 00000000..3e313d8e
--- /dev/null
+++ b/lib/cli/index.cjs
@@ -0,0 +1,3 @@
+"use strict";
+
+module.exports = require("./cli.js");
diff --git a/lib/cli/index.js b/lib/cli/index.js
deleted file mode 100644
index 71038aa6..00000000
--- a/lib/cli/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-"use strict";
-
-module.exports = require("./cli.mjs");
diff --git a/lib/cli/init.mjs b/lib/cli/init.js
similarity index 100%
rename from lib/cli/init.mjs
rename to lib/cli/init.js
diff --git a/lib/cli/lookup-files.mjs b/lib/cli/lookup-files.js
similarity index 99%
rename from lib/cli/lookup-files.mjs
rename to lib/cli/lookup-files.js
index bcc400c7..764588f7 100644
--- a/lib/cli/lookup-files.mjs
+++ b/lib/cli/lookup-files.js
@@ -10,7 +10,7 @@ import * as glob from "glob";
import {
createNoFilesMatchPatternError,
createMissingArgumentError,
-} from "../errors.mjs";
+} from "../errors.js";
import debugModule from "debug";
const debug = debugModule("mocha:cli:lookup-files");
diff --git a/lib/cli/node-flags.mjs b/lib/cli/node-flags.cjs
similarity index 87%
rename from lib/cli/node-flags.mjs
rename to lib/cli/node-flags.cjs
index b5cbe7d7..d3d55aaa 100644
--- a/lib/cli/node-flags.mjs
+++ b/lib/cli/node-flags.cjs
@@ -1,3 +1,5 @@
+"use strict";
+
/**
* Some settings and code related to Mocha's handling of Node.js/V8 flags.
* @private
@@ -5,8 +7,8 @@
*/
const nodeFlags = process.allowedNodeEnvironmentFlags;
-import { isMochaFlag } from "./run-option-metadata.mjs";
-import unparse from "yargs-unparser";
+const { isMochaFlag } = require("./run-option-metadata.cjs");
+const unparse = require("yargs-unparser");
/**
* These flags are considered "debug" flags.
@@ -32,7 +34,7 @@ const debugFlags = new Set(["inspect", "inspect-brk"]);
* @returns {boolean} If the flag is considered a "Node" flag.
* @private
*/
-export function isNodeFlag(flag, bareword = true) {
+function isNodeFlag(flag, bareword = true) {
if (!bareword) {
// check if the flag begins with dashes; if not, not a node flag.
if (!/^--?/.test(flag)) {
@@ -60,7 +62,7 @@ export function isNodeFlag(flag, bareword = true) {
* @returns {boolean}
* @private
*/
-export function impliesNoTimeouts(flag) {
+function impliesNoTimeouts(flag) {
return debugFlags.has(flag);
}
@@ -72,7 +74,7 @@ export function impliesNoTimeouts(flag) {
* @returns {string[]} Unparsed arguments using `=` to specify values
* @private
*/
-export function unparseNodeFlags(opts) {
+function unparseNodeFlags(opts) {
var args = unparse(opts);
return args.length
? args
@@ -83,3 +85,7 @@ export function unparseNodeFlags(opts) {
.split(" ")
: [];
}
+
+exports.isNodeFlag = isNodeFlag;
+exports.impliesNoTimeouts = impliesNoTimeouts;
+exports.unparseNodeFlags = unparseNodeFlags;
diff --git a/lib/cli/one-and-dones.mjs b/lib/cli/one-and-dones.js
similarity index 97%
rename from lib/cli/one-and-dones.mjs
rename to lib/cli/one-and-dones.js
index 22ee9578..aba3ee99 100644
--- a/lib/cli/one-and-dones.mjs
+++ b/lib/cli/one-and-dones.js
@@ -6,7 +6,7 @@
* @private
*/
-import Mocha from "../mocha.js";
+import Mocha from "../mocha.cjs";
/**
* Dumps a sorted list of the enumerable, lower-case keys of some object
diff --git a/lib/cli/options.mjs b/lib/cli/options.cjs
similarity index 90%
rename from lib/cli/options.mjs
rename to lib/cli/options.cjs
index 144297db..11f79a52 100644
--- a/lib/cli/options.mjs
+++ b/lib/cli/options.cjs
@@ -1,3 +1,5 @@
+"use strict";
+
/**
* Main entry point for handling filesystem-based configuration,
* whether that's a config file or `package.json` or whatever.
@@ -5,29 +7,30 @@
* @private
*/
-import { readFileSync } from "node:fs";
-import pc from "picocolors";
-import yargsParser from "yargs-parser";
-import {
+const { readFileSync } = require("node:fs");
+const pc = require("picocolors");
+const yargsParser = require("yargs-parser");
+const {
types,
aliases,
isMochaFlag,
expectedTypeForFlag,
-} from "./run-option-metadata.mjs";
-import { ONE_AND_DONE_ARGS } from "./one-and-dones.mjs";
-import mocharc from "../mocharc.json" with { type: "json" };
-import { list } from "./run-helpers.js";
-import { loadConfig, findConfig } from "./config.js";
-import { sync } from "find-up";
-import debugModule from "debug";
-const debug = debugModule("mocha:cli:options");
-import { isNodeFlag } from "./node-flags.mjs";
-import {
+} = require("./run-option-metadata.cjs");
+const { ONE_AND_DONE_ARGS } = require("./one-and-dones.js");
+const mocharc = require("../mocharc.json");
+const { list } = require("./run-helpers.cjs");
+const { loadConfig, findConfig } = require("./config.cjs");
+const { sync } = require("find-up");
+const debugModule = require("debug");
+const { isNodeFlag } = require("./node-flags.cjs");
+const {
createUnparsableFileError,
createInvalidArgumentTypeError,
createUnsupportedError,
-} from "../errors.mjs";
-import { isNumeric } from "../utils.js";
+} = require("../errors.js");
+const { isNumeric } = require("../utils.cjs");
+
+const debug = debugModule("mocha:cli:options");
/**
* The `yargs-parser` namespace
@@ -45,7 +48,7 @@ import { isNumeric } from "../utils.js";
* Base yargs parser configuration
* @private
*/
-export const YARGS_PARSER_CONFIG = {
+const YARGS_PARSER_CONFIG = {
"combine-arrays": true,
"short-option-groups": false,
"dot-notation": false,
@@ -209,7 +212,7 @@ const parse = (args = [], defaultValues = {}, ...configObjects) => {
* @alias module:lib/cli.loadRc
* @returns {external:yargsParser.Arguments|void} Parsed config, or nothing if `args.config` is `false`
*/
-export const loadRc = (args = {}) => {
+const loadRc = (args = {}) => {
if (args.config !== false) {
const config = args.config || findConfig();
return config ? loadConfig(config) : {};
@@ -225,7 +228,7 @@ export const loadRc = (args = {}) => {
* @alias module:lib/cli.loadPkgRc
* @returns {external:yargsParser.Arguments|void} Parsed config. Throws if unparsableF. Empty object if file not found.
*/
-export const loadPkgRc = (args = {}) => {
+const loadPkgRc = (args = {}) => {
let result;
if (args.package === false) {
return result;
@@ -283,7 +286,7 @@ export const loadPkgRc = (args = {}) => {
* @alias module:lib/cli.loadOptions
* @returns {external:yargsParser.Arguments} Parsed args from everything
*/
-export const loadOptions = (argv = []) => {
+const loadOptions = (argv = []) => {
let args = parse(argv);
// short-circuit: look for a flag that would abort loading of options
if (
@@ -328,3 +331,8 @@ export const loadOptions = (argv = []) => {
return args;
};
+
+exports.YARGS_PARSER_CONFIG = YARGS_PARSER_CONFIG;
+exports.loadRc = loadRc;
+exports.loadPkgRc = loadPkgRc;
+exports.loadOptions = loadOptions;
diff --git a/lib/cli/run-helpers.js b/lib/cli/run-helpers.cjs
similarity index 94%
rename from lib/cli/run-helpers.js
rename to lib/cli/run-helpers.cjs
index d0f16b44..948cb222 100644
--- a/lib/cli/run-helpers.js
+++ b/lib/cli/run-helpers.cjs
@@ -8,22 +8,22 @@
*/
/**
- * @typedef {import('../mocha.js')} Mocha
+ * @typedef {import('../mocha.cjs')} Mocha
* @typedef {import('../types.d.ts').MochaOptions} MochaOptions
* @typedef {import('../types.d.ts').UnmatchedFile} UnmatchedFile
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
const fs = require("node:fs");
const path = require("node:path");
const pc = require("picocolors");
const debug = require("debug")("mocha:cli:run:helpers");
-const { watchRun, watchParallelRun } = require("./watch-run");
-const collectFiles = require("./collect-files");
+const { watchRun, watchParallelRun } = require("./watch-run.cjs");
+const collectFiles = require("./collect-files.cjs");
const { format } = require("node:util");
-const { createInvalidLegacyPluginError } = require("../errors.mjs");
-const { requireOrImport } = require("../nodejs/esm-utils");
-const { PluginLoader } = require("../plugin-loader.mjs");
+const { createInvalidLegacyPluginError } = require("../errors.js");
+const { requireOrImport } = require("../nodejs/esm-utils.cjs");
+const { PluginLoader } = require("../plugin-loader.js");
/**
* Exits Mocha when tests + code under test has finished execution (default)
@@ -152,7 +152,7 @@ const handleUnmatchedFiles = (mocha, unmatchedFiles) => {
* @param {Mocha} mocha - Mocha instance
* @param {MochaOptions} [opts] - Command line options
* @param {Object} fileCollectParams - Parameters that control test
- * file collection. See `lib/cli/collect-files.js`.
+ * file collection. See `lib/cli/collect-files.cjs`.
* @returns {Promise<Runner>}
* @private
*/
@@ -183,7 +183,7 @@ const singleRun = async (
* @param {Mocha} mocha - Mocha instance
* @param {MochaOptions} options - Command line options
* @param {Object} fileCollectParams - Parameters that control test
- * file collection. See `lib/cli/collect-files.js`.
+ * file collection. See `lib/cli/collect-files.cjs`.
* @returns {Promise<Runner>}
* @ignore
* @private
diff --git a/lib/cli/run-option-metadata.mjs b/lib/cli/run-option-metadata.cjs
similarity index 95%
rename from lib/cli/run-option-metadata.mjs
rename to lib/cli/run-option-metadata.cjs
index 7195e6e8..996fbefa 100644
--- a/lib/cli/run-option-metadata.mjs
+++ b/lib/cli/run-option-metadata.cjs
@@ -1,3 +1,5 @@
+"use strict";
+
/**
* Metadata about various options of the `run` command
* @see module:lib/cli/run
@@ -135,4 +137,7 @@ const expectedTypeForFlag = (flag) => {
);
};
-export { types, aliases, isMochaFlag, expectedTypeForFlag };
+exports.types = types;
+exports.aliases = aliases;
+exports.isMochaFlag = isMochaFlag;
+exports.expectedTypeForFlag = expectedTypeForFlag;
diff --git a/lib/cli/run.js b/lib/cli/run.cjs
similarity index 97%
rename from lib/cli/run.js
rename to lib/cli/run.cjs
index bdca79b4..5a444ff4 100644
--- a/lib/cli/run.js
+++ b/lib/cli/run.cjs
@@ -8,24 +8,24 @@
*/
const pc = require("picocolors");
-const Mocha = require("../mocha");
+const Mocha = require("../mocha.cjs");
const {
createUnsupportedError,
createInvalidArgumentValueError,
createMissingArgumentError,
-} = require("../errors.mjs");
+} = require("../errors.js");
const {
list,
handleRequires,
validateLegacyPlugin,
runMocha,
-} = require("./run-helpers");
-const { ONE_AND_DONES, ONE_AND_DONE_ARGS } = require("./one-and-dones.mjs");
+} = require("./run-helpers.cjs");
+const { ONE_AND_DONES, ONE_AND_DONE_ARGS } = require("./one-and-dones.js");
const debug = require("debug")("mocha:cli:run");
const defaults = require("../mocharc.json");
-const { types, aliases } = require("./run-option-metadata.mjs");
-const { isCI, logSymbols } = require("../utils");
+const { types, aliases } = require("./run-option-metadata.cjs");
+const { isCI, logSymbols } = require("../utils.cjs");
/**
* Logical option groups
diff --git a/lib/cli/watch-run.js b/lib/cli/watch-run.cjs
similarity index 98%
rename from lib/cli/watch-run.js
rename to lib/cli/watch-run.cjs
index 495d1e28..b558a6e4 100644
--- a/lib/cli/watch-run.js
+++ b/lib/cli/watch-run.cjs
@@ -6,16 +6,16 @@ const chokidar = require("chokidar");
const glob = require("glob");
const isPathInside = require("is-path-inside");
const { minimatch } = require("minimatch");
-const Context = require("../context.mjs").Context;
-const collectFiles = require("./collect-files");
-const { logSymbols } = require("../utils");
+const Context = require("../context.js").Context;
+const collectFiles = require("./collect-files.cjs");
+const { logSymbols } = require("../utils.cjs");
/**
* @typedef {import('chokidar').FSWatcher} FSWatcher
* @typedef {import('glob').Glob['patterns'][number]} Pattern
* The `Pattern` class is not exported by the `glob` package.
* Ref [link](../../node_modules/glob/dist/commonjs/pattern.d.ts).
- * @typedef {import('../mocha.js')} Mocha
+ * @typedef {import('../mocha.cjs')} Mocha
* @typedef {import('../types.d.ts').BeforeWatchRun} BeforeWatchRun
* @typedef {import('../types.d.ts').FileCollectionOptions} FileCollectionOptions
* @typedef {import('../types.d.ts').Rerunner} Rerunner
@@ -64,7 +64,7 @@ exports.watchParallelRun = (
// this `require` is needed because the require cache has been cleared. the dynamic
// exports set via the below call to `mocha.ui()` won't work properly if a
// test depends on this module.
- const Mocha = require("../mocha");
+ const Mocha = require("../mocha.cjs");
// ... and now that we've gotten a new module, we need to use it again due
// to `mocha.ui()` call
@@ -105,7 +105,7 @@ exports.watchParallelRun = (
* @param {string[]} opts.watchIgnore - List of paths and patterns to
* exclude from watching. See `ignored` option of `chokidar`.
* @param {FileCollectionOptions} fileCollectParams - Parameters that control test
- * file collection. See `lib/cli/collect-files.js`.
+ * file collection. See `lib/cli/collect-files.cjs`.
* @private
*/
exports.watchRun = (mocha, { watchFiles, watchIgnore }, fileCollectParams) => {
@@ -126,7 +126,7 @@ exports.watchRun = (mocha, { watchFiles, watchIgnore }, fileCollectParams) => {
// this `require` is needed because the require cache has been cleared. the dynamic
// exports set via the below call to `mocha.ui()` won't work properly if a
// test depends on this module.
- const Mocha = require("../mocha");
+ const Mocha = require("../mocha.cjs");
// ... and now that we've gotten a new module, we need to use it again due
// to `mocha.ui()` call
diff --git a/lib/context.mjs b/lib/context.js
similarity index 96%
rename from lib/context.mjs
rename to lib/context.js
index 885a065a..a5f0b76a 100644
--- a/lib/context.mjs
+++ b/lib/context.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('./runnable.mjs')} Runnable
+ * @typedef {import('./runnable.js')} Runnable
*/
/**
diff --git a/lib/error-constants.mjs b/lib/error-constants.js
similarity index 100%
rename from lib/error-constants.mjs
rename to lib/error-constants.js
diff --git a/lib/errors.mjs b/lib/errors.js
similarity index 98%
rename from lib/errors.mjs
rename to lib/errors.js
index 3f3ae056..f6432199 100644
--- a/lib/errors.mjs
+++ b/lib/errors.js
@@ -1,13 +1,13 @@
/**
- * @typedef {import('./mocha.js')} Mocha
- * @typedef {import('./runnable.mjs')} Runnable
+ * @typedef {import('./mocha.cjs')} Mocha
+ * @typedef {import('./runnable.js')} Runnable
* @typedef {import('./types.d.ts').MochaTimeoutError} MochaTimeoutError
* @typedef {import('./types.d.ts').PluginDefinition} PluginDefinition
*/
import { format } from "node:util";
-import { constants } from "./error-constants.mjs";
-import { isCI } from "./utils.js";
+import { constants } from "./error-constants.js";
+import { isCI } from "./utils.cjs";
/**
* Contains error codes and factory functions to create throwable error objects
diff --git a/lib/hook.mjs b/lib/hook.js
similarity index 95%
rename from lib/hook.mjs
rename to lib/hook.js
index 776a1b99..782fcf48 100644
--- a/lib/hook.mjs
+++ b/lib/hook.js
@@ -1,5 +1,5 @@
-import { Runnable } from "./runnable.mjs";
-import utils from "./utils.js";
+import { Runnable } from "./runnable.js";
+import utils from "./utils.cjs";
const { MOCHA_ID_PROP_NAME } = utils.constants;
diff --git a/lib/interfaces/bdd.mjs b/lib/interfaces/bdd.js
similarity index 95%
rename from lib/interfaces/bdd.mjs
rename to lib/interfaces/bdd.js
index c0a31a0a..01c83710 100644
--- a/lib/interfaces/bdd.mjs
+++ b/lib/interfaces/bdd.js
@@ -1,6 +1,6 @@
-import { Test } from "../test.mjs";
-import { Suite } from "../suite.mjs";
-import { createCommon } from "./common.mjs";
+import { Test } from "../test.js";
+import { Suite } from "../suite.js";
+import { createCommon } from "./common.js";
const EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE;
diff --git a/lib/interfaces/common.mjs b/lib/interfaces/common.js
similarity index 98%
rename from lib/interfaces/common.mjs
rename to lib/interfaces/common.js
index 3453791a..9f82dfc0 100644
--- a/lib/interfaces/common.mjs
+++ b/lib/interfaces/common.js
@@ -1,9 +1,9 @@
-import { Suite } from "../suite.mjs";
+import { Suite } from "../suite.js";
import {
createMissingArgumentError,
createUnsupportedError,
createForbiddenExclusivityError,
-} from "../errors.mjs";
+} from "../errors.js";
/**
* Functions common to more than one interface.
diff --git a/lib/interfaces/exports.mjs b/lib/interfaces/exports.js
similarity index 95%
rename from lib/interfaces/exports.mjs
rename to lib/interfaces/exports.js
index 8021d634..96cc09c8 100644
--- a/lib/interfaces/exports.mjs
+++ b/lib/interfaces/exports.js
@@ -1,5 +1,5 @@
-import { Suite } from "../suite.mjs";
-import { Test } from "../test.mjs";
+import { Suite } from "../suite.js";
+import { Test } from "../test.js";
/**
* Exports-style (as Node.js module) interface:
diff --git a/lib/interfaces/index.js b/lib/interfaces/index.js
new file mode 100644
index 00000000..a86fa4f1
--- /dev/null
+++ b/lib/interfaces/index.js
@@ -0,0 +1,11 @@
+import { bddInterface } from "./bdd.js";
+import { tddInterface } from "./tdd.js";
+import { qUnitInterface } from "./qunit.js";
+import { exportsInterface } from "./exports.js";
+
+export {
+ bddInterface as bdd,
+ tddInterface as tdd,
+ qUnitInterface as qunit,
+ exportsInterface as exports,
+};
diff --git a/lib/interfaces/index.mjs b/lib/interfaces/index.mjs
deleted file mode 100644
index 91dfbde4..00000000
--- a/lib/interfaces/index.mjs
+++ /dev/null
@@ -1,11 +0,0 @@
-import { bddInterface } from "./bdd.mjs";
-import { tddInterface } from "./tdd.mjs";
-import { qUnitInterface } from "./qunit.mjs";
-import { exportsInterface } from "./exports.mjs";
-
-export {
- bddInterface as bdd,
- tddInterface as tdd,
- qUnitInterface as qunit,
- exportsInterface as exports,
-};
diff --git a/lib/interfaces/qunit.mjs b/lib/interfaces/qunit.js
similarity index 94%
rename from lib/interfaces/qunit.mjs
rename to lib/interfaces/qunit.js
index 95573732..54a7899b 100644
--- a/lib/interfaces/qunit.mjs
+++ b/lib/interfaces/qunit.js
@@ -1,6 +1,6 @@
-import { Test } from "../test.mjs";
-import { Suite } from "../suite.mjs";
-import { createCommon } from "./common.mjs";
+import { Test } from "../test.js";
+import { Suite } from "../suite.js";
+import { createCommon } from "./common.js";
const EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE;
diff --git a/lib/interfaces/tdd.mjs b/lib/interfaces/tdd.js
similarity index 95%
rename from lib/interfaces/tdd.mjs
rename to lib/interfaces/tdd.js
index 88657111..40a2be1b 100644
--- a/lib/interfaces/tdd.mjs
+++ b/lib/interfaces/tdd.js
@@ -1,6 +1,6 @@
-import { Test } from "../test.mjs";
-import { Suite } from "../suite.mjs";
-import { createCommon } from "./common.mjs";
+import { Test } from "../test.js";
+import { Suite } from "../suite.js";
+import { createCommon } from "./common.js";
const EVENT_FILE_PRE_REQUIRE = Suite.constants.EVENT_FILE_PRE_REQUIRE;
diff --git a/lib/mocha.js b/lib/mocha.cjs
similarity index 97%
rename from lib/mocha.js
rename to lib/mocha.cjs
index 0de11dca..aad4cedd 100644
--- a/lib/mocha.js
+++ b/lib/mocha.cjs
@@ -6,22 +6,21 @@
* MIT Licensed
*/
-var { escapeRegExp } = require("./utils/regexp.mjs");
+var { escapeRegExp } = require("./utils/regexp.js");
var path = require("node:path");
-var builtinReporters = require("./reporters");
-var utils = require("./utils");
+var builtinReporters = require("./reporters/index.cjs");
+var utils = require("./utils.cjs");
var mocharc = require("./mocharc.json");
-var { Suite } = require("./suite.mjs");
-var esmUtils = require("./nodejs/esm-utils");
-var createStatsCollector =
- require("./stats-collector.mjs").createStatsCollector;
+var { Suite } = require("./suite.js");
+var esmUtils = require("./nodejs/esm-utils.cjs");
+var createStatsCollector = require("./stats-collector.js").createStatsCollector;
const {
createInvalidReporterError,
createInvalidInterfaceError,
createMochaInstanceAlreadyDisposedError,
createMochaInstanceAlreadyRunningError,
createUnsupportedError,
-} = require("./errors.mjs");
+} = require("./errors.js");
const { EVENT_FILE_PRE_REQUIRE, EVENT_FILE_POST_REQUIRE, EVENT_FILE_REQUIRE } =
Suite.constants;
var debug = require("debug")("mocha:mocha");
@@ -86,22 +85,22 @@ if (!utils.isBrowser() && typeof module.paths !== "undefined") {
exports.utils = utils;
// Must be extensible, see `should add the interface` test
// in `run-helpers.spec.js`
-exports.interfaces = { ...require("./interfaces/index.mjs") };
+exports.interfaces = { ...require("./interfaces/index.js") };
/**
* @public
* @memberof Mocha
*/
exports.reporters = builtinReporters;
-exports.Runnable = require("./runnable.mjs").Runnable;
-exports.Context = require("./context.mjs").Context;
+exports.Runnable = require("./runnable.js").Runnable;
+exports.Context = require("./context.js").Context;
/**
*
* @memberof Mocha
*/
-exports.Runner = require("./runner");
+exports.Runner = require("./runner.cjs");
exports.Suite = Suite;
-exports.Hook = require("./hook.mjs").Hook;
-exports.Test = require("./test.mjs").Test;
+exports.Hook = require("./hook.js").Hook;
+exports.Test = require("./test.js").Test;
let currentContext;
exports.afterEach = function (...args) {
@@ -468,7 +467,7 @@ Mocha.unloadFile = function (file) {
"unloadFile() is only supported in a Node.js environment",
);
}
- return require("./nodejs/file-unloader").unloadFile(file);
+ return require("./nodejs/file-unloader.cjs").unloadFile(file);
};
/**
@@ -972,7 +971,7 @@ Object.defineProperty(Mocha.prototype, "version", {
* @see {@link Mocha#unloadFiles}
* @see {@link Runner#run}
* @param {DoneCB} [fn] - Callback invoked when test execution completed.
- * @returns {import("./runner.js")} runner instance
+ * @returns {import("./runner.cjs")} runner instance
* @example
*
* // exit with non-zero status if there were test failures
@@ -1136,7 +1135,7 @@ Mocha.prototype.parallelMode = function parallelMode(enable = true) {
// swap Runner class
this._runnerClass = parallel
- ? require("./nodejs/parallel-buffered-runner")
+ ? require("./nodejs/parallel-buffered-runner.cjs")
: exports.Runner;
// lazyLoadFiles may have been set `true` otherwise (for ESM loading),
diff --git a/lib/nodejs/buffered-worker-pool.js b/lib/nodejs/buffered-worker-pool.cjs
similarity index 96%
rename from lib/nodejs/buffered-worker-pool.js
rename to lib/nodejs/buffered-worker-pool.cjs
index 25fd26ab..cd357df9 100644
--- a/lib/nodejs/buffered-worker-pool.js
+++ b/lib/nodejs/buffered-worker-pool.cjs
@@ -15,11 +15,11 @@
const serializeJavascript = require("serialize-javascript");
const workerpool = require("workerpool");
-const { deserialize } = require("./serializer.mjs");
+const { deserialize } = require("./serializer.js");
const debug = require("debug")("mocha:parallel:buffered-worker-pool");
-const { createInvalidArgumentTypeError } = require("../errors.mjs");
+const { createInvalidArgumentTypeError } = require("../errors.js");
-const WORKER_PATH = require.resolve("./worker.js");
+const WORKER_PATH = require.resolve("./worker.cjs");
/**
* A mapping of Mocha `Options` objects to serialized values.
diff --git a/lib/nodejs/esm-utils.js b/lib/nodejs/esm-utils.cjs
similarity index 99%
rename from lib/nodejs/esm-utils.js
rename to lib/nodejs/esm-utils.cjs
index 16a47767..31c66695 100644
--- a/lib/nodejs/esm-utils.js
+++ b/lib/nodejs/esm-utils.cjs
@@ -1,7 +1,7 @@
const path = require("node:path");
const url = require("node:url");
const debug = require("debug")("mocha:esm-utils");
-const { isMochaError } = require("../errors.mjs");
+const { isMochaError } = require("../errors.js");
const forward = (x) => x;
diff --git a/lib/nodejs/file-unloader.js b/lib/nodejs/file-unloader.cjs
similarity index 100%
rename from lib/nodejs/file-unloader.js
rename to lib/nodejs/file-unloader.cjs
diff --git a/lib/nodejs/parallel-buffered-runner.js b/lib/nodejs/parallel-buffered-runner.cjs
similarity index 97%
rename from lib/nodejs/parallel-buffered-runner.js
rename to lib/nodejs/parallel-buffered-runner.cjs
index 9d5e1b72..de2d8128 100644
--- a/lib/nodejs/parallel-buffered-runner.js
+++ b/lib/nodejs/parallel-buffered-runner.cjs
@@ -13,17 +13,17 @@
* @typedef {import('../types.d.ts').SigIntListener} SigIntListener
*/
-const Runner = require("../runner");
+const Runner = require("../runner.cjs");
const { EVENT_RUN_BEGIN, EVENT_RUN_END } = Runner.constants;
const debug = require("debug")("mocha:parallel:parallel-buffered-runner");
-const { BufferedWorkerPool } = require("./buffered-worker-pool");
+const { BufferedWorkerPool } = require("./buffered-worker-pool.cjs");
const { setInterval, clearInterval } = global;
-const { createMap, constants } = require("../utils");
+const { createMap, constants } = require("../utils.cjs");
const { MOCHA_ID_PROP_NAME } = constants;
-const { createFatalError } = require("../errors.mjs");
+const { createFatalError } = require("../errors.js");
const DEFAULT_WORKER_REPORTER =
- require.resolve("./reporters/parallel-buffered");
+ require.resolve("./reporters/parallel-buffered.cjs");
/**
* List of options to _not_ serialize for transmission to workers
diff --git a/lib/nodejs/reporters/parallel-buffered.js b/lib/nodejs/reporters/parallel-buffered.cjs
similarity index 96%
rename from lib/nodejs/reporters/parallel-buffered.js
rename to lib/nodejs/reporters/parallel-buffered.cjs
index cdde3a38..1fb0c0ca 100644
--- a/lib/nodejs/reporters/parallel-buffered.js
+++ b/lib/nodejs/reporters/parallel-buffered.cjs
@@ -8,7 +8,7 @@
/**
* @typedef {import('../../types.d.ts').BufferedEvent} BufferedEvent
- * @typedef {import('../../runner.js')} Runner
+ * @typedef {import('../../runner.cjs')} Runner
*/
/**
@@ -29,13 +29,13 @@ const {
EVENT_HOOK_BEGIN,
EVENT_HOOK_END,
EVENT_RUN_END,
-} = require("../../runner").constants;
+} = require("../../runner.cjs").constants;
const {
SerializableEvent,
SerializableWorkerResult,
-} = require("../serializer.mjs");
+} = require("../serializer.js");
const debug = require("debug")("mocha:reporters:buffered");
-const { Base } = require("../../reporters/base.mjs");
+const { Base } = require("../../reporters/base.js");
/**
* List of events to listen to; these will be buffered and sent
diff --git a/lib/nodejs/serializer.mjs b/lib/nodejs/serializer.js
similarity index 99%
rename from lib/nodejs/serializer.mjs
rename to lib/nodejs/serializer.js
index ee6a84ac..74e41a10 100644
--- a/lib/nodejs/serializer.mjs
+++ b/lib/nodejs/serializer.js
@@ -9,8 +9,8 @@
* @typedef {import('../types.d.ts').SerializedWorkerResult} SerializedWorkerResult
*/
-import { type, breakCircularDeps } from "../utils.js";
-import { createInvalidArgumentTypeError } from "../errors.mjs";
+import { type, breakCircularDeps } from "../utils.cjs";
+import { createInvalidArgumentTypeError } from "../errors.js";
import d from "debug";
// this is not named `mocha:parallel:serializer` because it's noisy and it's
diff --git a/lib/nodejs/worker.js b/lib/nodejs/worker.cjs
similarity index 95%
rename from lib/nodejs/worker.js
rename to lib/nodejs/worker.cjs
index 45505608..3aec72bd 100644
--- a/lib/nodejs/worker.js
+++ b/lib/nodejs/worker.cjs
@@ -14,14 +14,17 @@
const {
createInvalidArgumentTypeError,
createInvalidArgumentValueError,
-} = require("../errors.mjs");
+} = require("../errors.js");
const workerpool = require("workerpool");
-const Mocha = require("../mocha");
-const { handleRequires, validateLegacyPlugin } = require("../cli/run-helpers");
+const Mocha = require("../mocha.cjs");
+const {
+ handleRequires,
+ validateLegacyPlugin,
+} = require("../cli/run-helpers.cjs");
const d = require("debug");
const debug = d.debug(`mocha:parallel:worker:${process.pid}`);
const isDebugEnabled = d.enabled(`mocha:parallel:worker:${process.pid}`);
-const { serialize } = require("./serializer.mjs");
+const { serialize } = require("./serializer.js");
const { setInterval, clearInterval } = global;
let rootHooks;
diff --git a/lib/pending.mjs b/lib/pending.js
similarity index 100%
rename from lib/pending.mjs
rename to lib/pending.js
diff --git a/lib/plugin-loader.mjs b/lib/plugin-loader.js
similarity index 99%
rename from lib/plugin-loader.mjs
rename to lib/plugin-loader.js
index 0bf903c0..c873be43 100644
--- a/lib/plugin-loader.mjs
+++ b/lib/plugin-loader.js
@@ -17,8 +17,8 @@ import debugModule from "debug";
import {
createInvalidPluginDefinitionError,
createInvalidPluginImplementationError,
-} from "./errors.mjs";
-import { castArray } from "./utils.js";
+} from "./errors.js";
+import { castArray } from "./utils.cjs";
const debug = debugModule("mocha:plugin-loader");
/**
diff --git a/lib/reporters/base.mjs b/lib/reporters/base.js
similarity index 98%
rename from lib/reporters/base.mjs
rename to lib/reporters/base.js
index c4f3ff88..e537ed9b 100644
--- a/lib/reporters/base.mjs
+++ b/lib/reporters/base.js
@@ -1,6 +1,6 @@
/**
- * @typedef {import('../runner.js')} Runner
- * @typedef {import('../test.mjs')} Test
+ * @typedef {import('../runner.cjs')} Runner
+ * @typedef {import('../test.js')} Test
* @typedef {import('../types.d.ts').FullErrorStack} FullErrorStack
*/
@@ -13,9 +13,9 @@
import * as diff from "diff";
import milliseconds from "ms";
-import utils from "../utils.js";
+import utils from "../utils.cjs";
import supportsColor from "supports-color";
-import Runner from "../runner.js";
+import Runner from "../runner.cjs";
const { constants } = Runner;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
diff --git a/lib/reporters/doc.mjs b/lib/reporters/doc.js
similarity index 94%
rename from lib/reporters/doc.mjs
rename to lib/reporters/doc.js
index 5a2a8039..62e33e3a 100644
--- a/lib/reporters/doc.mjs
+++ b/lib/reporters/doc.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,9 +9,9 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import utils from "../utils.js";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import utils from "../utils.cjs";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
diff --git a/lib/reporters/dot.mjs b/lib/reporters/dot.js
similarity index 93%
rename from lib/reporters/dot.mjs
rename to lib/reporters/dot.js
index b1c70c52..eac37b81 100644
--- a/lib/reporters/dot.mjs
+++ b/lib/reporters/dot.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,8 +9,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var { constants } = Runner;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
diff --git a/lib/reporters/html.mjs b/lib/reporters/html.js
similarity index 98%
rename from lib/reporters/html.mjs
rename to lib/reporters/html.js
index 2917cde7..b806e567 100644
--- a/lib/reporters/html.mjs
+++ b/lib/reporters/html.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,10 +9,10 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import utils from "../utils.js";
-import { escapeRegExp } from "../utils/regexp.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import utils from "../utils.cjs";
+import { escapeRegExp } from "../utils/regexp.js";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
diff --git a/lib/reporters/index.js b/lib/reporters/index.cjs
similarity index 54%
rename from lib/reporters/index.js
rename to lib/reporters/index.cjs
index 9758ea46..c813eda7 100644
--- a/lib/reporters/index.js
+++ b/lib/reporters/index.cjs
@@ -2,33 +2,33 @@
// Alias exports to a their normalized format Mocha#reporter to prevent a need
// for dynamic (try/catch) requires, which Browserify doesn't handle.
-const { Base } = require("./base.mjs");
+const { Base } = require("./base.js");
exports.Base = exports.base = Base;
-const { Dot } = require("./dot.mjs");
+const { Dot } = require("./dot.js");
exports.Dot = exports.dot = Dot;
-const { Doc } = require("./doc.mjs");
+const { Doc } = require("./doc.js");
exports.Doc = exports.doc = Doc;
-const { TAP } = require("./tap.mjs");
+const { TAP } = require("./tap.js");
exports.TAP = exports.tap = TAP;
-const { JSONReporter } = require("./json.mjs");
+const { JSONReporter } = require("./json.js");
exports.JSON = exports.json = JSONReporter;
-const { HTML } = require("./html.mjs");
+const { HTML } = require("./html.js");
exports.HTML = exports.html = HTML;
-const { List } = require("./list.mjs");
+const { List } = require("./list.js");
exports.List = exports.list = List;
-const { Min } = require("./min.mjs");
+const { Min } = require("./min.js");
exports.Min = exports.min = Min;
-const { Spec } = require("./spec.mjs");
+const { Spec } = require("./spec.js");
exports.Spec = exports.spec = Spec;
-const { NyanCat } = require("./nyan.mjs");
+const { NyanCat } = require("./nyan.js");
exports.Nyan = exports.nyan = NyanCat;
-const { XUnit } = require("./xunit.mjs");
+const { XUnit } = require("./xunit.js");
exports.XUnit = exports.xunit = XUnit;
-const { Markdown } = require("./markdown.mjs");
+const { Markdown } = require("./markdown.js");
exports.Markdown = exports.markdown = Markdown;
-const { Progress } = require("./progress.mjs");
+const { Progress } = require("./progress.js");
exports.Progress = exports.progress = Progress;
-const { Landing } = require("./landing.mjs");
+const { Landing } = require("./landing.js");
exports.Landing = exports.landing = Landing;
-const { JSONStream } = require("./json-stream.mjs");
+const { JSONStream } = require("./json-stream.js");
exports.JSONStream = exports["json-stream"] = JSONStream;
diff --git a/lib/reporters/json-stream.mjs b/lib/reporters/json-stream.js
similarity index 92%
rename from lib/reporters/json-stream.mjs
rename to lib/reporters/json-stream.js
index 5b200818..a4e11852 100644
--- a/lib/reporters/json-stream.mjs
+++ b/lib/reporters/json-stream.js
@@ -1,6 +1,6 @@
/**
- * @typedef {import('../runner.js')} Runner
- * @typedef {import('../test.mjs')} Test
+ * @typedef {import('../runner.cjs')} Runner
+ * @typedef {import('../test.js')} Test
*/
/**
@@ -10,8 +10,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
diff --git a/lib/reporters/json.mjs b/lib/reporters/json.js
similarity index 95%
rename from lib/reporters/json.mjs
rename to lib/reporters/json.js
index e2dedf9c..66ee9e29 100644
--- a/lib/reporters/json.mjs
+++ b/lib/reporters/json.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,12 +9,12 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
+import { Base } from "./base.js";
import fs from "node:fs";
import path from "node:path";
-import * as errors from "../errors.mjs";
-import utils from "../utils.js";
-import Runner from "../runner.js";
+import * as errors from "../errors.js";
+import utils from "../utils.cjs";
+import Runner from "../runner.cjs";
const createUnsupportedError = errors.createUnsupportedError;
var constants = Runner.constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
diff --git a/lib/reporters/landing.mjs b/lib/reporters/landing.js
similarity index 93%
rename from lib/reporters/landing.mjs
rename to lib/reporters/landing.js
index 42749bc6..d6831d3b 100644
--- a/lib/reporters/landing.mjs
+++ b/lib/reporters/landing.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,9 +9,9 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
-import { Runnable } from "../runnable.mjs";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
+import { Runnable } from "../runnable.js";
var constants = Runner.constants;
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
var EVENT_RUN_END = constants.EVENT_RUN_END;
diff --git a/lib/reporters/list.mjs b/lib/reporters/list.js
similarity index 93%
rename from lib/reporters/list.mjs
rename to lib/reporters/list.js
index 7bd36e11..ada2c35e 100644
--- a/lib/reporters/list.mjs
+++ b/lib/reporters/list.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,8 +9,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var { constants } = Runner;
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
diff --git a/lib/reporters/markdown.mjs b/lib/reporters/markdown.js
similarity index 94%
rename from lib/reporters/markdown.mjs
rename to lib/reporters/markdown.js
index b6047aaf..2e6848f9 100644
--- a/lib/reporters/markdown.mjs
+++ b/lib/reporters/markdown.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,9 +9,9 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import utils from "../utils.js";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import utils from "../utils.cjs";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_RUN_END = constants.EVENT_RUN_END;
var EVENT_SUITE_BEGIN = constants.EVENT_SUITE_BEGIN;
diff --git a/lib/reporters/min.mjs b/lib/reporters/min.js
similarity index 89%
rename from lib/reporters/min.mjs
rename to lib/reporters/min.js
index 1d8d6b40..5e0953e1 100644
--- a/lib/reporters/min.mjs
+++ b/lib/reporters/min.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,8 +9,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var { constants } = Runner;
var EVENT_RUN_END = constants.EVENT_RUN_END;
diff --git a/lib/reporters/nyan.mjs b/lib/reporters/nyan.js
similarity index 97%
rename from lib/reporters/nyan.mjs
rename to lib/reporters/nyan.js
index ab12ce71..aa414432 100644
--- a/lib/reporters/nyan.mjs
+++ b/lib/reporters/nyan.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,8 +9,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
var EVENT_TEST_PENDING = constants.EVENT_TEST_PENDING;
diff --git a/lib/reporters/progress.mjs b/lib/reporters/progress.js
similarity index 95%
rename from lib/reporters/progress.mjs
rename to lib/reporters/progress.js
index e610882c..b4a5d55a 100644
--- a/lib/reporters/progress.mjs
+++ b/lib/reporters/progress.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('../runner.js')} Runner
+ * @typedef {import('../runner.cjs')} Runner
*/
/**
@@ -9,8 +9,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
var EVENT_TEST_END = constants.EVENT_TEST_END;
diff --git a/lib/reporters/spec.mjs b/lib/reporters/spec.js
similarity index 93%
rename from lib/reporters/spec.mjs
rename to lib/reporters/spec.js
index 0044f183..1aed1421 100644
--- a/lib/reporters/spec.mjs
+++ b/lib/reporters/spec.js
@@ -1,6 +1,6 @@
/**
- * @typedef {import('../runner.js')} Runner
- * @typedef {import('../test.mjs')} Test
+ * @typedef {import('../runner.cjs')} Runner
+ * @typedef {import('../test.js')} Test
*/
/**
@@ -10,8 +10,8 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_RUN_BEGIN = constants.EVENT_RUN_BEGIN;
var EVENT_RUN_END = constants.EVENT_RUN_END;
diff --git a/lib/reporters/tap.mjs b/lib/reporters/tap.js
similarity index 97%
rename from lib/reporters/tap.mjs
rename to lib/reporters/tap.js
index 108aa809..384dbfa8 100644
--- a/lib/reporters/tap.mjs
+++ b/lib/reporters/tap.js
@@ -1,6 +1,6 @@
/**
- * @typedef {import('../runner.js')} Runner
- * @typedef {import('../test.mjs')} Test
+ * @typedef {import('../runner.cjs')} Runner
+ * @typedef {import('../test.js')} Test
*/
/**
@@ -11,8 +11,8 @@
*/
import util from "node:util";
-import { Base } from "./base.mjs";
-import Runner from "../runner.js";
+import { Base } from "./base.js";
+import Runner from "../runner.cjs";
var constants = Runner.constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
var EVENT_TEST_FAIL = constants.EVENT_TEST_FAIL;
diff --git a/lib/reporters/xunit.mjs b/lib/reporters/xunit.js
similarity index 94%
rename from lib/reporters/xunit.mjs
rename to lib/reporters/xunit.js
index 802bbf26..4842890b 100644
--- a/lib/reporters/xunit.mjs
+++ b/lib/reporters/xunit.js
@@ -1,6 +1,6 @@
/**
- * @typedef {import('../runner.js')} Runner
- * @typedef {import('../test.mjs')} Test
+ * @typedef {import('../runner.cjs')} Runner
+ * @typedef {import('../test.js')} Test
*/
/**
@@ -10,13 +10,13 @@
* Module dependencies.
*/
-import { Base } from "./base.mjs";
-import utils from "../utils.js";
+import { Base } from "./base.js";
+import utils from "../utils.cjs";
import fs from "node:fs";
import path from "node:path";
-import * as errors from "../errors.mjs";
-import Runner from "../runner.js";
-import { Runnable } from "../runnable.mjs";
+import * as errors from "../errors.js";
+import Runner from "../runner.cjs";
+import { Runnable } from "../runnable.js";
var createUnsupportedError = errors.createUnsupportedError;
var constants = Runner.constants;
var EVENT_TEST_PASS = constants.EVENT_TEST_PASS;
diff --git a/lib/runnable.mjs b/lib/runnable.js
similarity index 99%
rename from lib/runnable.mjs
rename to lib/runnable.js
index 0d83917f..db55c03e 100644
--- a/lib/runnable.mjs
+++ b/lib/runnable.js
@@ -1,13 +1,13 @@
import { EventEmitter } from "node:events";
-import { PendingError } from "./pending.mjs";
+import { PendingError } from "./pending.js";
import debugModule from "debug";
import milliseconds from "ms";
-import utils from "./utils.js";
+import utils from "./utils.cjs";
import {
createInvalidExceptionError,
createMultipleDoneError,
createTimeoutError,
-} from "./errors.mjs";
+} from "./errors.js";
const debug = debugModule("mocha:runnable");
diff --git a/lib/runner.js b/lib/runner.cjs
similarity index 99%
rename from lib/runner.js
rename to lib/runner.cjs
index dfa5f373..4ebadc50 100644
--- a/lib/runner.js
+++ b/lib/runner.cjs
@@ -9,11 +9,11 @@
* @private
*/
var EventEmitter = require("node:events").EventEmitter;
-var { PendingError } = require("./pending.mjs");
-var utils = require("./utils");
+var { PendingError } = require("./pending.js");
+var utils = require("./utils.cjs");
var debug = require("debug")("mocha:runner");
-var { Runnable } = require("./runnable.mjs");
-var { Suite } = require("./suite.mjs");
+var { Runnable } = require("./runnable.js");
+var { Suite } = require("./suite.js");
var HOOK_TYPE_BEFORE_EACH = Suite.constants.HOOK_TYPE_BEFORE_EACH;
var HOOK_TYPE_AFTER_EACH = Suite.constants.HOOK_TYPE_AFTER_EACH;
var HOOK_TYPE_AFTER_ALL = Suite.constants.HOOK_TYPE_AFTER_ALL;
@@ -30,8 +30,8 @@ const {
createUnsupportedError,
createFatalError,
isMochaError,
-} = require("./errors.mjs");
-const { constants: errorConstants } = require("./error-constants.mjs");
+} = require("./errors.js");
+const { constants: errorConstants } = require("./error-constants.js");
/**
* Non-enumerable globals.
diff --git a/lib/stats-collector.mjs b/lib/stats-collector.js
similarity index 94%
rename from lib/stats-collector.mjs
rename to lib/stats-collector.js
index 00c07c0d..6e7cfdbd 100644
--- a/lib/stats-collector.mjs
+++ b/lib/stats-collector.js
@@ -1,6 +1,6 @@
/**
* @typedef {import('./types.d.ts').StatsCollector} StatsCollector
- * @typedef {import('./runner.js')} Runner
+ * @typedef {import('./runner.cjs')} Runner
*/
/**
@@ -8,7 +8,7 @@
* @module
*/
-import Runner from "./runner.js";
+import Runner from "./runner.cjs";
const {
EVENT_TEST_PASS,
diff --git a/lib/suite.mjs b/lib/suite.js
similarity index 99%
rename from lib/suite.mjs
rename to lib/suite.js
index 50b5e494..ff78e2b0 100644
--- a/lib/suite.mjs
+++ b/lib/suite.js
@@ -1,5 +1,5 @@
/**
- * @typedef {import('./test.mjs')} Test
+ * @typedef {import('./test.js')} Test
*/
/**
@@ -7,11 +7,11 @@
* @private
*/
import { EventEmitter } from "node:events";
-import { Hook } from "./hook.mjs";
-import utils from "./utils.js";
+import { Hook } from "./hook.js";
+import utils from "./utils.cjs";
import debugModule from "debug";
import milliseconds from "ms";
-import * as errors from "./errors.mjs";
+import * as errors from "./errors.js";
const {
assignNewMochaID,
diff --git a/lib/test.mjs b/lib/test.js
similarity index 94%
rename from lib/test.mjs
rename to lib/test.js
index 21520027..de69a082 100644
--- a/lib/test.mjs
+++ b/lib/test.js
@@ -1,6 +1,6 @@
-import { Runnable } from "./runnable.mjs";
-import utils from "./utils.js";
-import { createInvalidArgumentTypeError } from "./errors.mjs";
+import { Runnable } from "./runnable.js";
+import utils from "./utils.cjs";
+import { createInvalidArgumentTypeError } from "./errors.js";
const { isString } = utils;
const { MOCHA_ID_PROP_NAME } = utils.constants;
diff --git a/lib/types.d.ts b/lib/types.d.ts
index 7b5e9858..1f35eb5f 100644
--- a/lib/types.d.ts
+++ b/lib/types.d.ts
@@ -8,9 +8,9 @@ import type { FSWatcher, MatchFunction } from "chokidar" with {
"resolution-mode": "import",
};
-import type { constants } from "./error-constants.mjs";
-import type Mocha from "./mocha.js";
-import Runner from "./runner.js";
+import type { constants } from "./error-constants.js";
+import type Mocha from "./mocha.cjs";
+import Runner from "./runner.cjs";
/**
* Command-line options
diff --git a/lib/utils.js b/lib/utils.cjs
similarity index 100%
rename from lib/utils.js
rename to lib/utils.cjs
diff --git a/lib/utils/regexp.mjs b/lib/utils/regexp.js
similarity index 100%
rename from lib/utils/regexp.mjs
rename to lib/utils/regexp.js
diff --git a/mocha.mjs b/mocha.mjs
index b0fd9ce2..27f17859 100644
--- a/mocha.mjs
+++ b/mocha.mjs
@@ -1,3 +1,5 @@
+// This file is `/mocha.mjs` because the built file is `/mocha.js`
+
// the .js built file is not committed to the repo
/* eslint-disable-next-line n/no-missing-import */
import "./mocha.js";
diff --git a/package-lock.json b/package-lock.json
index b8df25f5..f87f2a3d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -31,7 +31,7 @@
"yargs-unparser": "^2.0.0"
},
"bin": {
- "mocha": "bin/mocha.mjs"
+ "mocha": "bin/mocha.js"
},
"devDependencies": {
"@eslint/js": "^10.0.0",
diff --git a/package.json b/package.json
index aca85f8a..13f70fe2 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mocha",
"version": "12.0.0-beta-9.6",
- "type": "commonjs",
+ "type": "module",
"description": "Classic, reliable, trusted test framework for Node.js and the browser",
"keywords": [
"mocha",
@@ -32,7 +32,7 @@
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
"notifyLogo": "https://ibin.co/4QuRuGjXvl36.png",
"bin": {
- "mocha": "./bin/mocha.mjs"
+ "mocha": "./bin/mocha.js"
},
"directories": {
"lib": "./lib",
@@ -42,7 +42,7 @@
"node": "^20.19.0 || >=22.12.0"
},
"scripts": {
- "build": "rollup -c ./rollup.config.mjs",
+ "build": "rollup -c ./rollup.config.js",
"clean": "rimraf mocha.js mocha.js.map",
"docs": "cd docs; npm run docs",
"format:check": "prettier --check .",
@@ -56,34 +56,34 @@
"prepublishOnly": "run-s clean build version",
"pretest-browser:playwright": "playwright install chromium --with-deps",
"test-browser:playwright": "playwright test",
- "test-browser:webpack-compat": "webpack --mode development --config ./test/browser-specific/fixtures/webpack/webpack.config.js",
+ "test-browser:webpack-compat": "webpack --mode development --config ./test/browser-specific/fixtures/webpack/webpack.config.cjs",
"test-browser": "run-s clean build test-browser:*",
"test-coverage-clean": "rimraf .nyc_output coverage",
"test-coverage-generate": "nyc report --reporter=lcov --reporter=text",
- "test-node-run-only": "cross-env NODE_OPTIONS=--enable-source-maps nyc --no-clean --reporter=json node bin/mocha.mjs --no-forbid-only",
- "test-node-run": "cross-env NODE_OPTIONS=--enable-source-maps nyc --no-clean --reporter=json node bin/mocha.mjs --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:watch": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/options/watch.spec.js\"",
+ "test-node-run-only": "cross-env NODE_OPTIONS=--enable-source-maps nyc --no-clean --reporter=json node bin/mocha.js --no-forbid-only",
+ "test-node-run": "cross-env NODE_OPTIONS=--enable-source-maps 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.cjs\"",
+ "test-node:integration:watch": "run-s clean build && npm run -s test-node-run -- --parallel --timeout 10000 --slow 3750 \"test/integration/options/watch.spec.cjs\"",
"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",
"test-node:interfaces:tdd": "npm run -s test-node-run -- --ui tdd test/interfaces/tdd.spec",
"test-node:interfaces": "run-p test-node:interfaces:*",
- "test-node:jsapi": "node test/jsapi/index.mjs",
+ "test-node:jsapi": "node test/jsapi/index.js",
"test-node:only:bddRequire": "npm run -s test-node-run-only -- --ui qunit test/only/bdd-require.spec --no-parallel",
"test-node:only:globalBdd": "npm run -s test-node-run-only -- --ui bdd test/only/global/bdd.spec --no-parallel",
"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,mjs}\"",
- "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:reporters": "npm run -s test-node-run -- \"test/reporters/*.spec.{cjs,js}\"",
+ "test-node:requires": "npm run -s test-node-run -- --require coffeescript/register --require test/require/a.cjs --require test/require/b.coffee --require test/require/c.cjs --require test/require/d.coffee test/require/require.spec.cjs",
+ "test-node:unit": "npm run -s test-node-run -- \"test/unit/**/*.spec.cjs\" \"test/node-unit/**/*.spec.{cjs,js}\"",
"test-node": "run-s test-coverage-clean test-node:* test-coverage-generate",
- "test-smoke": "node ./bin/mocha.mjs --no-config test/smoke/smoke.spec.js",
+ "test-smoke": "node ./bin/mocha.js --no-config test/smoke/smoke.spec.cjs",
"test": "run-s lint test-node test-browser",
"tsc": "tsc",
- "version:linkify-changelog": "node scripts/linkify-changelog.mjs",
- "version:update-authors": "node scripts/update-authors.js",
+ "version:linkify-changelog": "node scripts/linkify-changelog.js",
+ "version:update-authors": "node scripts/update-authors.cjs",
"version": "run-p version:* && git add -A ./AUTHORS ./CHANGELOG.md"
},
"dependencies": {
@@ -155,27 +155,27 @@
"lib/**/*.html",
"lib/**/*.js",
"lib/**/*.json",
- "lib/**/*.mjs",
- "index.mjs",
+ "lib/**/*.cjs",
+ "index.js",
"mocha.css",
"mocha.js",
"mocha.js.map",
"mocha.mjs",
- "browser-entry.mjs"
+ "browser-entry.js"
],
"browser": {
- "./index.mjs": "./browser-entry.mjs",
+ "./index.js": "./browser-entry.js",
"fs": false,
"path": false,
"supports-color": false,
- "./lib/nodejs/buffered-worker-pool.js": false,
- "./lib/nodejs/esm-utils.js": false,
- "./lib/nodejs/file-unloader.js": false,
- "./lib/nodejs/parallel-buffered-runner.js": false,
- "./lib/nodejs/serializer.mjs": false,
- "./lib/nodejs/worker.js": false,
- "./lib/nodejs/reporters/parallel-buffered.js": false,
- "./lib/cli/index.js": false
+ "./lib/nodejs/buffered-worker-pool.cjs": false,
+ "./lib/nodejs/esm-utils.cjs": false,
+ "./lib/nodejs/file-unloader.cjs": false,
+ "./lib/nodejs/parallel-buffered-runner.cjs": false,
+ "./lib/nodejs/serializer.js": false,
+ "./lib/nodejs/worker.cjs": false,
+ "./lib/nodejs/reporters/parallel-buffered.cjs": false,
+ "./lib/cli/index.cjs": false
},
"overrides": {
"@types/eslint": "^9.6.1",
diff --git a/playwright.config.mjs b/playwright.config.js
similarity index 76%
rename from playwright.config.mjs
rename to playwright.config.js
index be39f8d1..f67d273c 100644
--- a/playwright.config.mjs
+++ b/playwright.config.js
@@ -1,6 +1,6 @@
import { defineConfig } from "@playwright/test";
-import { baseURL } from "./test/browser/config.mjs";
+import { baseURL } from "./test/browser/config.js";
export default defineConfig({
testDir: "./test/browser",
@@ -8,14 +8,14 @@ export default defineConfig({
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
reporter: process.env.CI ? "github" : "list",
- globalSetup: "./test/browser/global-setup.mjs",
+ globalSetup: "./test/browser/global-setup.js",
use: {
baseURL,
trace: "on-first-retry",
},
projects: [{ name: "chromium", use: { browserName: "chromium" } }],
webServer: {
- command: "node test/browser/server.mjs",
+ command: "node test/browser/server.js",
url: baseURL,
reuseExistingServer: !process.env.CI,
timeout: 60_000,
diff --git a/rollup.config.mjs b/rollup.config.js
similarity index 97%
rename from rollup.config.mjs
rename to rollup.config.js
index 965a6d9e..021d39a3 100644
--- a/rollup.config.mjs
+++ b/rollup.config.js
@@ -7,11 +7,11 @@ import nodePolyfills from "rollup-plugin-polyfill-node";
// Debugging tools
import { visualizer } from "rollup-plugin-visualizer";
-import pickFromPackageJson from "./scripts/pick-from-package-json.mjs";
+import pickFromPackageJson from "./scripts/pick-from-package-json.js";
import packageJson from "./package.json" with { type: "json" };
const config = {
- input: "./browser-entry.mjs",
+ input: "./browser-entry.js",
strictDeprecations: true,
output: {
file: "./mocha.js",
diff --git a/scripts/linkify-changelog.mjs b/scripts/linkify-changelog.js
similarity index 100%
rename from scripts/linkify-changelog.mjs
rename to scripts/linkify-changelog.js
diff --git a/scripts/pick-from-package-json.mjs b/scripts/pick-from-package-json.js
similarity index 100%
rename from scripts/pick-from-package-json.mjs
rename to scripts/pick-from-package-json.js
diff --git a/scripts/update-authors.js b/scripts/update-authors.cjs
similarity index 96%
rename from scripts/update-authors.js
rename to scripts/update-authors.cjs
index 32ac8db5..c9c92349 100755
--- a/scripts/update-authors.js
+++ b/scripts/update-authors.cjs
@@ -55,5 +55,5 @@ rl.on("line", (line) => {
});
rl.on("close", () => {
- output.end("\n# Generated by scripts/update-authors.js\n");
+ output.end("\n# Generated by scripts/update-authors.cjs\n");
});
diff --git a/test/README.md b/test/README.md
index c3de4e1d..512f3db0 100644
--- a/test/README.md
+++ b/test/README.md
@@ -2,14 +2,14 @@
- **All assertions should be made using [unexpected](http://unexpected.js.org)**, unless there's a good reason not to. Exceptions include:
- Testing diff output. Mocha generates diff output unless the assertion library decides to do this itself. Since `unexpected` generates its _own_ diff output, we need to use an assertion library that does not; we use the built-in `assert` module.
- - `test/unit/runnable.spec.js` must avoid 3rd-party code; read source for more info
+ - `test/unit/runnable.spec.cjs` must avoid 3rd-party code; read source for more info
- Tests asserting interop with other specific assertion libraries.
- All tests have extension `.spec.js`.
- All test fixtures have extension `.fixture.js`.
- All test fixtures are _ignored_ by ESLint.
-- `mocha.opts` will require `test/setup.js`, which is the main harness.
-- `test/assertions.js` contains Mocha-specific types and assertions for `unexpected`
+- `mocha.opts` will require `test/setup.cjs`, which is the main harness.
+- `test/assertions.cjs` contains Mocha-specific types and assertions for `unexpected`
- `test/node-unit/` only runs in Node.js; `test/browser-specific/` only runs in the browser.
- - See `./browser/config.mjs` for the list of suites that run in the browser via Playwright.
+ - See `./browser/config.js` for the list of suites that run in the browser via Playwright.
- We can't run all of the Node.js tests in one `mocha` command, because we need to use different command-line options to test the various reporters and interfaces.
- See `../package-scripts.js` for more info about how things are split up.
diff --git a/test/assertions.js b/test/assertions.cjs
similarity index 99%
rename from test/assertions.js
rename to test/assertions.cjs
index b3913344..10befd81 100644
--- a/test/assertions.js
+++ b/test/assertions.cjs
@@ -1,7 +1,7 @@
"use strict";
const { version } = require("../package.json");
-const { escapeRegExp } = require("../lib/utils/regexp.mjs");
+const { escapeRegExp } = require("../lib/utils/regexp.js");
module.exports = {
name: "unexpected-mocha-internal",
diff --git a/test/browser-specific/esm.spec.mjs b/test/browser-specific/esm.spec.js
similarity index 84%
rename from test/browser-specific/esm.spec.mjs
rename to test/browser-specific/esm.spec.js
index 48aacd33..e2ad6a01 100644
--- a/test/browser-specific/esm.spec.mjs
+++ b/test/browser-specific/esm.spec.js
@@ -1,4 +1,4 @@
-import "./fixtures/esm.fixture.mjs";
+import "./fixtures/esm.fixture.js";
it("should register a global if it did not fail", function () {
expect(window.MOCHA_IS_OK, "to be ok");
diff --git a/test/browser-specific/fixtures/esm.fixture.mjs b/test/browser-specific/fixtures/esm.fixture.js
similarity index 100%
rename from test/browser-specific/fixtures/esm.fixture.mjs
rename to test/browser-specific/fixtures/esm.fixture.js
diff --git a/test/browser-specific/fixtures/webpack/webpack.config.js b/test/browser-specific/fixtures/webpack/webpack.config.cjs
similarity index 87%
rename from test/browser-specific/fixtures/webpack/webpack.config.js
rename to test/browser-specific/fixtures/webpack/webpack.config.cjs
index 5da4c1a6..5e4d705f 100644
--- a/test/browser-specific/fixtures/webpack/webpack.config.js
+++ b/test/browser-specific/fixtures/webpack/webpack.config.cjs
@@ -9,7 +9,7 @@ console.error('output dir: %s', outputPath);
module.exports = {
bail: true,
- entry: require.resolve('./webpack.fixture.mjs'),
+ entry: require.resolve('./webpack.fixture.js'),
target: 'browserslist:last 2 Chrome versions',
output: {
path: outputPath,
diff --git a/test/browser-specific/fixtures/webpack/webpack.fixture.mjs b/test/browser-specific/fixtures/webpack/webpack.fixture.js
similarity index 100%
rename from test/browser-specific/fixtures/webpack/webpack.fixture.mjs
rename to test/browser-specific/fixtures/webpack/webpack.fixture.js
diff --git a/test/browser-specific/setup.js b/test/browser-specific/setup.cjs
similarity index 100%
rename from test/browser-specific/setup.js
rename to test/browser-specific/setup.cjs
diff --git a/test/browser/config.mjs b/test/browser/config.js
similarity index 91%
rename from test/browser/config.mjs
rename to test/browser/config.js
index 00548385..ca40e3f5 100644
--- a/test/browser/config.mjs
+++ b/test/browser/config.js
@@ -5,8 +5,8 @@ export const PORT = Number(process.env.MOCHA_BROWSER_TEST_PORT) || 8787;
export const baseURL = `http://localhost:${PORT}`;
-// The bundled setup.js file is generated by global-setup.mjs and served from this location.
-export const SETUP_BUNDLE_PATH = "test/browser/.generated/setup.js";
+// This file is generated by global-setup.js
+export const SETUP_BUNDLE_PATH = "test/browser/.generated/setup.cjs";
/**
* @typedef {object} BrowserSuite
@@ -21,5 +21,5 @@ export const suites = [
{ name: "bdd", ui: "bdd", specs: ["/test/interfaces/bdd.spec.js"] },
{ name: "tdd", ui: "tdd", specs: ["/test/interfaces/tdd.spec.js"] },
{ name: "qunit", ui: "qunit", specs: ["/test/interfaces/qunit.spec.js"] },
- { name: "esm", ui: "bdd", modules: ["/test/browser-specific/esm.spec.mjs"] },
+ { name: "esm", ui: "bdd", modules: ["/test/browser-specific/esm.spec.js"] },
];
diff --git a/test/browser/global-setup.mjs b/test/browser/global-setup.js
similarity index 76%
rename from test/browser/global-setup.mjs
rename to test/browser/global-setup.js
index 5a7fa22b..1c87cfae 100644
--- a/test/browser/global-setup.mjs
+++ b/test/browser/global-setup.js
@@ -1,5 +1,5 @@
-// Playwright global setup step that bundles test/browser-specific/setup.js for the browser.
-// The interface specs ("bdd" / "tdd" / "qunit") and ESM specs are loaded directly in the page, but setup.js relies on CommonJS "require" to build the global expect, so it has to be bundled first.
+// Playwright global setup step that bundles test/browser-specific/setup.cjs for the browser.
+// The interface specs ("bdd" / "tdd" / "qunit") and ESM specs are loaded directly in the page, but setup.cjs relies on CommonJS "require" to build the global expect, so it has to be bundled first.
// We reuse the same Rollup plugin pipeline as the Mocha browser build so the "global" and "process" shims behave consistently across both environments.
import path from "node:path";
@@ -11,18 +11,18 @@ import nodeResolve from "@rollup/plugin-node-resolve";
import { rollup } from "rollup";
import nodePolyfills from "rollup-plugin-polyfill-node";
-import { SETUP_BUNDLE_PATH } from "./config.mjs";
+import { SETUP_BUNDLE_PATH } from "./config.js";
const root = path.resolve(fileURLToPath(import.meta.url), "../../..");
/**
- * Bundles setup.js into a single browser-ready IIFE (Immediately Invoked Function Expression).
+ * Bundles setup.cjs into a single browser-ready IIFE (Immediately Invoked Function Expression).
*
* @returns {Promise<void>}
*/
export default async function buildSetupBundle() {
const bundle = await rollup({
- input: path.join(root, "test/browser-specific/setup.js"),
+ input: path.join(root, "test/browser-specific/setup.cjs"),
plugins: [
json(),
commonjs(),
diff --git a/test/browser/run.spec.mjs b/test/browser/run.spec.js
similarity index 94%
rename from test/browser/run.spec.mjs
rename to test/browser/run.spec.js
index af7d8725..d71f85ef 100644
--- a/test/browser/run.spec.mjs
+++ b/test/browser/run.spec.js
@@ -1,6 +1,6 @@
import { expect, test } from "@playwright/test";
-import { suites } from "./config.mjs";
+import { suites } from "./config.js";
for (const suite of suites) {
test(`browser suite: ${suite.name}`, async ({ page }) => {
diff --git a/test/browser/server.mjs b/test/browser/server.js
similarity index 97%
rename from test/browser/server.mjs
rename to test/browser/server.js
index 57e0b287..d194e076 100644
--- a/test/browser/server.mjs
+++ b/test/browser/server.js
@@ -3,7 +3,7 @@ import http from "node:http";
import path from "node:path";
import { fileURLToPath } from "node:url";
-import { baseURL, PORT, SETUP_BUNDLE_PATH, suites } from "./config.mjs";
+import { baseURL, PORT, SETUP_BUNDLE_PATH, suites } from "./config.js";
const root = path.resolve(fileURLToPath(import.meta.url), "../../..");
@@ -19,7 +19,7 @@ const MIME_TYPES = {
/**
* Builds the HTML runner page for a single suite.
*
- * @param {import("./config.mjs").BrowserSuite} suite
+ * @param {import("./config.js").BrowserSuite} suite
* @returns {string}
*/
const renderRunner = (suite) => {
diff --git a/test/compiler-fixtures/esm-loader.fixture.mjs b/test/compiler-fixtures/esm-loader.fixture.js
similarity index 100%
rename from test/compiler-fixtures/esm-loader.fixture.mjs
rename to test/compiler-fixtures/esm-loader.fixture.js
diff --git a/test/compiler-fixtures/esm-only-loader/esm-loader.fixture.mjs b/test/compiler-fixtures/esm-only-loader/esm-loader.fixture.js
similarity index 100%
rename from test/compiler-fixtures/esm-only-loader/esm-loader.fixture.mjs
rename to test/compiler-fixtures/esm-only-loader/esm-loader.fixture.js
diff --git a/test/compiler-fixtures/esm-only-loader/esm.fixture.js b/test/compiler-fixtures/esm-only-loader/esm.fixture.js
index 1b34d1ac..bb7db633 100644
--- a/test/compiler-fixtures/esm-only-loader/esm.fixture.js
+++ b/test/compiler-fixtures/esm-only-loader/esm.fixture.js
@@ -1,3 +1,3 @@
import Module from "node:module";
-Module.register(new URL("./esm-loader.fixture.mjs", import.meta.url));
+Module.register(new URL("./esm-loader.fixture.js", import.meta.url));
diff --git a/test/compiler-fixtures/esm.fixture.js b/test/compiler-fixtures/esm.fixture.cjs
similarity index 67%
rename from test/compiler-fixtures/esm.fixture.js
rename to test/compiler-fixtures/esm.fixture.cjs
index 1d2ad081..f1b0de9e 100644
--- a/test/compiler-fixtures/esm.fixture.js
+++ b/test/compiler-fixtures/esm.fixture.cjs
@@ -3,5 +3,5 @@ const { pathToFileURL } = require("node:url");
const path = require("node:path");
Module.register(
- pathToFileURL(path.resolve(__dirname, "esm-loader.fixture.mjs")),
+ pathToFileURL(path.resolve(__dirname, "esm-loader.fixture.js")),
);
diff --git a/test/compiler-fixtures/foo.fixture.js b/test/compiler-fixtures/foo.fixture.cjs
similarity index 100%
rename from test/compiler-fixtures/foo.fixture.js
rename to test/compiler-fixtures/foo.fixture.cjs
diff --git a/test/compiler-fixtures/js.fixture.js b/test/compiler-fixtures/js.fixture.cjs
similarity index 100%
rename from test/compiler-fixtures/js.fixture.js
rename to test/compiler-fixtures/js.fixture.cjs
diff --git a/test/compiler-fixtures/ts.fixture.js b/test/compiler-fixtures/ts.fixture.cjs
similarity index 100%
rename from test/compiler-fixtures/ts.fixture.js
rename to test/compiler-fixtures/ts.fixture.cjs
diff --git a/test/integration/color.spec.js b/test/integration/color.spec.cjs
similarity index 100%
rename from test/integration/color.spec.js
rename to test/integration/color.spec.cjs
diff --git a/test/integration/common-js-require.spec.js b/test/integration/common-js-require.spec.cjs
similarity index 92%
rename from test/integration/common-js-require.spec.js
rename to test/integration/common-js-require.spec.cjs
index f006f42d..90f66474 100644
--- a/test/integration/common-js-require.spec.js
+++ b/test/integration/common-js-require.spec.cjs
@@ -1,10 +1,10 @@
"use strict";
-const { runMochaAsync } = require("./helpers");
+const { runMochaAsync } = require("./helpers.cjs");
describe("common js require", () => {
it("should be able to run a test where all mocha exports are used", async () => {
- const result = await runMochaAsync("common-js-require.fixture.js", [
+ const result = await runMochaAsync("common-js-require.fixture.cjs", [
"--delay",
"--no-forbid-only",
]);
diff --git a/test/integration/compiler-cjs.spec.js b/test/integration/compiler-cjs.spec.cjs
similarity index 90%
rename from test/integration/compiler-cjs.spec.js
rename to test/integration/compiler-cjs.spec.cjs
index ab574779..63077b34 100644
--- a/test/integration/compiler-cjs.spec.js
+++ b/test/integration/compiler-cjs.spec.cjs
@@ -10,7 +10,7 @@ describe("support CJS require.extension compilers with esm syntax", function ()
process.execPath +
'" "' +
path.join("bin", "mocha") +
- '" -R json --require test/compiler-fixtures/js.fixture "test/compiler-cjs/*.js"',
+ '" -R json --require test/compiler-fixtures/js.fixture.cjs "test/compiler-cjs/*.js"',
{ cwd: path.join(__dirname, "..", "..") },
function (error, stdout) {
if (error && !stdout) {
@@ -38,7 +38,7 @@ describe("support CJS require.extension compilers with esm syntax", function ()
process.execPath +
'" "' +
path.join("bin", "mocha") +
- '" -R json --require test/compiler-fixtures/ts.fixture "test/compiler-cjs/*.ts"',
+ '" -R json --require test/compiler-fixtures/ts.fixture.cjs "test/compiler-cjs/*.ts"',
{ cwd: path.join(__dirname, "..", "..") },
function (error, stdout) {
if (error && !stdout) {
diff --git a/test/integration/compiler-esm-only-loader.spec.js b/test/integration/compiler-esm-only-loader.spec.cjs
similarity index 100%
rename from test/integration/compiler-esm-only-loader.spec.js
rename to test/integration/compiler-esm-only-loader.spec.cjs
diff --git a/test/integration/compiler-esm.spec.js b/test/integration/compiler-esm.spec.cjs
similarity index 95%
rename from test/integration/compiler-esm.spec.js
rename to test/integration/compiler-esm.spec.cjs
index 3d6d6a1f..692ed11b 100644
--- a/test/integration/compiler-esm.spec.js
+++ b/test/integration/compiler-esm.spec.cjs
@@ -15,7 +15,7 @@ describe("support ESM module loader compilers", function () {
process.execPath +
'" "' +
path.join("bin", "mocha") +
- `" -R json --require test/compiler-fixtures/esm.fixture "${filename}"`,
+ `" -R json --require test/compiler-fixtures/esm.fixture.cjs "${filename}"`,
{ cwd: path.join(__dirname, "..", "..") },
function (error, stdout) {
if (error && !stdout) {
diff --git a/test/integration/compiler-globbing.spec.js b/test/integration/compiler-globbing.spec.cjs
similarity index 93%
rename from test/integration/compiler-globbing.spec.js
rename to test/integration/compiler-globbing.spec.cjs
index 28d4a3c5..e6693d79 100644
--- a/test/integration/compiler-globbing.spec.js
+++ b/test/integration/compiler-globbing.spec.cjs
@@ -10,7 +10,7 @@ describe("globbing like --compilers", function () {
process.execPath +
'" "' +
path.join("bin", "mocha") +
- '" -R json --require coffeescript/register --require test/compiler-fixtures/foo.fixture "test/compiler/*.@(coffee|foo)"',
+ '" -R json --require coffeescript/register --require test/compiler-fixtures/foo.fixture.cjs "test/compiler/*.@(coffee|foo)"',
{ cwd: path.join(__dirname, "..", "..") },
function (error, stdout) {
if (error && !stdout) {
diff --git a/test/integration/config.spec.js b/test/integration/config.spec.cjs
similarity index 93%
rename from test/integration/config.spec.js
rename to test/integration/config.spec.cjs
index a5d82094..a391278e 100644
--- a/test/integration/config.spec.js
+++ b/test/integration/config.spec.cjs
@@ -5,19 +5,17 @@
var fs = require("node:fs");
var path = require("node:path");
-var loadConfig = require("../../lib/cli/config").loadConfig;
+var loadConfig = require("../../lib/cli/config.cjs").loadConfig;
describe("config", function () {
it("should return the same values for all supported config types", function () {
var configDir = path.join(__dirname, "fixtures", "config");
- var js = loadConfig(path.join(configDir, "mocharc.js")); // canonical form
+ var js = loadConfig(path.join(configDir, "mocharc.js")); // canonical form, ESM
var cjs = loadConfig(path.join(configDir, "mocharc.cjs"));
var json = loadConfig(path.join(configDir, "mocharc.json"));
- var mjs = loadConfig(path.join(configDir, "mocharc.mjs"));
var yaml = loadConfig(path.join(configDir, "mocharc.yaml"));
expect(cjs, "to equal", js);
expect(json, "to equal", js);
- expect(mjs, "to equal", js);
expect(yaml, "to equal", js);
});
@@ -51,7 +49,7 @@ describe("config", function () {
it("should rethrow error from absolute path configuration", function () {
function _loadConfig() {
- loadConfig(path.join(configDir, "mocharcWithThrowError.js"));
+ loadConfig(path.join(configDir, "mocharcWithThrowError.cjs"));
}
expect(_loadConfig, "to throw", {
@@ -63,7 +61,7 @@ describe("config", function () {
var relConfigDir = configDir.substring(projRootDir.length + 1);
function _loadConfig() {
- loadConfig(path.join(".", relConfigDir, "mocharcWithThrowError.js"));
+ loadConfig(path.join(".", relConfigDir, "mocharcWithThrowError.cjs"));
}
expect(_loadConfig, "to throw", {
diff --git a/test/integration/constants.mjs b/test/integration/constants.js
similarity index 100%
rename from test/integration/constants.mjs
rename to test/integration/constants.js
diff --git a/test/integration/diffs.spec.js b/test/integration/diffs.spec.cjs
similarity index 96%
rename from test/integration/diffs.spec.js
rename to test/integration/diffs.spec.cjs
index 2b4b70a0..e7b0f4ab 100644
--- a/test/integration/diffs.spec.js
+++ b/test/integration/diffs.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var run = helpers.runMocha;
var fs = require("node:fs");
var path = require("node:path");
@@ -69,7 +69,7 @@ describe("diffs", function () {
var diffs, expected;
before(function (done) {
- run("diffs/diffs.fixture.js", [], function (err, res) {
+ run("diffs/diffs.fixture.cjs", [], function (err, res) {
if (err) {
done(err);
return;
diff --git a/test/integration/duplicate-arguments.spec.js b/test/integration/duplicate-arguments.spec.cjs
similarity index 94%
rename from test/integration/duplicate-arguments.spec.js
rename to test/integration/duplicate-arguments.spec.cjs
index 2107533f..fbc69c53 100644
--- a/test/integration/duplicate-arguments.spec.js
+++ b/test/integration/duplicate-arguments.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var runMochaJSON = require("./helpers").runMochaJSON;
+var runMochaJSON = require("./helpers.cjs").runMochaJSON;
describe("when non-array argument is provided multiple times", function () {
describe("when the same argument name is used", function () {
diff --git a/test/integration/esm.spec.js b/test/integration/esm.spec.cjs
similarity index 90%
rename from test/integration/esm.spec.js
rename to test/integration/esm.spec.cjs
index 3d8b143e..bffe90cb 100644
--- a/test/integration/esm.spec.js
+++ b/test/integration/esm.spec.cjs
@@ -1,11 +1,11 @@
"use strict";
var path = require("node:path");
-const { runMochaJSON: run, runMochaAsync } = require("./helpers");
+const { runMochaJSON: run, runMochaAsync } = require("./helpers.cjs");
var args = [];
describe("esm", function () {
it("should pass a passing esm test that uses esm", function (done) {
- var fixture = "esm/esm-success.fixture.mjs";
+ var fixture = "esm/esm-success.fixture.js";
run(fixture, args, function (err, result) {
if (err) {
done(err);
@@ -18,7 +18,7 @@ describe("esm", function () {
});
it("should fail a failing esm test that uses esm", function (done) {
- var fixture = "esm/esm-failure.fixture.mjs";
+ var fixture = "esm/esm-failure.fixture.js";
run(fixture, args, function (err, result) {
if (err) {
done(err);
@@ -34,13 +34,13 @@ describe("esm", function () {
});
it("should show file location when there is a syntax error in the test", async function () {
- var fixture = "esm/syntax-error/esm-syntax-error.fixture.mjs";
+ var fixture = "esm/syntax-error/esm-syntax-error.fixture.js";
const err = await runMochaAsync(fixture, args, { stdio: "pipe" }).catch(
(err) => err,
);
expect(err.output, "to contain", "SyntaxError").and(
"to contain",
- "esm-syntax-error.fixture.mjs",
+ "esm-syntax-error.fixture.js",
);
});
@@ -90,7 +90,7 @@ describe("esm", function () {
fixture,
[
"--unhandled-rejections=warn",
- "--loader=./test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.mjs",
+ "--loader=./test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.js",
],
{
stdio: "pipe",
diff --git a/test/integration/events.spec.js b/test/integration/events.spec.cjs
similarity index 89%
rename from test/integration/events.spec.js
rename to test/integration/events.spec.cjs
index 57264e36..db1fcbbf 100644
--- a/test/integration/events.spec.js
+++ b/test/integration/events.spec.cjs
@@ -1,12 +1,12 @@
"use strict";
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("event order", function () {
describe("trivial test case", function () {
it("should assert trivial event order", function (done) {
- runMochaJSON("runner/events-basic.fixture.js", [], function (err, res) {
+ runMochaJSON("runner/events-basic.fixture.cjs", [], function (err, res) {
if (err) {
done(err);
return;
@@ -23,7 +23,7 @@ describe("event order", function () {
describe("--bail test case", function () {
it("should assert --bail event order", function (done) {
runMochaJSON(
- "runner/events-bail.fixture.js",
+ "runner/events-bail.fixture.cjs",
["--bail"],
function (err, res) {
if (err) {
@@ -42,7 +42,7 @@ describe("event order", function () {
describe("--retries test case", function () {
it("should assert --retries event order", function (done) {
runMochaJSON(
- "runner/events-retries.fixture.js",
+ "runner/events-retries.fixture.cjs",
["--retries", "1"],
function (err, res) {
if (err) {
@@ -61,7 +61,7 @@ describe("event order", function () {
describe("--delay test case", function () {
it("should assert --delay event order", function (done) {
runMochaJSON(
- "runner/events-delay.fixture.js",
+ "runner/events-delay.fixture.cjs",
["--delay"],
function (err, res) {
if (err) {
@@ -81,7 +81,7 @@ describe("event order", function () {
describe("--retries and --bail test case", function () {
it("should assert --retries event order", function (done) {
runMochaJSON(
- "runner/events-bail-retries.fixture.js",
+ "runner/events-bail-retries.fixture.cjs",
["--retries", "1", "--bail"],
function (err, res) {
if (err) {
diff --git a/test/integration/fifo.spec.js b/test/integration/fifo.spec.cjs
similarity index 96%
rename from test/integration/fifo.spec.js
rename to test/integration/fifo.spec.cjs
index f2f7e863..9bd93062 100644
--- a/test/integration/fifo.spec.js
+++ b/test/integration/fifo.spec.cjs
@@ -11,7 +11,7 @@ const {
const { join } = require("node:path");
const { tmpdir } = require("node:os");
-const { invokeMocha, toJSONResult } = require("./helpers");
+const { invokeMocha, toJSONResult } = require("./helpers.cjs");
describe("FIFO support", function () {
it("should accept a test passed as a FIFO", function (done) {
diff --git a/test/integration/file-utils.spec.js b/test/integration/file-utils.spec.cjs
similarity index 98%
rename from test/integration/file-utils.spec.js
rename to test/integration/file-utils.spec.cjs
index 496c504e..bb8bae5f 100644
--- a/test/integration/file-utils.spec.js
+++ b/test/integration/file-utils.spec.cjs
@@ -1,9 +1,9 @@
"use strict";
-const { lookupFiles } = require("../../lib/cli/lookup-files.mjs");
+const { lookupFiles } = require("../../lib/cli/lookup-files.js");
const { existsSync, symlinkSync, renameSync } = require("node:fs");
const path = require("node:path");
-const { touchFile, createTempDir } = require("./helpers");
+const { touchFile, createTempDir } = require("./helpers.cjs");
const SYMLINK_SUPPORT = process.platform !== "win32";
diff --git a/test/integration/fixtures/collect-files.fixture.mjs b/test/integration/fixtures/collect-files.fixture.js
similarity index 100%
rename from test/integration/fixtures/collect-files.fixture.mjs
rename to test/integration/fixtures/collect-files.fixture.js
diff --git a/test/integration/fixtures/common-js-require.fixture.js b/test/integration/fixtures/common-js-require.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/common-js-require.fixture.js
rename to test/integration/fixtures/common-js-require.fixture.cjs
diff --git a/test/integration/fixtures/config/mocha-config/package.json b/test/integration/fixtures/config/mocha-config/package.json
index c6fe4df0..811367f5 100644
--- a/test/integration/fixtures/config/mocha-config/package.json
+++ b/test/integration/fixtures/config/mocha-config/package.json
@@ -1,6 +1,7 @@
{
"name": "mocha-config",
"version": "1.0.0",
+ "type": "commonjs",
"description": "Configure Mocha via package",
"main": "index.js",
"peerDependencies": {
diff --git a/test/integration/fixtures/config/mocharc.js b/test/integration/fixtures/config/mocharc.js
index adec9d68..7cbe079d 100644
--- a/test/integration/fixtures/config/mocharc.js
+++ b/test/integration/fixtures/config/mocharc.js
@@ -1,7 +1,5 @@
-'use strict';
-
// a comment
-module.exports = {
+export default {
require: ['foo', 'bar'],
bail: true,
reporter: 'dot',
diff --git a/test/integration/fixtures/config/mocharc.mjs b/test/integration/fixtures/config/mocharc.mjs
deleted file mode 100644
index 7cbe079d..00000000
--- a/test/integration/fixtures/config/mocharc.mjs
+++ /dev/null
@@ -1,7 +0,0 @@
-// a comment
-export default {
- require: ['foo', 'bar'],
- bail: true,
- reporter: 'dot',
- slow: 60
-};
diff --git a/test/integration/fixtures/config/mocharcWithThrowError.js b/test/integration/fixtures/config/mocharcWithThrowError.cjs
similarity index 100%
rename from test/integration/fixtures/config/mocharcWithThrowError.js
rename to test/integration/fixtures/config/mocharcWithThrowError.cjs
diff --git a/test/integration/fixtures/current-test-title.fixture.js b/test/integration/fixtures/current-test-title.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/current-test-title.fixture.js
rename to test/integration/fixtures/current-test-title.fixture.cjs
diff --git a/test/integration/fixtures/diff-hang-protection.fixture.js b/test/integration/fixtures/diff-hang-protection.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/diff-hang-protection.fixture.js
rename to test/integration/fixtures/diff-hang-protection.fixture.cjs
diff --git a/test/integration/fixtures/diffs/diffs.fixture.js b/test/integration/fixtures/diffs/diffs.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/diffs/diffs.fixture.js
rename to test/integration/fixtures/diffs/diffs.fixture.cjs
diff --git a/test/integration/fixtures/esm/add.mjs b/test/integration/fixtures/esm/add.js
similarity index 100%
rename from test/integration/fixtures/esm/add.mjs
rename to test/integration/fixtures/esm/add.js
diff --git a/test/integration/fixtures/esm/esm-failure.fixture.mjs b/test/integration/fixtures/esm/esm-failure.fixture.js
similarity index 75%
rename from test/integration/fixtures/esm/esm-failure.fixture.mjs
rename to test/integration/fixtures/esm/esm-failure.fixture.js
index 588d8fce..d7c233d3 100644
--- a/test/integration/fixtures/esm/esm-failure.fixture.mjs
+++ b/test/integration/fixtures/esm/esm-failure.fixture.js
@@ -1,4 +1,4 @@
-import {add} from './add.mjs';
+import {add} from './add.js';
it('should use a function from an esm, and fail', () => {
expect(add(3, 5), 'to be', 9);
diff --git a/test/integration/fixtures/esm/esm-success.fixture.mjs b/test/integration/fixtures/esm/esm-success.fixture.js
similarity index 73%
rename from test/integration/fixtures/esm/esm-success.fixture.mjs
rename to test/integration/fixtures/esm/esm-success.fixture.js
index 0df926ca..bf36b788 100644
--- a/test/integration/fixtures/esm/esm-success.fixture.mjs
+++ b/test/integration/fixtures/esm/esm-success.fixture.js
@@ -1,4 +1,4 @@
-import {add} from './add.mjs';
+import {add} from './add.js';
it('should use a function from an esm', () => {
expect(add(3, 5), 'to be', 8);
diff --git a/test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.mjs b/test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.js
similarity index 100%
rename from test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.mjs
rename to test/integration/fixtures/esm/loader-with-module-not-found/loader-that-recognizes-ts.js
diff --git a/test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.mjs b/test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.js
similarity index 100%
rename from test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.mjs
rename to test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.js
diff --git a/test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.ts b/test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.ts
index 22db1d5e..5f376757 100644
--- a/test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.ts
+++ b/test/integration/fixtures/esm/loader-with-module-not-found/test-that-imports-non-existing-module.fixture.ts
@@ -1,2 +1,2 @@
-// This file will be resolved to `test-that-imports-non-existing-module.fixture.mjs` by the loader
+// This file will be resolved to `test-that-imports-non-existing-module.fixture.js` by the loader
import 'non-existent-package';
diff --git a/test/integration/fixtures/esm/syntax-error/esm-syntax-error.fixture.mjs b/test/integration/fixtures/esm/syntax-error/esm-syntax-error.fixture.js
similarity index 100%
rename from test/integration/fixtures/esm/syntax-error/esm-syntax-error.fixture.mjs
rename to test/integration/fixtures/esm/syntax-error/esm-syntax-error.fixture.js
diff --git a/test/integration/fixtures/exit.fixture.js b/test/integration/fixtures/exit.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/exit.fixture.js
rename to test/integration/fixtures/exit.fixture.cjs
diff --git a/test/integration/fixtures/failing-sync.fixture.js b/test/integration/fixtures/failing-sync.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/failing-sync.fixture.js
rename to test/integration/fixtures/failing-sync.fixture.cjs
diff --git a/test/integration/fixtures/failing.fixture.js b/test/integration/fixtures/failing.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/failing.fixture.js
rename to test/integration/fixtures/failing.fixture.cjs
diff --git a/test/integration/fixtures/glob/glob.spec.js b/test/integration/fixtures/glob/glob.spec.js
index c6c3d26a..e4fe9e32 100644
--- a/test/integration/fixtures/glob/glob.spec.js
+++ b/test/integration/fixtures/glob/glob.spec.js
@@ -2,6 +2,6 @@
describe('globbing test', function() {
it('should find this test', function() {
- // see test/integration/glob.spec.js for details
+ // see test/integration/glob.spec.cjs for details
});
});
diff --git a/test/integration/fixtures/glob/nested/glob.spec.js b/test/integration/fixtures/glob/nested/glob.spec.js
index c6c3d26a..e4fe9e32 100644
--- a/test/integration/fixtures/glob/nested/glob.spec.js
+++ b/test/integration/fixtures/glob/nested/glob.spec.js
@@ -2,6 +2,6 @@
describe('globbing test', function() {
it('should find this test', function() {
- // see test/integration/glob.spec.js for details
+ // see test/integration/glob.spec.cjs for details
});
});
diff --git a/test/integration/fixtures/multiple-runs/clean-references.fixture.js b/test/integration/fixtures/multiple-runs/clean-references.fixture.cjs
similarity index 51%
rename from test/integration/fixtures/multiple-runs/clean-references.fixture.js
rename to test/integration/fixtures/multiple-runs/clean-references.fixture.cjs
index 2f204a0b..48c510b1 100644
--- a/test/integration/fixtures/multiple-runs/clean-references.fixture.js
+++ b/test/integration/fixtures/multiple-runs/clean-references.fixture.cjs
@@ -1,6 +1,6 @@
'use strict';
-const Mocha = require('../../../../lib/mocha');
+const Mocha = require('../../../../lib/mocha.cjs');
const mocha = new Mocha({ reporter: 'json' });
mocha.cleanReferencesAfterRun(true);
-require('./run-thrice-helper')(mocha);
+require('./run-thrice-helper.cjs')(mocha);
diff --git a/test/integration/fixtures/multiple-runs/dispose.fixture.cjs b/test/integration/fixtures/multiple-runs/dispose.fixture.cjs
new file mode 100644
index 00000000..cee929af
--- /dev/null
+++ b/test/integration/fixtures/multiple-runs/dispose.fixture.cjs
@@ -0,0 +1,6 @@
+'use strict';
+const Mocha = require('../../../../lib/mocha.cjs');
+
+const mocha = new Mocha({ reporter: 'json' });
+mocha.dispose();
+require('./run-thrice-helper.cjs')(mocha);
diff --git a/test/integration/fixtures/multiple-runs/dispose.fixture.js b/test/integration/fixtures/multiple-runs/dispose.fixture.js
deleted file mode 100644
index c0d3c4d7..00000000
--- a/test/integration/fixtures/multiple-runs/dispose.fixture.js
+++ /dev/null
@@ -1,6 +0,0 @@
-'use strict';
-const Mocha = require('../../../../lib/mocha');
-
-const mocha = new Mocha({ reporter: 'json' });
-mocha.dispose();
-require('./run-thrice-helper')(mocha);
diff --git a/test/integration/fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.js b/test/integration/fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.cjs
similarity index 85%
rename from test/integration/fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.js
rename to test/integration/fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.cjs
index 1a470770..e8a89cdd 100644
--- a/test/integration/fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.js
+++ b/test/integration/fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-const Mocha = require('../../../../lib/mocha');
+const Mocha = require('../../../../lib/mocha.cjs');
const mocha = new Mocha({ reporter: 'json' });
mocha.cleanReferencesAfterRun(false);
diff --git a/test/integration/fixtures/multiple-runs/run-thrice-helper.js b/test/integration/fixtures/multiple-runs/run-thrice-helper.cjs
similarity index 100%
rename from test/integration/fixtures/multiple-runs/run-thrice-helper.js
rename to test/integration/fixtures/multiple-runs/run-thrice-helper.cjs
diff --git a/test/integration/fixtures/multiple-runs/run-thrice.fixture.js b/test/integration/fixtures/multiple-runs/run-thrice.fixture.cjs
similarity index 51%
rename from test/integration/fixtures/multiple-runs/run-thrice.fixture.js
rename to test/integration/fixtures/multiple-runs/run-thrice.fixture.cjs
index 3c63ec37..ed7348a2 100644
--- a/test/integration/fixtures/multiple-runs/run-thrice.fixture.js
+++ b/test/integration/fixtures/multiple-runs/run-thrice.fixture.cjs
@@ -1,6 +1,6 @@
'use strict';
-const Mocha = require('../../../../lib/mocha');
+const Mocha = require('../../../../lib/mocha.cjs');
const mocha = new Mocha({ reporter: 'json' });
mocha.cleanReferencesAfterRun(false);
-require('./run-thrice-helper')(mocha);
+require('./run-thrice-helper.cjs')(mocha);
diff --git a/test/integration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.js b/test/integration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.cjs
similarity index 82%
rename from test/integration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.js
rename to test/integration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.cjs
index 1b031334..06220520 100644
--- a/test/integration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.js
+++ b/test/integration/fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-const Mocha = require('../../../../lib/mocha');
+const Mocha = require('../../../../lib/mocha.cjs');
const mocha = new Mocha({ reporter: 'json' });
mocha.addFile(require.resolve('./start-second-run-if-previous-is-still-running-suite.fixture.js'));
diff --git a/test/integration/fixtures/no-diff.fixture.js b/test/integration/fixtures/no-diff.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/no-diff.fixture.js
rename to test/integration/fixtures/no-diff.fixture.cjs
diff --git a/test/integration/fixtures/options/allow-uncaught/propagate.fixture.js b/test/integration/fixtures/options/allow-uncaught/propagate.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/allow-uncaught/propagate.fixture.js
rename to test/integration/fixtures/options/allow-uncaught/propagate.fixture.cjs
diff --git a/test/integration/fixtures/options/bail-with-after.fixture.js b/test/integration/fixtures/options/bail-with-after.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/bail-with-after.fixture.js
rename to test/integration/fixtures/options/bail-with-after.fixture.cjs
diff --git a/test/integration/fixtures/options/bail-with-afterEach.fixture.js b/test/integration/fixtures/options/bail-with-afterEach.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/bail-with-afterEach.fixture.js
rename to test/integration/fixtures/options/bail-with-afterEach.fixture.cjs
diff --git a/test/integration/fixtures/options/bail-with-before.fixture.js b/test/integration/fixtures/options/bail-with-before.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/bail-with-before.fixture.js
rename to test/integration/fixtures/options/bail-with-before.fixture.cjs
diff --git a/test/integration/fixtures/options/bail-with-beforeEach.fixture.js b/test/integration/fixtures/options/bail-with-beforeEach.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/bail-with-beforeEach.fixture.js
rename to test/integration/fixtures/options/bail-with-beforeEach.fixture.cjs
diff --git a/test/integration/fixtures/options/bail-with-test.fixture.js b/test/integration/fixtures/options/bail-with-test.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/bail-with-test.fixture.js
rename to test/integration/fixtures/options/bail-with-test.fixture.cjs
diff --git a/test/integration/fixtures/options/delay-only.fixture.js b/test/integration/fixtures/options/delay-only.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/delay-only.fixture.js
rename to test/integration/fixtures/options/delay-only.fixture.cjs
diff --git a/test/integration/fixtures/options/delay.fixture.js b/test/integration/fixtures/options/delay.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/delay.fixture.js
rename to test/integration/fixtures/options/delay.fixture.cjs
diff --git a/test/integration/fixtures/options/dry-run/stack-size.fixture.js b/test/integration/fixtures/options/dry-run/stack-size.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/dry-run/stack-size.fixture.js
rename to test/integration/fixtures/options/dry-run/stack-size.fixture.cjs
diff --git a/test/integration/fixtures/options/jobs/fail-in-parallel.fixture.js b/test/integration/fixtures/options/jobs/fail-in-parallel.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/jobs/fail-in-parallel.fixture.js
rename to test/integration/fixtures/options/jobs/fail-in-parallel.fixture.cjs
diff --git a/test/integration/fixtures/options/reporter-esm.fixture.mjs b/test/integration/fixtures/options/reporter-esm.fixture.js
similarity index 100%
rename from test/integration/fixtures/options/reporter-esm.fixture.mjs
rename to test/integration/fixtures/options/reporter-esm.fixture.js
diff --git a/test/integration/fixtures/options/reporter-with-options.fixture.js b/test/integration/fixtures/options/reporter-with-options.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/reporter-with-options.fixture.js
rename to test/integration/fixtures/options/reporter-with-options.fixture.cjs
diff --git a/test/integration/fixtures/options/watch/dependency.fixture.js b/test/integration/fixtures/options/watch/dependency.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/watch/dependency.fixture.js
rename to test/integration/fixtures/options/watch/dependency.fixture.cjs
diff --git a/test/integration/fixtures/options/watch/hook.fixture.js b/test/integration/fixtures/options/watch/hook.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/watch/hook.fixture.js
rename to test/integration/fixtures/options/watch/hook.fixture.cjs
diff --git a/test/integration/fixtures/options/watch/test-with-dependency.fixture.js b/test/integration/fixtures/options/watch/test-with-dependency.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/options/watch/test-with-dependency.fixture.js
rename to test/integration/fixtures/options/watch/test-with-dependency.fixture.cjs
diff --git a/test/integration/fixtures/parallel/circular-error-array.mjs b/test/integration/fixtures/parallel/circular-error-array.js
similarity index 77%
rename from test/integration/fixtures/parallel/circular-error-array.mjs
rename to test/integration/fixtures/parallel/circular-error-array.js
index 1695c7ff..5e3787b8 100644
--- a/test/integration/fixtures/parallel/circular-error-array.mjs
+++ b/test/integration/fixtures/parallel/circular-error-array.js
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.mjs";
+import {describe,it} from "../../../../index.js";
describe('test1', () => {
it('test', () => {
diff --git a/test/integration/fixtures/parallel/circular-error-object.mjs b/test/integration/fixtures/parallel/circular-error-object.js
similarity index 83%
rename from test/integration/fixtures/parallel/circular-error-object.mjs
rename to test/integration/fixtures/parallel/circular-error-object.js
index 34c5d1c3..45ba68a2 100644
--- a/test/integration/fixtures/parallel/circular-error-object.mjs
+++ b/test/integration/fixtures/parallel/circular-error-object.js
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.mjs";
+import {describe,it} from "../../../../index.js";
describe('test1', () => {
it('test', () => {
diff --git a/test/integration/fixtures/parallel/getter-error-object.mjs b/test/integration/fixtures/parallel/getter-error-object.js
similarity index 79%
rename from test/integration/fixtures/parallel/getter-error-object.mjs
rename to test/integration/fixtures/parallel/getter-error-object.js
index 086d469d..477427e6 100644
--- a/test/integration/fixtures/parallel/getter-error-object.mjs
+++ b/test/integration/fixtures/parallel/getter-error-object.js
@@ -1,4 +1,4 @@
-import {describe, it} from '../../../../index.mjs';
+import {describe, it} from '../../../../index.js';
describe('test1', () => {
it('test', async () => {
diff --git a/test/integration/fixtures/parallel/non-circular-error.mjs b/test/integration/fixtures/parallel/non-circular-error.js
similarity index 54%
rename from test/integration/fixtures/parallel/non-circular-error.mjs
rename to test/integration/fixtures/parallel/non-circular-error.js
index f76d51e2..251a58b0 100644
--- a/test/integration/fixtures/parallel/non-circular-error.mjs
+++ b/test/integration/fixtures/parallel/non-circular-error.js
@@ -1,4 +1,4 @@
-import {it} from '../../../../index.mjs';
+import {it} from '../../../../index.js';
it('test', () => {
throw new Error('Foo');
diff --git a/test/integration/fixtures/parallel/test1.mjs b/test/integration/fixtures/parallel/test1.js
similarity index 54%
rename from test/integration/fixtures/parallel/test1.mjs
rename to test/integration/fixtures/parallel/test1.js
index c153f097..5be1220a 100644
--- a/test/integration/fixtures/parallel/test1.mjs
+++ b/test/integration/fixtures/parallel/test1.js
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.mjs";
+import {describe,it} from "../../../../index.js";
describe('test1', () => {
it('should pass', () => {});
diff --git a/test/integration/fixtures/parallel/test2.mjs b/test/integration/fixtures/parallel/test2.js
similarity index 54%
rename from test/integration/fixtures/parallel/test2.mjs
rename to test/integration/fixtures/parallel/test2.js
index 5d566d3a..abd1f97a 100644
--- a/test/integration/fixtures/parallel/test2.mjs
+++ b/test/integration/fixtures/parallel/test2.js
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.mjs";
+import {describe,it} from "../../../../index.js";
describe('test2', () => {
it('should pass', () => {});
diff --git a/test/integration/fixtures/parallel/test3.mjs b/test/integration/fixtures/parallel/test3.js
similarity index 69%
rename from test/integration/fixtures/parallel/test3.mjs
rename to test/integration/fixtures/parallel/test3.js
index a290cfce..5210bd9b 100644
--- a/test/integration/fixtures/parallel/test3.mjs
+++ b/test/integration/fixtures/parallel/test3.js
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.mjs";
+import {describe,it} from "../../../../index.js";
describe('test3', () => {
it('should fail', () => {
diff --git a/test/integration/fixtures/parallel/testworkerid1.mjs b/test/integration/fixtures/parallel/testworkerid1.js
similarity index 100%
rename from test/integration/fixtures/parallel/testworkerid1.mjs
rename to test/integration/fixtures/parallel/testworkerid1.js
diff --git a/test/integration/fixtures/parallel/testworkerid2.mjs b/test/integration/fixtures/parallel/testworkerid2.js
similarity index 100%
rename from test/integration/fixtures/parallel/testworkerid2.mjs
rename to test/integration/fixtures/parallel/testworkerid2.js
diff --git a/test/integration/fixtures/parallel/testworkerid3.mjs b/test/integration/fixtures/parallel/testworkerid3.js
similarity index 100%
rename from test/integration/fixtures/parallel/testworkerid3.mjs
rename to test/integration/fixtures/parallel/testworkerid3.js
diff --git a/test/integration/fixtures/passing.fixture.js b/test/integration/fixtures/passing.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/passing.fixture.js
rename to test/integration/fixtures/passing.fixture.cjs
diff --git a/test/integration/fixtures/pending/programmatic.fixture.js b/test/integration/fixtures/pending/programmatic.fixture.cjs
similarity index 80%
rename from test/integration/fixtures/pending/programmatic.fixture.js
rename to test/integration/fixtures/pending/programmatic.fixture.cjs
index 65720be6..32563798 100644
--- a/test/integration/fixtures/pending/programmatic.fixture.js
+++ b/test/integration/fixtures/pending/programmatic.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-const Mocha = require('../../../../lib/mocha');
+const Mocha = require('../../../../lib/mocha.cjs');
const mocha = new Mocha({reporter: 'json'});
mocha.addFile("./test/integration/fixtures/__default__.fixture.js");
diff --git a/test/integration/fixtures/pending/skip-async-before-hooks.fixture.js b/test/integration/fixtures/pending/skip-async-before-hooks.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-async-before-hooks.fixture.js
rename to test/integration/fixtures/pending/skip-async-before-hooks.fixture.cjs
diff --git a/test/integration/fixtures/pending/skip-async-beforeEach.fixture.js b/test/integration/fixtures/pending/skip-async-beforeEach.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-async-beforeEach.fixture.js
rename to test/integration/fixtures/pending/skip-async-beforeEach.fixture.cjs
diff --git a/test/integration/fixtures/pending/skip-async-spec.fixture.js b/test/integration/fixtures/pending/skip-async-spec.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-async-spec.fixture.js
rename to test/integration/fixtures/pending/skip-async-spec.fixture.cjs
diff --git a/test/integration/fixtures/pending/skip-sync-before-hooks.fixture.js b/test/integration/fixtures/pending/skip-sync-before-hooks.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-sync-before-hooks.fixture.js
rename to test/integration/fixtures/pending/skip-sync-before-hooks.fixture.cjs
diff --git a/test/integration/fixtures/pending/skip-sync-before-inner.fixture.js b/test/integration/fixtures/pending/skip-sync-before-inner.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-sync-before-inner.fixture.js
rename to test/integration/fixtures/pending/skip-sync-before-inner.fixture.cjs
diff --git a/test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js b/test/integration/fixtures/pending/skip-sync-beforeEach.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-sync-beforeEach.fixture.js
rename to test/integration/fixtures/pending/skip-sync-beforeEach.fixture.cjs
diff --git a/test/integration/fixtures/pending/skip-sync-spec.fixture.js b/test/integration/fixtures/pending/skip-sync-spec.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/pending/skip-sync-spec.fixture.js
rename to test/integration/fixtures/pending/skip-sync-spec.fixture.cjs
diff --git a/test/integration/fixtures/plugins/global-fixtures/global-setup-teardown-multiple.fixture.js b/test/integration/fixtures/plugins/global-fixtures/global-setup-teardown-multiple.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/plugins/global-fixtures/global-setup-teardown-multiple.fixture.js
rename to test/integration/fixtures/plugins/global-fixtures/global-setup-teardown-multiple.fixture.cjs
diff --git a/test/integration/fixtures/plugins/global-fixtures/global-setup-teardown.fixture.js b/test/integration/fixtures/plugins/global-fixtures/global-setup-teardown.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/plugins/global-fixtures/global-setup-teardown.fixture.js
rename to test/integration/fixtures/plugins/global-fixtures/global-setup-teardown.fixture.cjs
diff --git a/test/integration/fixtures/plugins/global-fixtures/global-setup-throws.fixture.js b/test/integration/fixtures/plugins/global-fixtures/global-setup-throws.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/plugins/global-fixtures/global-setup-throws.fixture.js
rename to test/integration/fixtures/plugins/global-fixtures/global-setup-throws.fixture.cjs
diff --git a/test/integration/fixtures/plugins/global-fixtures/global-setup.fixture.js b/test/integration/fixtures/plugins/global-fixtures/global-setup.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/plugins/global-fixtures/global-setup.fixture.js
rename to test/integration/fixtures/plugins/global-fixtures/global-setup.fixture.cjs
diff --git a/test/integration/fixtures/plugins/global-fixtures/global-teardown-throws.fixture.js b/test/integration/fixtures/plugins/global-fixtures/global-teardown-throws.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/plugins/global-fixtures/global-teardown-throws.fixture.js
rename to test/integration/fixtures/plugins/global-fixtures/global-teardown-throws.fixture.cjs
diff --git a/test/integration/fixtures/plugins/global-fixtures/global-teardown.fixture.js b/test/integration/fixtures/plugins/global-fixtures/global-teardown.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/plugins/global-fixtures/global-teardown.fixture.js
rename to test/integration/fixtures/plugins/global-fixtures/global-teardown.fixture.cjs
diff --git a/test/integration/fixtures/plugins/root-hooks/package.json b/test/integration/fixtures/plugins/root-hooks/package.json
new file mode 100644
index 00000000..1cd945a3
--- /dev/null
+++ b/test/integration/fixtures/plugins/root-hooks/package.json
@@ -0,0 +1,3 @@
+{
+ "type": "commonjs"
+}
diff --git a/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm.fixture.mjs b/test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm.fixture.js
similarity index 100%
rename from test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm.fixture.mjs
rename to test/integration/fixtures/plugins/root-hooks/root-hook-defs-esm.fixture.js
diff --git a/test/integration/fixtures/plugins/root-hooks/root-hook-test-2.fixture.js b/test/integration/fixtures/plugins/root-hooks/root-hook-test-2.fixture.js
index 4d00018d..03e4b725 100644
--- a/test/integration/fixtures/plugins/root-hooks/root-hook-test-2.fixture.js
+++ b/test/integration/fixtures/plugins/root-hooks/root-hook-test-2.fixture.js
@@ -1,5 +1,5 @@
-// run with --require root-hook-defs-a.fixture.js --require
-// root-hook-defs-b.fixture.js
+// run with --require root-hook-defs-a.fixture.cjs --require
+// root-hook-defs-b.fixture.cjs
it('should also have some root hooks', function() {
// test
diff --git a/test/integration/fixtures/plugins/root-hooks/root-hook-test.fixture.js b/test/integration/fixtures/plugins/root-hooks/root-hook-test.fixture.js
index 412895c8..fd62f9f6 100644
--- a/test/integration/fixtures/plugins/root-hooks/root-hook-test.fixture.js
+++ b/test/integration/fixtures/plugins/root-hooks/root-hook-test.fixture.js
@@ -1,5 +1,5 @@
-// run with --require root-hook-defs-a.fixture.js --require
-// root-hook-defs-b.fixture.js
+// run with --require root-hook-defs-a.fixture.cjs --require
+// root-hook-defs-b.fixture.cjs
it('should have some root hooks', function() {
// test
diff --git a/test/integration/fixtures/retries/early-pass.fixture.js b/test/integration/fixtures/retries/early-pass.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/retries/early-pass.fixture.js
rename to test/integration/fixtures/retries/early-pass.fixture.cjs
diff --git a/test/integration/fixtures/runner/events-bail-retries.fixture.js b/test/integration/fixtures/runner/events-bail-retries.fixture.cjs
similarity index 96%
rename from test/integration/fixtures/runner/events-bail-retries.fixture.js
rename to test/integration/fixtures/runner/events-bail-retries.fixture.cjs
index 5ef61ae8..09904a10 100644
--- a/test/integration/fixtures/runner/events-bail-retries.fixture.js
+++ b/test/integration/fixtures/runner/events-bail-retries.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-var Runner = require('../../../../lib/runner.js');
+var Runner = require('../../../../lib/runner.cjs');
var assert = require('assert');
var constants = Runner.constants;
var EVENT_HOOK_BEGIN = constants.EVENT_HOOK_BEGIN;
diff --git a/test/integration/fixtures/runner/events-bail.fixture.js b/test/integration/fixtures/runner/events-bail.fixture.cjs
similarity index 96%
rename from test/integration/fixtures/runner/events-bail.fixture.js
rename to test/integration/fixtures/runner/events-bail.fixture.cjs
index ccb54a06..f28f4ebb 100644
--- a/test/integration/fixtures/runner/events-bail.fixture.js
+++ b/test/integration/fixtures/runner/events-bail.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-var Runner = require('../../../../lib/runner.js');
+var Runner = require('../../../../lib/runner.cjs');
var assert = require('assert');
var constants = Runner.constants;
var EVENT_HOOK_BEGIN = constants.EVENT_HOOK_BEGIN;
diff --git a/test/integration/fixtures/runner/events-basic.fixture.js b/test/integration/fixtures/runner/events-basic.fixture.cjs
similarity index 97%
rename from test/integration/fixtures/runner/events-basic.fixture.js
rename to test/integration/fixtures/runner/events-basic.fixture.cjs
index 6f38878c..9669146f 100644
--- a/test/integration/fixtures/runner/events-basic.fixture.js
+++ b/test/integration/fixtures/runner/events-basic.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-var Runner = require('../../../../lib/runner.js');
+var Runner = require('../../../../lib/runner.cjs');
var assert = require('assert');
var constants = Runner.constants;
var EVENT_DELAY_BEGIN = constants.EVENT_DELAY_BEGIN;
diff --git a/test/integration/fixtures/runner/events-delay.fixture.js b/test/integration/fixtures/runner/events-delay.fixture.cjs
similarity index 97%
rename from test/integration/fixtures/runner/events-delay.fixture.js
rename to test/integration/fixtures/runner/events-delay.fixture.cjs
index b1ac40ff..4de5531a 100644
--- a/test/integration/fixtures/runner/events-delay.fixture.js
+++ b/test/integration/fixtures/runner/events-delay.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-var Runner = require('../../../../lib/runner.js');
+var Runner = require('../../../../lib/runner.cjs');
var assert = require('assert');
var constants = Runner.constants;
var EVENT_DELAY_BEGIN = constants.EVENT_DELAY_BEGIN;
diff --git a/test/integration/fixtures/runner/events-retries.fixture.js b/test/integration/fixtures/runner/events-retries.fixture.cjs
similarity index 96%
rename from test/integration/fixtures/runner/events-retries.fixture.js
rename to test/integration/fixtures/runner/events-retries.fixture.cjs
index 987c3d81..048661a6 100644
--- a/test/integration/fixtures/runner/events-retries.fixture.js
+++ b/test/integration/fixtures/runner/events-retries.fixture.cjs
@@ -1,5 +1,5 @@
'use strict';
-var Runner = require('../../../../lib/runner.js');
+var Runner = require('../../../../lib/runner.cjs');
var assert = require('assert');
var constants = Runner.constants;
var EVENT_HOOK_BEGIN = constants.EVENT_HOOK_BEGIN;
diff --git a/test/integration/fixtures/signals-sigterm-numeric.fixture.js b/test/integration/fixtures/signals-sigterm-numeric.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/signals-sigterm-numeric.fixture.js
rename to test/integration/fixtures/signals-sigterm-numeric.fixture.cjs
diff --git a/test/integration/fixtures/simple-reporter.js b/test/integration/fixtures/simple-reporter.cjs
similarity index 100%
rename from test/integration/fixtures/simple-reporter.js
rename to test/integration/fixtures/simple-reporter.cjs
diff --git a/test/integration/fixtures/simple-ui.fixture.mjs b/test/integration/fixtures/simple-ui.fixture.cjs
similarity index 56%
rename from test/integration/fixtures/simple-ui.fixture.mjs
rename to test/integration/fixtures/simple-ui.fixture.cjs
index 6c392195..b71f3920 100644
--- a/test/integration/fixtures/simple-ui.fixture.mjs
+++ b/test/integration/fixtures/simple-ui.fixture.cjs
@@ -1,19 +1,19 @@
-import Mocha from '../../../lib/mocha.js'
-import { createCommon as MochaInterface } from '../../../lib/interfaces/common.mjs';
+'use strict';
-const Test = Mocha.Test;
-const EVENT_FILE_PRE_REQUIRE = Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE;
+var Mocha = require('../../../lib/mocha.cjs');
+var Test = Mocha.Test;
+var EVENT_FILE_PRE_REQUIRE = Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE;
/**
* A simple UI that only exposes a single function: test
*/
-function SimpleUI(suite) {
+module.exports = Mocha.interfaces['simple-ui'] = function(suite) {
suite.on(EVENT_FILE_PRE_REQUIRE, function(
context,
file,
mocha
) {
- const common = MochaInterface(
+ var common = require('../../../lib/interfaces/common.js').createCommon(
[suite],
context
);
@@ -25,7 +25,7 @@ function SimpleUI(suite) {
* and callback `fn` acting as a thunk.
*/
context.test = function(title, fn) {
- const test = new Test(title, fn);
+ var test = new Test(title, fn);
test.file = file;
suite.addTest(test);
@@ -33,7 +33,3 @@ function SimpleUI(suite) {
};
});
};
-
-Mocha.interfaces['simple-ui'] = SimpleUI;
-
-export default SimpleUI;
diff --git a/test/integration/fixtures/simple-ui.fixture.js b/test/integration/fixtures/simple-ui.fixture.js
index 4e8ba379..7adc41fa 100644
--- a/test/integration/fixtures/simple-ui.fixture.js
+++ b/test/integration/fixtures/simple-ui.fixture.js
@@ -1,19 +1,19 @@
-'use strict';
+import Mocha from '../../../lib/mocha.cjs'
+import { createCommon as MochaInterface } from '../../../lib/interfaces/common.js';
-var Mocha = require('../../../lib/mocha');
-var Test = Mocha.Test;
-var EVENT_FILE_PRE_REQUIRE = Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE;
+const Test = Mocha.Test;
+const EVENT_FILE_PRE_REQUIRE = Mocha.Suite.constants.EVENT_FILE_PRE_REQUIRE;
/**
* A simple UI that only exposes a single function: test
*/
-module.exports = Mocha.interfaces['simple-ui'] = function(suite) {
+function SimpleUI(suite) {
suite.on(EVENT_FILE_PRE_REQUIRE, function(
context,
file,
mocha
) {
- var common = require('../../../lib/interfaces/common.mjs').createCommon(
+ const common = MochaInterface(
[suite],
context
);
@@ -25,7 +25,7 @@ module.exports = Mocha.interfaces['simple-ui'] = function(suite) {
* and callback `fn` acting as a thunk.
*/
context.test = function(title, fn) {
- var test = new Test(title, fn);
+ const test = new Test(title, fn);
test.file = file;
suite.addTest(test);
@@ -33,3 +33,7 @@ module.exports = Mocha.interfaces['simple-ui'] = function(suite) {
};
});
};
+
+Mocha.interfaces['simple-ui'] = SimpleUI;
+
+export default SimpleUI;
diff --git a/test/integration/fixtures/stack-trace.fixture.js b/test/integration/fixtures/stack-trace.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/stack-trace.fixture.js
rename to test/integration/fixtures/stack-trace.fixture.cjs
diff --git a/test/integration/fixtures/uncaught/listeners.fixture.js b/test/integration/fixtures/uncaught/listeners.fixture.cjs
similarity index 86%
rename from test/integration/fixtures/uncaught/listeners.fixture.js
rename to test/integration/fixtures/uncaught/listeners.fixture.cjs
index 33c70892..b4b9c151 100644
--- a/test/integration/fixtures/uncaught/listeners.fixture.js
+++ b/test/integration/fixtures/uncaught/listeners.fixture.cjs
@@ -1,7 +1,7 @@
'use strict';
const assert = require('assert');
-const mocha = require('../../../../lib/mocha');
+const mocha = require('../../../../lib/mocha.cjs');
// keep this low to avoid warning
for (let i = 0; i < 5; i++) {
diff --git a/test/integration/fixtures/uncaught/recover.fixture.js b/test/integration/fixtures/uncaught/recover.fixture.cjs
similarity index 100%
rename from test/integration/fixtures/uncaught/recover.fixture.js
rename to test/integration/fixtures/uncaught/recover.fixture.cjs
diff --git a/test/integration/glob.spec.js b/test/integration/glob.spec.cjs
similarity index 100%
rename from test/integration/glob.spec.js
rename to test/integration/glob.spec.cjs
diff --git a/test/integration/helpers.js b/test/integration/helpers.cjs
similarity index 97%
rename from test/integration/helpers.js
rename to test/integration/helpers.cjs
index 6f6b18b3..7e964eaf 100644
--- a/test/integration/helpers.js
+++ b/test/integration/helpers.cjs
@@ -5,16 +5,16 @@ const fs = require("node:fs");
const fsP = require("node:fs/promises");
const { format } = require("node:util");
const path = require("node:path");
-const { Base } = require("../../lib/reporters/base.mjs");
-const { escapeRegExp } = require("../../lib/utils/regexp.mjs");
+const { Base } = require("../../lib/reporters/base.js");
+const { escapeRegExp } = require("../../lib/utils/regexp.js");
const debug = require("debug")("mocha:test:integration:helpers");
const SIGNAL_OFFSET = 128;
-const { DEFAULT_WATCH_BUDGET_MS } = require("./constants.mjs");
+const { DEFAULT_WATCH_BUDGET_MS } = require("./constants.js");
/**
* Path to `mocha` executable
*/
-const MOCHA_EXECUTABLE = require.resolve("../../bin/mocha.mjs");
+const MOCHA_EXECUTABLE = require.resolve("../../bin/mocha.js");
/**
* regular expression used for splitting lines based on new line / dot symbol.
@@ -392,16 +392,28 @@ function createSubprocess(args, done, opts = {}) {
* @returns {string} Resolved filepath
*/
function resolveFixturePath(fixture) {
- if (
- path.extname(fixture) !== ".js" &&
- path.extname(fixture) !== ".mjs" &&
- path.extname(fixture) !== ".ts"
- ) {
- fixture += ".fixture.js";
+ if (path.isAbsolute(fixture)) {
+ return fixture;
}
- return path.isAbsolute(fixture)
- ? fixture
- : path.resolve(__dirname, "fixtures", fixture);
+
+ const supportedFixtureExtensions = [".cjs", ".js", ".ts"];
+
+ if (supportedFixtureExtensions.includes(path.extname(fixture))) {
+ return path.resolve(__dirname, "fixtures", fixture);
+ }
+
+ for (const extension of supportedFixtureExtensions) {
+ const resolved = path.resolve(
+ __dirname,
+ "fixtures",
+ `${fixture}.fixture${extension}`,
+ );
+ if (fs.existsSync(resolved)) {
+ return resolved;
+ }
+ }
+
+ return path.resolve(__dirname, "fixtures", `${fixture}.fixture.js`);
}
/**
diff --git a/test/integration/hook-err.spec.js b/test/integration/hook-err.spec.cjs
similarity index 99%
rename from test/integration/hook-err.spec.js
rename to test/integration/hook-err.spec.cjs
index c0904c0c..e7a31481 100644
--- a/test/integration/hook-err.spec.js
+++ b/test/integration/hook-err.spec.cjs
@@ -4,8 +4,8 @@ const {
runMochaJSON,
runMochaJSONAsync,
SPLIT_DOT_REPORTER_REGEXP,
-} = require("./helpers");
-const { bang } = require("../../lib/reporters/base.mjs").Base.symbols;
+} = require("./helpers.cjs");
+const { bang } = require("../../lib/reporters/base.js").Base.symbols;
describe("hook error handling", function () {
let lines;
diff --git a/test/integration/hooks.spec.js b/test/integration/hooks.spec.cjs
similarity index 83%
rename from test/integration/hooks.spec.js
rename to test/integration/hooks.spec.cjs
index 7139a4b8..54cc4169 100644
--- a/test/integration/hooks.spec.js
+++ b/test/integration/hooks.spec.cjs
@@ -1,9 +1,10 @@
"use strict";
var assert = require("node:assert");
-var runMocha = require("./helpers").runMocha;
-var runMochaJSON = require("./helpers").runMochaJSON;
-var SPLIT_DOT_REPORTER_REGEXP = require("./helpers").SPLIT_DOT_REPORTER_REGEXP;
+var runMocha = require("./helpers.cjs").runMocha;
+var runMochaJSON = require("./helpers.cjs").runMochaJSON;
+var SPLIT_DOT_REPORTER_REGEXP =
+ require("./helpers.cjs").SPLIT_DOT_REPORTER_REGEXP;
var args = ["--reporter", "dot"];
describe("hooks", function () {
@@ -52,7 +53,7 @@ describe("hooks", function () {
});
it("current test title of all hooks", function (done) {
- runMochaJSON("current-test-title.fixture.js", [], function (err, res) {
+ runMochaJSON("current-test-title.fixture.cjs", [], function (err, res) {
if (err) {
return done(err);
}
diff --git a/test/integration/init.spec.js b/test/integration/init.spec.cjs
similarity index 97%
rename from test/integration/init.spec.js
rename to test/integration/init.spec.cjs
index ee8298b3..d2f5f269 100644
--- a/test/integration/init.spec.js
+++ b/test/integration/init.spec.cjs
@@ -2,7 +2,7 @@
var fs = require("node:fs");
var rimraf = require("rimraf");
-var invokeMocha = require("./helpers").invokeMocha;
+var invokeMocha = require("./helpers.cjs").invokeMocha;
var path = require("node:path");
var os = require("node:os");
diff --git a/test/integration/invalid-arguments.spec.js b/test/integration/invalid-arguments.spec.cjs
similarity index 90%
rename from test/integration/invalid-arguments.spec.js
rename to test/integration/invalid-arguments.spec.cjs
index bee66ac1..9bf6c138 100644
--- a/test/integration/invalid-arguments.spec.js
+++ b/test/integration/invalid-arguments.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var invokeMocha = require("./helpers").invokeMocha;
+var invokeMocha = require("./helpers.cjs").invokeMocha;
describe("invalid arguments", function () {
describe("when argument is missing required value", function () {
diff --git a/test/integration/multiple-done.spec.js b/test/integration/multiple-done.spec.cjs
similarity index 96%
rename from test/integration/multiple-done.spec.js
rename to test/integration/multiple-done.spec.cjs
index eb37b7b7..e42a0cad 100644
--- a/test/integration/multiple-done.spec.js
+++ b/test/integration/multiple-done.spec.cjs
@@ -1,8 +1,8 @@
"use strict";
-var runMochaJSON = require("./helpers").runMochaJSON;
-var invokeMocha = require("./helpers").invokeMocha;
-var MULTIPLE_DONE = require("../../lib/error-constants.mjs").constants
+var runMochaJSON = require("./helpers.cjs").runMochaJSON;
+var invokeMocha = require("./helpers.cjs").invokeMocha;
+var MULTIPLE_DONE = require("../../lib/error-constants.js").constants
.MULTIPLE_DONE;
describe("multiple calls to done()", function () {
diff --git a/test/integration/multiple-runs.spec.js b/test/integration/multiple-runs.spec.cjs
similarity index 94%
rename from test/integration/multiple-runs.spec.js
rename to test/integration/multiple-runs.spec.cjs
index 5d293e5f..11115ad8 100644
--- a/test/integration/multiple-runs.spec.js
+++ b/test/integration/multiple-runs.spec.cjs
@@ -1,11 +1,11 @@
"use strict";
-const { invokeNode } = require("./helpers");
+const { invokeNode } = require("./helpers.cjs");
describe("multiple runs", function () {
it("should be allowed to run multiple times if cleanReferences is turned off", function (done) {
var path =
- require.resolve("./fixtures/multiple-runs/run-thrice.fixture.js");
+ require.resolve("./fixtures/multiple-runs/run-thrice.fixture.cjs");
invokeNode([path], function (err, res) {
if (err) {
done(err);
@@ -29,7 +29,7 @@ describe("multiple runs", function () {
it("should not be allowed if cleanReferences is true", function (done) {
var path =
- require.resolve("./fixtures/multiple-runs/clean-references.fixture.js");
+ require.resolve("./fixtures/multiple-runs/clean-references.fixture.cjs");
invokeNode(
[path],
function (err, res) {
@@ -49,7 +49,7 @@ describe("multiple runs", function () {
});
it("should not be allowed if the instance is disposed", function (done) {
- var path = require.resolve("./fixtures/multiple-runs/dispose.fixture.js");
+ var path = require.resolve("./fixtures/multiple-runs/dispose.fixture.cjs");
invokeNode(
[path, "--directly-dispose"],
function (err, res) {
@@ -67,7 +67,7 @@ describe("multiple runs", function () {
it("should not be allowed to run while a previous run is in progress", function (done) {
var path =
- require.resolve("./fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture");
+ require.resolve("./fixtures/multiple-runs/start-second-run-if-previous-is-still-running.fixture.cjs");
invokeNode(
[path],
function (err, res) {
@@ -84,7 +84,7 @@ describe("multiple runs", function () {
it("should reset the hooks between runs", function (done) {
var path =
- require.resolve("./fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture");
+ require.resolve("./fixtures/multiple-runs/multiple-runs-with-flaky-before-each.fixture.cjs");
invokeNode([path], function (err, res) {
expect(err, "to be null");
expect(res.code, "to be", 0);
diff --git a/test/integration/no-diff.spec.js b/test/integration/no-diff.spec.cjs
similarity index 80%
rename from test/integration/no-diff.spec.js
rename to test/integration/no-diff.spec.cjs
index 294d6dd5..bc6de838 100644
--- a/test/integration/no-diff.spec.js
+++ b/test/integration/no-diff.spec.cjs
@@ -1,12 +1,12 @@
"use strict";
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var run = helpers.runMocha;
describe("no-diff", function () {
describe("when enabled", function () {
it("should not display a diff", function (done) {
- run("no-diff.fixture.js", ["--no-diff"], function (err, res) {
+ run("no-diff.fixture.cjs", ["--no-diff"], function (err, res) {
if (err) {
done(err);
return;
@@ -20,7 +20,7 @@ describe("no-diff", function () {
describe("when disabled", function () {
it("should display a diff", function (done) {
- run("no-diff.fixture.js", ["--diff"], function (err, res) {
+ run("no-diff.fixture.cjs", ["--diff"], function (err, res) {
if (err) {
done(err);
return;
diff --git a/test/integration/only.spec.js b/test/integration/only.spec.cjs
similarity index 97%
rename from test/integration/only.spec.js
rename to test/integration/only.spec.cjs
index a2e8fccf..f35a1dcd 100644
--- a/test/integration/only.spec.js
+++ b/test/integration/only.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var run = require("./helpers").runMochaJSON;
+var run = require("./helpers.cjs").runMochaJSON;
var assert = require("node:assert");
describe(".only()", function () {
diff --git a/test/integration/options/allowUncaught.spec.js b/test/integration/options/allowUncaught.spec.cjs
similarity index 89%
rename from test/integration/options/allowUncaught.spec.js
rename to test/integration/options/allowUncaught.spec.cjs
index e911dec2..bf27e726 100644
--- a/test/integration/options/allowUncaught.spec.js
+++ b/test/integration/options/allowUncaught.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMocha = helpers.runMocha;
var runMochaJSON = helpers.runMochaJSON;
@@ -9,7 +9,11 @@ describe("--allow-uncaught", function () {
var args = ["--allow-uncaught"];
it("should throw an uncaught error and exit process", function (done) {
- var fixture = path.join("options", "allow-uncaught", "propagate");
+ var fixture = path.join(
+ "options",
+ "allow-uncaught",
+ "propagate.fixture.cjs",
+ );
runMocha(
fixture,
args,
diff --git a/test/integration/options/asyncOnly.spec.js b/test/integration/options/asyncOnly.spec.cjs
similarity index 95%
rename from test/integration/options/asyncOnly.spec.js
rename to test/integration/options/asyncOnly.spec.cjs
index 64bd55f8..dbda1315 100644
--- a/test/integration/options/asyncOnly.spec.js
+++ b/test/integration/options/asyncOnly.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--async-only", function () {
diff --git a/test/integration/options/bail.spec.js b/test/integration/options/bail.spec.cjs
similarity index 98%
rename from test/integration/options/bail.spec.js
rename to test/integration/options/bail.spec.cjs
index 836f7ba7..13dcd44b 100644
--- a/test/integration/options/bail.spec.js
+++ b/test/integration/options/bail.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--bail", function () {
diff --git a/test/integration/options/delay.spec.js b/test/integration/options/delay.spec.cjs
similarity index 97%
rename from test/integration/options/delay.spec.js
rename to test/integration/options/delay.spec.cjs
index c4b0ac53..cda17307 100644
--- a/test/integration/options/delay.spec.js
+++ b/test/integration/options/delay.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--delay", function () {
diff --git a/test/integration/options/dryRun.spec.js b/test/integration/options/dryRun.spec.cjs
similarity index 96%
rename from test/integration/options/dryRun.spec.js
rename to test/integration/options/dryRun.spec.cjs
index 41563b11..d3746ae9 100644
--- a/test/integration/options/dryRun.spec.js
+++ b/test/integration/options/dryRun.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--dry-run", function () {
diff --git a/test/integration/options/exit.spec.js b/test/integration/options/exit.spec.cjs
similarity index 95%
rename from test/integration/options/exit.spec.js
rename to test/integration/options/exit.spec.cjs
index e86748fd..eba2c9c9 100644
--- a/test/integration/options/exit.spec.js
+++ b/test/integration/options/exit.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var runMocha = require("../helpers").runMocha;
+var runMocha = require("../helpers.cjs").runMocha;
describe("--exit", function () {
var behaviors = {
@@ -41,7 +41,7 @@ describe("--exit", function () {
var didExit = true;
var timeoutObj;
- var fixture = "exit.fixture.js";
+ var fixture = "exit.fixture.cjs";
var args = behaviors[behavior] ? [behaviors[behavior]] : [];
mocha = runMocha(fixture, args, function postmortem(err) {
clearTimeout(timeoutObj);
diff --git a/test/integration/options/extension.spec.js b/test/integration/options/extension.spec.cjs
similarity index 92%
rename from test/integration/options/extension.spec.js
rename to test/integration/options/extension.spec.cjs
index 62347932..f6ca84a9 100644
--- a/test/integration/options/extension.spec.js
+++ b/test/integration/options/extension.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var invokeMocha = helpers.invokeMocha;
var toJSONResult = helpers.toJSONResult;
@@ -10,7 +10,7 @@ describe("--extension", function () {
"--require",
"coffeescript/register",
"--require",
- "./test/setup",
+ "./test/setup.cjs",
"--reporter",
"json",
"--extension",
@@ -34,7 +34,7 @@ describe("--extension", function () {
"--require",
"coffeescript/register",
"--require",
- "./test/setup",
+ "./test/setup.cjs",
"--reporter",
"json",
"--extension",
diff --git a/test/integration/options/failZero.spec.js b/test/integration/options/failZero.spec.cjs
similarity index 92%
rename from test/integration/options/failZero.spec.js
rename to test/integration/options/failZero.spec.cjs
index 16156b4b..2b60d975 100644
--- a/test/integration/options/failZero.spec.js
+++ b/test/integration/options/failZero.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--fail-zero", function () {
diff --git a/test/integration/options/file.spec.js b/test/integration/options/file.spec.cjs
similarity index 97%
rename from test/integration/options/file.spec.js
rename to test/integration/options/file.spec.cjs
index 2dc0756c..76cf58cd 100644
--- a/test/integration/options/file.spec.js
+++ b/test/integration/options/file.spec.cjs
@@ -5,7 +5,7 @@ const {
runMochaJSON,
resolveFixturePath: resolvePath,
runMocha,
-} = require("../helpers");
+} = require("../helpers.cjs");
describe("--file", function () {
var args = [];
@@ -68,7 +68,7 @@ describe("--file", function () {
});
it("should run esm tests passed via file", function (done) {
- const esmFile = "collect-files.fixture.mjs";
+ const esmFile = "collect-files.fixture.js";
const testArgs = ["--file", resolvePath(esmFile)];
runMochaJSON(esmFile, testArgs, function (err, res) {
diff --git a/test/integration/options/forbidOnly.spec.js b/test/integration/options/forbidOnly.spec.cjs
similarity index 99%
rename from test/integration/options/forbidOnly.spec.js
rename to test/integration/options/forbidOnly.spec.cjs
index 6d28906a..808661aa 100644
--- a/test/integration/options/forbidOnly.spec.js
+++ b/test/integration/options/forbidOnly.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMocha = helpers.runMocha;
var runMochaJSON = helpers.runMochaJSON;
diff --git a/test/integration/options/forbidPending.spec.js b/test/integration/options/forbidPending.spec.cjs
similarity index 98%
rename from test/integration/options/forbidPending.spec.js
rename to test/integration/options/forbidPending.spec.cjs
index f16e329a..3858429a 100644
--- a/test/integration/options/forbidPending.spec.js
+++ b/test/integration/options/forbidPending.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMocha = helpers.runMocha;
var runMochaJSON = helpers.runMochaJSON;
diff --git a/test/integration/options/grep.spec.js b/test/integration/options/grep.spec.cjs
similarity index 98%
rename from test/integration/options/grep.spec.js
rename to test/integration/options/grep.spec.cjs
index 950ecd61..4d74fc9c 100644
--- a/test/integration/options/grep.spec.js
+++ b/test/integration/options/grep.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMocha = helpers.runMocha;
var runMochaJSON = helpers.runMochaJSON;
diff --git a/test/integration/options/ignore.spec.js b/test/integration/options/ignore.spec.cjs
similarity index 98%
rename from test/integration/options/ignore.spec.js
rename to test/integration/options/ignore.spec.cjs
index 0414c11b..0d64645f 100644
--- a/test/integration/options/ignore.spec.js
+++ b/test/integration/options/ignore.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
var resolvePath = helpers.resolveFixturePath;
diff --git a/test/integration/options/invert.spec.js b/test/integration/options/invert.spec.cjs
similarity index 91%
rename from test/integration/options/invert.spec.js
rename to test/integration/options/invert.spec.cjs
index 20f1e164..fe8bb70a 100644
--- a/test/integration/options/invert.spec.js
+++ b/test/integration/options/invert.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var runMocha = require("../helpers").runMocha;
+var runMocha = require("../helpers.cjs").runMocha;
describe("--invert", function () {
describe("when used without --fgrep or --grep", function () {
diff --git a/test/integration/options/jobs.spec.js b/test/integration/options/jobs.spec.cjs
similarity index 95%
rename from test/integration/options/jobs.spec.js
rename to test/integration/options/jobs.spec.cjs
index 964c4b47..2c1c4e5e 100644
--- a/test/integration/options/jobs.spec.js
+++ b/test/integration/options/jobs.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaAsync = helpers.runMochaAsync;
describe("--jobs", function () {
diff --git a/test/integration/options/listInterfaces.spec.js b/test/integration/options/listInterfaces.spec.cjs
similarity index 89%
rename from test/integration/options/listInterfaces.spec.js
rename to test/integration/options/listInterfaces.spec.cjs
index 72608d7b..c9bcb3d2 100644
--- a/test/integration/options/listInterfaces.spec.js
+++ b/test/integration/options/listInterfaces.spec.cjs
@@ -1,9 +1,9 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var invokeMocha = helpers.invokeMocha;
var escapeRegExp = helpers.escapeRegExp;
-var interfaces = require("../../../lib/mocha").interfaces;
+var interfaces = require("../../../lib/mocha.cjs").interfaces;
describe("--list-interfaces", function () {
it("should dump a list of all interfaces with descriptions", function (done) {
diff --git a/test/integration/options/listReporters.spec.js b/test/integration/options/listReporters.spec.cjs
similarity index 90%
rename from test/integration/options/listReporters.spec.js
rename to test/integration/options/listReporters.spec.cjs
index f9c4dec3..fca9055f 100644
--- a/test/integration/options/listReporters.spec.js
+++ b/test/integration/options/listReporters.spec.cjs
@@ -1,9 +1,9 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var invokeMocha = helpers.invokeMocha;
var escapeRegExp = helpers.escapeRegExp;
-var reporters = require("../../../lib/mocha").reporters;
+var reporters = require("../../../lib/mocha.cjs").reporters;
describe("--list-reporters", function () {
it("should dump a list of all reporters with descriptions", function (done) {
diff --git a/test/integration/options/node-flags.spec.js b/test/integration/options/node-flags.spec.cjs
similarity index 93%
rename from test/integration/options/node-flags.spec.js
rename to test/integration/options/node-flags.spec.cjs
index 92ce1a7d..1224ed73 100644
--- a/test/integration/options/node-flags.spec.js
+++ b/test/integration/options/node-flags.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var invokeMocha = require("../helpers").invokeMocha;
+var invokeMocha = require("../helpers.cjs").invokeMocha;
describe("node flags", function () {
it("should not consider argument values to be node flags", function (done) {
diff --git a/test/integration/options/parallel.spec.js b/test/integration/options/parallel.spec.cjs
similarity index 98%
rename from test/integration/options/parallel.spec.js
rename to test/integration/options/parallel.spec.cjs
index a0389030..2fe35bca 100644
--- a/test/integration/options/parallel.spec.js
+++ b/test/integration/options/parallel.spec.cjs
@@ -1,11 +1,11 @@
"use strict";
-const Mocha = require("../../../lib/mocha");
+const Mocha = require("../../../lib/mocha.cjs");
const {
runMochaAsync,
invokeMochaAsync,
getSummary,
resolveFixturePath,
-} = require("../helpers");
+} = require("../helpers.cjs");
const psList = require("ps-list").default;
const REPORTER_FIXTURE_PATH = resolveFixturePath("options/parallel/test-a");
@@ -41,7 +41,7 @@ async function checkProcessExists(pid) {
* Run a test fixture with the same reporter in both parallel and serial modes,
* returning both outputs for comparison
* @param {string} reporter - Reporter name
- * @returns {{actual: import('../helpers').Summary, expected: import('../helpers').Summary}}
+ * @returns {{actual: import('../helpers.cjs').Summary, expected: import('../helpers.cjs').Summary}}
*/
async function compareReporters(reporter) {
const [actual, expected] = await Promise.all([
@@ -142,14 +142,14 @@ describe("--parallel", function () {
const expected = getSummary(
await invokeMochaAsync([
"--no-parallel",
- resolveFixturePath("esm/*.fixture.mjs"),
+ resolveFixturePath("esm/*.fixture.js"),
])[1],
);
const actual = getSummary(
await invokeMochaAsync([
"--parallel",
- resolveFixturePath("esm/*.fixture.mjs"),
+ resolveFixturePath("esm/*.fixture.js"),
])[1],
);
diff --git a/test/integration/options/passOnFailingTestSuite.spec.js b/test/integration/options/passOnFailingTestSuite.spec.cjs
similarity index 88%
rename from test/integration/options/passOnFailingTestSuite.spec.js
rename to test/integration/options/passOnFailingTestSuite.spec.cjs
index ef2f977b..5e451d11 100644
--- a/test/integration/options/passOnFailingTestSuite.spec.js
+++ b/test/integration/options/passOnFailingTestSuite.spec.cjs
@@ -1,13 +1,13 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("Enabled --pass-on-failing-test-suite", function () {
var args = ["--pass-on-failing-test-suite=true"];
it("Test should finish with zero code with disabled option", function (done) {
- var fixture = "failing-sync.fixture.js";
+ var fixture = "failing-sync.fixture.cjs";
runMochaJSON(fixture, args, function (err, res) {
if (err) {
return done(err);
@@ -25,7 +25,7 @@ describe("Disabled --pass-on-failing-test-suite", function () {
var args = ["--pass-on-failing-test-suite=false"];
it("Test should return non-zero code with enabled option", function (done) {
- var fixture = "failing-sync.fixture.js";
+ var fixture = "failing-sync.fixture.cjs";
runMochaJSON(fixture, args, function (err, res) {
if (err) {
return done(err);
diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.cjs
similarity index 94%
rename from test/integration/options/posixExitCodes.spec.js
rename to test/integration/options/posixExitCodes.spec.cjs
index f4d3a50d..5529f87b 100644
--- a/test/integration/options/posixExitCodes.spec.js
+++ b/test/integration/options/posixExitCodes.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMocha = helpers.runMocha;
var os = require("node:os");
@@ -52,7 +52,7 @@ describe("--posix-exit-codes", function () {
it("should exit with the correct POSIX shell code on numeric fatal signal", function (done) {
// not supported on Windows
if (os.platform() !== "win32") {
- var fixture = "signals-sigterm-numeric.fixture.js";
+ var fixture = "signals-sigterm-numeric.fixture.cjs";
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
return done(err);
@@ -70,7 +70,7 @@ describe("--posix-exit-codes", function () {
});
it("should exit with code 1 if there are test failures", function (done) {
- var fixture = "failing.fixture.js";
+ var fixture = "failing.fixture.cjs";
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
return done(err);
@@ -121,7 +121,7 @@ describe("--posix-exit-codes", function () {
});
it("should exit with code 1 if there are test failures", function (done) {
- var fixture = "failing.fixture.js";
+ var fixture = "failing.fixture.cjs";
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
return done(err);
@@ -139,7 +139,7 @@ describe("--posix-exit-codes", function () {
var args = ["--no-warnings"];
it("should exit with the number of failed tests", function (done) {
- var fixture = "failing.fixture.js";
+ var fixture = "failing.fixture.cjs";
var numFailures = 3;
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
@@ -155,7 +155,7 @@ describe("--posix-exit-codes", function () {
var args = [];
it("should exit with the number of failed tests", function (done) {
- var fixture = "failing.fixture.js";
+ var fixture = "failing.fixture.cjs";
var numFailures = 3;
runMocha(fixture, args, function postmortem(err, res) {
if (err) {
diff --git a/test/integration/options/reporter-option.spec.js b/test/integration/options/reporter-option.spec.cjs
similarity index 88%
rename from test/integration/options/reporter-option.spec.js
rename to test/integration/options/reporter-option.spec.cjs
index 9fbbdaee..60c59fcf 100644
--- a/test/integration/options/reporter-option.spec.js
+++ b/test/integration/options/reporter-option.spec.cjs
@@ -1,13 +1,13 @@
"use strict";
-var runMocha = require("../helpers").runMocha;
+var runMocha = require("../helpers.cjs").runMocha;
var path = require("node:path");
describe("--reporter-option", function () {
describe("when given options w/ invalid format", function () {
it("should display an error", function (done) {
runMocha(
- "passing.fixture.js",
+ "passing.fixture.cjs",
["--reporter-option", "foo=bar=baz"],
function (err, res) {
if (err) {
@@ -25,7 +25,7 @@ describe("--reporter-option", function () {
it("should allow comma-separated values", function (done) {
runMocha(
- "passing.fixture.js",
+ "passing.fixture.cjs",
[
"--reporter",
path.join(
@@ -33,7 +33,7 @@ describe("--reporter-option", function () {
"..",
"fixtures",
"options",
- "reporter-with-options.fixture.js",
+ "reporter-with-options.fixture.cjs",
),
"--reporter-option",
"foo=bar,baz=quux",
@@ -54,7 +54,7 @@ describe("--reporter-option", function () {
it("should allow repeated options", function (done) {
runMocha(
- "passing.fixture.js",
+ "passing.fixture.cjs",
[
"--reporter",
path.join(
@@ -62,7 +62,7 @@ describe("--reporter-option", function () {
"..",
"fixtures",
"options",
- "reporter-with-options.fixture.js",
+ "reporter-with-options.fixture.cjs",
),
"--reporter-option",
"foo=bar",
diff --git a/test/integration/options/reporter.spec.js b/test/integration/options/reporter.spec.cjs
similarity index 80%
rename from test/integration/options/reporter.spec.js
rename to test/integration/options/reporter.spec.cjs
index 3d6f5773..6f82a430 100644
--- a/test/integration/options/reporter.spec.js
+++ b/test/integration/options/reporter.spec.cjs
@@ -1,12 +1,12 @@
"use strict";
-var runMocha = require("../helpers").runMocha;
+var runMocha = require("../helpers.cjs").runMocha;
var path = require("node:path");
describe("--reporter", function () {
it("should work for ESM", function (done) {
runMocha(
- "passing.fixture.js",
+ "passing.fixture.cjs",
[
"--reporter",
path.join(
@@ -14,7 +14,7 @@ describe("--reporter", function () {
"..",
"fixtures",
"options",
- "reporter-esm.fixture.mjs",
+ "reporter-esm.fixture.js",
),
],
function (err, res) {
diff --git a/test/integration/options/retries.spec.js b/test/integration/options/retries.spec.cjs
similarity index 93%
rename from test/integration/options/retries.spec.js
rename to test/integration/options/retries.spec.cjs
index 01385e1f..cf190d8a 100644
--- a/test/integration/options/retries.spec.js
+++ b/test/integration/options/retries.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--retries", function () {
diff --git a/test/integration/options/sort.spec.js b/test/integration/options/sort.spec.cjs
similarity index 93%
rename from test/integration/options/sort.spec.js
rename to test/integration/options/sort.spec.cjs
index 0ac3a9e8..30efb408 100644
--- a/test/integration/options/sort.spec.js
+++ b/test/integration/options/sort.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path").posix;
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--sort", function () {
diff --git a/test/integration/options/timeout.spec.js b/test/integration/options/timeout.spec.cjs
similarity index 98%
rename from test/integration/options/timeout.spec.js
rename to test/integration/options/timeout.spec.cjs
index 8145579f..38e1d4f9 100644
--- a/test/integration/options/timeout.spec.js
+++ b/test/integration/options/timeout.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--timeout", function () {
diff --git a/test/integration/options/ui.spec.js b/test/integration/options/ui.spec.cjs
similarity index 95%
rename from test/integration/options/ui.spec.js
rename to test/integration/options/ui.spec.cjs
index 1e3937bb..77334de8 100644
--- a/test/integration/options/ui.spec.js
+++ b/test/integration/options/ui.spec.cjs
@@ -1,11 +1,11 @@
"use strict";
-var helpers = require("../helpers");
+var helpers = require("../helpers.cjs");
var runMochaJSON = helpers.runMochaJSON;
describe("--ui", function () {
- var simpleUiPath = require.resolve("../fixtures/simple-ui.fixture.js");
- var simpleUiESMPath = require.resolve("../fixtures/simple-ui.fixture.mjs");
+ var simpleUiPath = require.resolve("../fixtures/simple-ui.fixture.cjs");
+ var simpleUiESMPath = require.resolve("../fixtures/simple-ui.fixture.js");
it("should load interface and run it", function (done) {
runMochaJSON(
diff --git a/test/integration/options/watch.spec.js b/test/integration/options/watch.spec.cjs
similarity index 99%
rename from test/integration/options/watch.spec.js
rename to test/integration/options/watch.spec.cjs
index 5416ad3f..997a41ac 100644
--- a/test/integration/options/watch.spec.js
+++ b/test/integration/options/watch.spec.cjs
@@ -11,8 +11,8 @@ const {
replaceFileContents,
createTempDir,
DEFAULT_FIXTURE,
-} = require("../helpers");
-const { DEFAULT_WATCH_BUDGET_MS } = require("../constants.mjs");
+} = require("../helpers.cjs");
+const { DEFAULT_WATCH_BUDGET_MS } = require("../constants.js");
describe("--watch", function () {
describe("when enabled", function () {
@@ -21,7 +21,7 @@ describe("--watch", function () {
*/
let tempDir;
/**
- * @type {import('../helpers').RemoveTempDirCallback}
+ * @type {import('../helpers.cjs').RemoveTempDirCallback}
*/
let cleanup;
diff --git a/test/integration/parallel.spec.js b/test/integration/parallel.spec.cjs
similarity index 67%
rename from test/integration/parallel.spec.js
rename to test/integration/parallel.spec.cjs
index c6b46b29..97b6a14f 100644
--- a/test/integration/parallel.spec.js
+++ b/test/integration/parallel.spec.cjs
@@ -1,46 +1,43 @@
"use strict";
const assert = require("node:assert");
-const { runMochaJSONAsync } = require("./helpers");
+const { runMochaJSONAsync } = require("./helpers.cjs");
describe("parallel run", () => {
/**
* @see https://github.com/mochajs/mocha/issues/4559
*/
it('should allow `import {it} from "mocha"` module syntax', async () => {
- const result = await runMochaJSONAsync("parallel/test3.mjs", [
+ const result = await runMochaJSONAsync("parallel/test3.js", [
"--parallel",
"--jobs",
"2",
- require.resolve("./fixtures/parallel/test1.mjs"),
- require.resolve("./fixtures/parallel/test2.mjs"),
+ require.resolve("./fixtures/parallel/test1.js"),
+ require.resolve("./fixtures/parallel/test2.js"),
]);
assert.strictEqual(result.stats.failures, 1);
assert.strictEqual(result.stats.passes, 2);
});
it("should correctly set worker ids for each process", async () => {
- const result = await runMochaJSONAsync("parallel/testworkerid3.mjs", [
+ const result = await runMochaJSONAsync("parallel/testworkerid3.js", [
"--parallel",
"--jobs",
"2",
- require.resolve("./fixtures/parallel/testworkerid1.mjs"),
- require.resolve("./fixtures/parallel/testworkerid2.mjs"),
+ require.resolve("./fixtures/parallel/testworkerid1.js"),
+ require.resolve("./fixtures/parallel/testworkerid2.js"),
]);
assert.strictEqual(result.stats.failures, 0);
assert.strictEqual(result.stats.passes, 3);
});
it("should correctly handle circular array references in an exception", async () => {
- const result = await runMochaJSONAsync(
- "parallel/circular-error-array.mjs",
- [
- "--parallel",
- "--jobs",
- "2",
- require.resolve("./fixtures/parallel/testworkerid1.mjs"),
- ],
- );
+ const result = await runMochaJSONAsync("parallel/circular-error-array.js", [
+ "--parallel",
+ "--jobs",
+ "2",
+ require.resolve("./fixtures/parallel/testworkerid1.js"),
+ ]);
assert.strictEqual(result.stats.failures, 1);
assert.strictEqual(result.stats.passes, 1);
assert.strictEqual(result.failures[0].err.message, "Foo");
@@ -48,17 +45,14 @@ describe("parallel run", () => {
});
it("should correctly handle an exception with retries", async () => {
- const result = await runMochaJSONAsync(
- "parallel/circular-error-array.mjs",
- [
- "--parallel",
- "--jobs",
- "2",
- "--retries",
- "1",
- require.resolve("./fixtures/parallel/testworkerid1.mjs"),
- ],
- );
+ const result = await runMochaJSONAsync("parallel/circular-error-array.js", [
+ "--parallel",
+ "--jobs",
+ "2",
+ "--retries",
+ "1",
+ require.resolve("./fixtures/parallel/testworkerid1.js"),
+ ]);
assert.strictEqual(result.stats.failures, 1);
assert.strictEqual(result.stats.passes, 1);
assert.strictEqual(result.failures[0].err.message, "Foo");
@@ -67,12 +61,12 @@ describe("parallel run", () => {
it("should correctly handle circular object references in an exception", async () => {
const result = await runMochaJSONAsync(
- "parallel/circular-error-object.mjs",
+ "parallel/circular-error-object.js",
[
"--parallel",
"--jobs",
"2",
- require.resolve("./fixtures/parallel/testworkerid1.mjs"),
+ require.resolve("./fixtures/parallel/testworkerid1.js"),
],
);
assert.strictEqual(result.stats.failures, 1);
@@ -84,11 +78,11 @@ describe("parallel run", () => {
});
it("should correctly handle a non-writable getter reference in an exception", async () => {
- const result = await runMochaJSONAsync("parallel/getter-error-object.mjs", [
+ const result = await runMochaJSONAsync("parallel/getter-error-object.js", [
"--parallel",
"--jobs",
"2",
- require.resolve("./fixtures/parallel/testworkerid1.mjs"),
+ require.resolve("./fixtures/parallel/testworkerid1.js"),
]);
assert.strictEqual(result.stats.failures, 1);
assert.strictEqual(result.stats.passes, 1);
diff --git a/test/integration/pending.spec.js b/test/integration/pending.spec.cjs
similarity index 95%
rename from test/integration/pending.spec.js
rename to test/integration/pending.spec.cjs
index 11ad7ead..816c103d 100644
--- a/test/integration/pending.spec.js
+++ b/test/integration/pending.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var assert = require("node:assert");
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var run = helpers.runMochaJSON;
var invokeNode = helpers.invokeNode;
var toJSONResult = helpers.toJSONResult;
@@ -58,7 +58,7 @@ describe("pending", function () {
describe("synchronous skip()", function () {
describe("in spec", function () {
it("should immediately skip the spec and run all others", function (done) {
- run("pending/skip-sync-spec.fixture.js", args, function (err, res) {
+ run("pending/skip-sync-spec.fixture.cjs", args, function (err, res) {
if (err) {
return done(err);
}
@@ -109,7 +109,7 @@ describe("pending", function () {
});
});
it("should run before and after hooks", function (done) {
- run("pending/skip-sync-before-hooks.fixture.js", function (err, res) {
+ run("pending/skip-sync-before-hooks.fixture.cjs", function (err, res) {
if (err) {
return done(err);
}
@@ -126,7 +126,7 @@ describe("pending", function () {
});
});
it("should skip all sync/async inner before/after hooks", function (done) {
- run("pending/skip-sync-before-inner.fixture.js", function (err, res) {
+ run("pending/skip-sync-before-inner.fixture.cjs", function (err, res) {
if (err) {
return done(err);
}
@@ -166,7 +166,7 @@ describe("pending", function () {
describe("in beforeEach", function () {
it("should skip all suite specs", function (done) {
- var fixture = "pending/skip-sync-beforeEach.fixture.js";
+ var fixture = "pending/skip-sync-beforeEach.fixture.cjs";
run(fixture, args, function (err, res) {
if (err) {
return done(err);
@@ -209,7 +209,7 @@ describe("pending", function () {
describe("asynchronous skip()", function () {
describe("in spec", function () {
it("should immediately skip the spec and run all others", function (done) {
- run("pending/skip-async-spec.fixture.js", args, function (err, res) {
+ run("pending/skip-async-spec.fixture.cjs", args, function (err, res) {
if (err) {
return done(err);
}
@@ -239,7 +239,7 @@ describe("pending", function () {
});
});
it("should run before and after hooks", function (done) {
- run("pending/skip-async-before-hooks.fixture.js", function (err, res) {
+ run("pending/skip-async-before-hooks.fixture.cjs", function (err, res) {
if (err) {
return done(err);
}
@@ -279,7 +279,7 @@ describe("pending", function () {
describe("in beforeEach", function () {
it("should skip all suite specs", function (done) {
- var fixture = "pending/skip-async-beforeEach.fixture.js";
+ var fixture = "pending/skip-async-beforeEach.fixture.cjs";
run(fixture, args, function (err, res) {
if (err) {
return done(err);
@@ -302,7 +302,7 @@ describe("pending", function () {
describe("programmatic usage", function () {
it("should skip the test by listening to test event", function (done) {
- var path = require.resolve("./fixtures/pending/programmatic.fixture.js");
+ var path = require.resolve("./fixtures/pending/programmatic.fixture.cjs");
invokeNode([path], function (err, res) {
if (err) {
return done(err);
diff --git a/test/integration/plugins/global-fixtures.spec.js b/test/integration/plugins/global-fixtures.spec.cjs
similarity index 86%
rename from test/integration/plugins/global-fixtures.spec.js
rename to test/integration/plugins/global-fixtures.spec.cjs
index 5de00a0a..6ac5b8d9 100644
--- a/test/integration/plugins/global-fixtures.spec.js
+++ b/test/integration/plugins/global-fixtures.spec.cjs
@@ -10,7 +10,7 @@ const {
invokeMochaAsync,
resolveFixturePath,
createTempDir,
-} = require("../helpers");
+} = require("../helpers.cjs");
describe("global setup/teardown", function () {
const watchBudgetMs = 8500;
@@ -20,7 +20,9 @@ describe("global setup/teardown", function () {
return expect(
runMochaAsync(DEFAULT_FIXTURE, [
"--require",
- resolveFixturePath("plugins/global-fixtures/global-setup-teardown"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-setup-teardown.fixture.cjs",
+ ),
]),
"when fulfilled",
"to have passed",
@@ -32,7 +34,9 @@ describe("global setup/teardown", function () {
return expect(
runMochaAsync(DEFAULT_FIXTURE, [
"--require",
- resolveFixturePath("plugins/global-fixtures/global-teardown"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-teardown.fixture.cjs",
+ ),
]),
"when fulfilled",
"to contain once",
@@ -46,7 +50,9 @@ describe("global setup/teardown", function () {
return expect(
runMochaAsync(DEFAULT_FIXTURE, [
"--require",
- resolveFixturePath("plugins/global-fixtures/global-setup"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-setup.fixture.cjs",
+ ),
]),
"when fulfilled",
"to contain once",
@@ -59,7 +65,9 @@ describe("global setup/teardown", function () {
return expect(
runMochaAsync(DEFAULT_FIXTURE, [
"--require",
- resolveFixturePath("plugins/global-fixtures/global-setup-teardown"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-setup-teardown.fixture.cjs",
+ ),
]),
"when fulfilled",
"to contain once",
@@ -73,7 +81,7 @@ describe("global setup/teardown", function () {
runMochaAsync(DEFAULT_FIXTURE, [
"--require",
resolveFixturePath(
- "plugins/global-fixtures/global-setup-teardown-multiple",
+ "plugins/global-fixtures/global-setup-teardown-multiple.fixture.cjs",
),
]),
"when fulfilled",
@@ -99,7 +107,7 @@ describe("global setup/teardown", function () {
it("should handle when global teardown throws", async function () {
const res = await runWithFixture(
- "plugins/global-fixtures/global-teardown-throws",
+ "plugins/global-fixtures/global-teardown-throws.fixture.cjs",
);
expect(
res,
@@ -112,7 +120,7 @@ describe("global setup/teardown", function () {
it("should handle when global setup throws", async function () {
const res = await runWithFixture(
- "plugins/global-fixtures/global-setup-throws",
+ "plugins/global-fixtures/global-setup-throws.fixture.cjs",
);
expect(
res,
@@ -149,7 +157,7 @@ describe("global setup/teardown", function () {
[
"--require",
resolveFixturePath(
- "plugins/global-fixtures/global-setup-teardown",
+ "plugins/global-fixtures/global-setup-teardown.fixture.cjs",
),
testFile,
],
@@ -169,7 +177,9 @@ describe("global setup/teardown", function () {
runMochaWatchAsync(
[
"--require",
- resolveFixturePath("plugins/global-fixtures/global-teardown"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-teardown.fixture.cjs",
+ ),
testFile,
],
{ cwd: tempDir, budgetMs: watchBudgetMs },
@@ -190,7 +200,9 @@ describe("global setup/teardown", function () {
runMochaWatchAsync(
[
"--require",
- resolveFixturePath("plugins/global-fixtures/global-setup"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-setup.fixture.cjs",
+ ),
testFile,
],
{ cwd: tempDir, budgetMs: watchBudgetMs },
@@ -211,7 +223,7 @@ describe("global setup/teardown", function () {
[
"--require",
resolveFixturePath(
- "plugins/global-fixtures/global-setup-teardown-multiple",
+ "plugins/global-fixtures/global-setup-teardown-multiple.fixture.cjs",
),
testFile,
],
@@ -234,7 +246,9 @@ describe("global setup/teardown", function () {
runMochaAsync(DEFAULT_FIXTURE, [
"--parallel",
"--require",
- resolveFixturePath("plugins/global-fixtures/global-setup-teardown"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-setup-teardown.fixture.cjs",
+ ),
]),
"when fulfilled",
"to have passed",
@@ -246,7 +260,9 @@ describe("global setup/teardown", function () {
runMochaAsync(DEFAULT_FIXTURE, [
"--parallel",
"--require",
- resolveFixturePath("plugins/global-fixtures/global-setup-teardown"),
+ resolveFixturePath(
+ "plugins/global-fixtures/global-setup-teardown.fixture.cjs",
+ ),
]),
"when fulfilled",
"to contain once",
@@ -261,7 +277,7 @@ describe("global setup/teardown", function () {
"--parallel",
"--require",
resolveFixturePath(
- "plugins/global-fixtures/global-setup-teardown-multiple",
+ "plugins/global-fixtures/global-setup-teardown-multiple.fixture.cjs",
),
]),
"when fulfilled",
@@ -297,7 +313,7 @@ describe("global setup/teardown", function () {
"--parallel",
"--require",
resolveFixturePath(
- "plugins/global-fixtures/global-setup-teardown",
+ "plugins/global-fixtures/global-setup-teardown.fixture.cjs",
),
testFile,
],
@@ -318,7 +334,7 @@ describe("global setup/teardown", function () {
"--parallel",
"--require",
resolveFixturePath(
- "plugins/global-fixtures/global-setup-teardown-multiple",
+ "plugins/global-fixtures/global-setup-teardown-multiple.fixture.cjs",
),
testFile,
],
diff --git a/test/integration/plugins/root-hooks.spec.js b/test/integration/plugins/root-hooks.spec.cjs
similarity index 75%
rename from test/integration/plugins/root-hooks.spec.js
rename to test/integration/plugins/root-hooks.spec.cjs
index 4fe0bcdc..ccea3441 100644
--- a/test/integration/plugins/root-hooks.spec.js
+++ b/test/integration/plugins/root-hooks.spec.cjs
@@ -1,7 +1,6 @@
"use strict";
-var invokeMochaAsync = require("../helpers").invokeMochaAsync;
-const semver = require("semver");
+var invokeMochaAsync = require("../helpers.cjs").invokeMochaAsync;
/**
* Extracts root hook log messages from run results
@@ -93,7 +92,7 @@ describe("root hooks", function () {
"--require=" +
require.resolve(
// as object
- "../fixtures/plugins/root-hooks/root-hook-defs-esm.fixture.mjs",
+ "../fixtures/plugins/root-hooks/root-hook-defs-esm.fixture.js",
),
"--require=" +
require.resolve(
@@ -122,73 +121,8 @@ describe("root hooks", function () {
});
});
- describe("support ESM via .js extension w/o type=module", 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 20.10.0, 21.1.0)
- // newer versions of Node no longer fail :)
- function isNewerVersion(vString) {
- // Latest versions considered "older": 18.20.8, 20.18.3, 22.11.0
- // (May update after writing)
- return semver.satisfies(vString, "^20.19.0 || ^22.12.0 || ^24.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 20.10.0, 21.1.0)
- // newer versions of Node no longer fail :)
- if (isNewerVersion(process.versions.node)) {
- return true; // skip suite on newer Node versions
- }
-
- 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 20.10.0, 21.1.0
- // adding the flag to older versions of Node does nothing
- 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,
- );
- });
- });
-
- describe("on newer versions, should work", function () {
- if (!isNewerVersion(process.versions.node)) {
- return true; // skip suite on older Node versions
- }
-
+ describe("support ESM via .js extension when type=commonjs", function () {
+ describe("should work", function () {
const filename =
"../fixtures/plugins/root-hooks/root-hook-defs-esm-broken.fixture.js";
const runSuccessRegex = /0 passing/;
diff --git a/test/integration/regression.spec.js b/test/integration/regression.spec.cjs
similarity index 96%
rename from test/integration/regression.spec.js
rename to test/integration/regression.spec.cjs
index b88cb286..28038762 100644
--- a/test/integration/regression.spec.js
+++ b/test/integration/regression.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
-var run = require("./helpers").runMocha;
-var runJSON = require("./helpers").runMochaJSON;
+var run = require("./helpers.cjs").runMocha;
+var runJSON = require("./helpers.cjs").runMochaJSON;
describe("regressions", function () {
it("issue-1991: Declarations do not get cleaned up unless you set them to `null` - Memory Leak", function (done) {
diff --git a/test/integration/repo-tooling.spec.js b/test/integration/repo-tooling.spec.cjs
similarity index 83%
rename from test/integration/repo-tooling.spec.js
rename to test/integration/repo-tooling.spec.cjs
index f85adf24..a5e6c81f 100644
--- a/test/integration/repo-tooling.spec.js
+++ b/test/integration/repo-tooling.spec.cjs
@@ -1,16 +1,16 @@
"use strict";
-const { runMochaJSONAsync } = require("./helpers");
+const { runMochaJSONAsync } = require("./helpers.cjs");
describe("repo tooling", function () {
it("issue-5663: line numbers are wrong in stack traces when running mocha self tests", async function () {
- const output = await runMochaJSONAsync("stack-trace.fixture.js");
+ const output = await runMochaJSONAsync("stack-trace.fixture.cjs");
expect(
output.failures[0].err.stack,
"to contain",
// this file needs to be un-excluded from nyc instrumentation, or else this test would fail to catch any
// issues with nyc instrumentation affecting stack traces.
- "stack-trace.fixture.js:7",
+ "stack-trace.fixture.cjs:7",
);
});
});
diff --git a/test/integration/reporters.spec.js b/test/integration/reporters.spec.cjs
similarity index 94%
rename from test/integration/reporters.spec.js
rename to test/integration/reporters.spec.cjs
index c1164d6f..a2beb1fc 100644
--- a/test/integration/reporters.spec.js
+++ b/test/integration/reporters.spec.cjs
@@ -4,7 +4,7 @@ var os = require("node:os");
var fs = require("node:fs");
var crypto = require("node:crypto");
var path = require("node:path");
-var run = require("./helpers").runMocha;
+var run = require("./helpers.cjs").runMocha;
describe("reporters", function () {
describe("markdown", function () {
@@ -12,7 +12,7 @@ describe("reporters", function () {
before(function (done) {
run(
- "passing.fixture.js",
+ "passing.fixture.cjs",
["--reporter", "markdown"],
function (err, result) {
res = result;
@@ -49,7 +49,7 @@ describe("reporters", function () {
"</testsuite>",
];
- run("passing.fixture.js", args, function (err) {
+ run("passing.fixture.cjs", args, function (err) {
if (err) return done(err);
var xml = fs.readFileSync(tmpFile, "utf8");
@@ -67,11 +67,11 @@ describe("reporters", function () {
describe("loader", function () {
it("loads a reporter from a path relative to the current working directory", function (done) {
var reporterAtARelativePath =
- "test/integration/fixtures/simple-reporter.js";
+ "test/integration/fixtures/simple-reporter.cjs";
var args = ["--reporter=" + reporterAtARelativePath];
- run("passing.fixture.js", args, function (err, result) {
+ run("passing.fixture.cjs", args, function (err, result) {
if (err) {
done(err);
return;
@@ -85,12 +85,12 @@ describe("reporters", function () {
// Generates an absolute path string
var reporterAtAnAbsolutePath = path.join(
process.cwd(),
- "test/integration/fixtures/simple-reporter.js",
+ "test/integration/fixtures/simple-reporter.cjs",
);
var args = ["--reporter=" + reporterAtAnAbsolutePath];
- run("passing.fixture.js", args, function (err, result) {
+ run("passing.fixture.cjs", args, function (err, result) {
if (err) {
done(err);
return;
@@ -186,7 +186,7 @@ describe("reporters", function () {
});
};
- runFixtureAndValidateOutput("passing.fixture.js", {
+ runFixtureAndValidateOutput("passing.fixture.cjs", {
numTests: 2,
});
runFixtureAndValidateOutput("reporters.fixture.js", {
diff --git a/test/integration/retries.spec.js b/test/integration/retries.spec.cjs
similarity index 94%
rename from test/integration/retries.spec.js
rename to test/integration/retries.spec.cjs
index c3f03465..38ed55bb 100644
--- a/test/integration/retries.spec.js
+++ b/test/integration/retries.spec.cjs
@@ -1,10 +1,10 @@
"use strict";
var assert = require("node:assert");
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var runJSON = helpers.runMochaJSON;
var args = [];
-var { bang } = require("../../lib/reporters/base.mjs").Base.symbols;
+var { bang } = require("../../lib/reporters/base.js").Base.symbols;
describe("retries", function () {
it("are ran in correct order", function (done) {
@@ -60,7 +60,7 @@ describe("retries", function () {
});
it("should exit early if test passes", function (done) {
- runJSON("retries/early-pass.fixture.js", args, function (err, res) {
+ runJSON("retries/early-pass.fixture.cjs", args, function (err, res) {
if (err) {
return done(err);
}
diff --git a/test/integration/suite.spec.js b/test/integration/suite.spec.cjs
similarity index 97%
rename from test/integration/suite.spec.js
rename to test/integration/suite.spec.cjs
index 758954b9..0e275fde 100644
--- a/test/integration/suite.spec.js
+++ b/test/integration/suite.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var run = require("./helpers").runMocha;
+var run = require("./helpers.cjs").runMocha;
var args = [];
describe("suite w/no callback", function () {
diff --git a/test/integration/timeout.spec.js b/test/integration/timeout.spec.cjs
similarity index 96%
rename from test/integration/timeout.spec.js
rename to test/integration/timeout.spec.cjs
index c0389647..1396d319 100644
--- a/test/integration/timeout.spec.js
+++ b/test/integration/timeout.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var assert = require("node:assert");
-var run = require("./helpers").runMochaJSON;
+var run = require("./helpers.cjs").runMochaJSON;
var args = [];
describe("this.timeout()", function () {
diff --git a/test/integration/uncaught.spec.js b/test/integration/uncaught.spec.cjs
similarity index 99%
rename from test/integration/uncaught.spec.js
rename to test/integration/uncaught.spec.cjs
index 0a62b743..91717ae9 100644
--- a/test/integration/uncaught.spec.js
+++ b/test/integration/uncaught.spec.cjs
@@ -6,7 +6,7 @@ const {
invokeMochaAsync,
invokeNode,
resolveFixturePath,
-} = require("./helpers");
+} = require("./helpers.cjs");
var args = [];
describe("uncaught exceptions", function () {
diff --git a/test/interfaces/bdd.spec.js b/test/interfaces/bdd.spec.js
index 99554554..a0575146 100644
--- a/test/interfaces/bdd.spec.js
+++ b/test/interfaces/bdd.spec.js
@@ -1,5 +1,3 @@
-"use strict";
-
describe("integer primitives", function () {
describe("arithmetic", function () {
it("should add", function () {
diff --git a/test/interfaces/exports.spec.js b/test/interfaces/exports.spec.cjs
similarity index 100%
rename from test/interfaces/exports.spec.js
rename to test/interfaces/exports.spec.cjs
diff --git a/test/interfaces/qunit.spec.js b/test/interfaces/qunit.spec.js
index b6479536..1faa6113 100644
--- a/test/interfaces/qunit.spec.js
+++ b/test/interfaces/qunit.spec.js
@@ -1,5 +1,3 @@
-"use strict";
-
suite("integer primitives");
test("should add", function () {
diff --git a/test/interfaces/tdd.spec.js b/test/interfaces/tdd.spec.js
index 14642c1e..65846ad6 100644
--- a/test/interfaces/tdd.spec.js
+++ b/test/interfaces/tdd.spec.js
@@ -1,5 +1,3 @@
-"use strict";
-
suite("integer primitives", function () {
suite("arithmetic", function () {
var initialValue = 41;
diff --git a/test/jsapi/index.js b/test/jsapi/index.js
new file mode 100644
index 00000000..feb89069
--- /dev/null
+++ b/test/jsapi/index.js
@@ -0,0 +1,23 @@
+import Mocha from "../../index.js";
+
+var mocha = new Mocha({
+ ui: "bdd",
+ globals: ["okGlobalA", "okGlobalB", "okGlobalC", "callback*"],
+ growl: true,
+});
+
+import "../setup.cjs";
+
+mocha.addFile("test/unit/suite.spec.cjs");
+mocha.addFile("test/unit/runner.spec.cjs");
+mocha.addFile("test/unit/runnable.spec.cjs");
+mocha.addFile("test/unit/hook-sync.spec.cjs");
+mocha.addFile("test/unit/hook-sync-nested.spec.cjs");
+mocha.addFile("test/unit/hook-async.spec.cjs");
+mocha.addFile("test/unit/duration.spec.cjs");
+mocha.addFile("test/unit/globals.spec.cjs");
+mocha.addFile("test/unit/timeout.spec.cjs");
+
+mocha.run(function () {
+ console.log("done");
+});
diff --git a/test/jsapi/index.mjs b/test/jsapi/index.mjs
deleted file mode 100644
index df4f4266..00000000
--- a/test/jsapi/index.mjs
+++ /dev/null
@@ -1,23 +0,0 @@
-import Mocha from "../../index.mjs";
-
-var mocha = new Mocha({
- ui: "bdd",
- globals: ["okGlobalA", "okGlobalB", "okGlobalC", "callback*"],
- growl: true,
-});
-
-import "../setup.js";
-
-mocha.addFile("test/unit/suite.spec.js");
-mocha.addFile("test/unit/runner.spec.js");
-mocha.addFile("test/unit/runnable.spec.js");
-mocha.addFile("test/unit/hook-sync.spec.js");
-mocha.addFile("test/unit/hook-sync-nested.spec.js");
-mocha.addFile("test/unit/hook-async.spec.js");
-mocha.addFile("test/unit/duration.spec.js");
-mocha.addFile("test/unit/globals.spec.js");
-mocha.addFile("test/unit/timeout.spec.js");
-
-mocha.run(function () {
- console.log("done");
-});
diff --git a/test/node-unit/buffered-worker-pool.spec.js b/test/node-unit/buffered-worker-pool.spec.cjs
similarity index 97%
rename from test/node-unit/buffered-worker-pool.spec.js
rename to test/node-unit/buffered-worker-pool.spec.cjs
index ff70e7f1..cb2d8f3e 100644
--- a/test/node-unit/buffered-worker-pool.spec.js
+++ b/test/node-unit/buffered-worker-pool.spec.cjs
@@ -30,13 +30,13 @@ describe("class BufferedWorkerPool", function () {
serializeJavascript = sinon.spy(require("serialize-javascript"));
BufferedWorkerPool = rewiremock.proxy(
- require.resolve("../../lib/nodejs/buffered-worker-pool"),
+ require.resolve("../../lib/nodejs/buffered-worker-pool.cjs"),
{
workerpool: {
pool: sinon.stub().returns(pool),
cpus: 8,
},
- "../../lib/nodejs/serializer": serializer,
+ "../../lib/nodejs/serializer.js": serializer,
"serialize-javascript": serializeJavascript,
},
).BufferedWorkerPool;
diff --git a/test/node-unit/cli/config.spec.js b/test/node-unit/cli/config.spec.cjs
similarity index 96%
rename from test/node-unit/cli/config.spec.js
rename to test/node-unit/cli/config.spec.cjs
index 10ac61fe..85ae6900 100644
--- a/test/node-unit/cli/config.spec.js
+++ b/test/node-unit/cli/config.spec.cjs
@@ -2,7 +2,7 @@
const sinon = require("sinon");
const rewiremock = require("rewiremock/node");
-const { parsers } = require("../../../lib/cli/config");
+const { parsers } = require("../../../lib/cli/config.cjs");
describe("cli/config", function () {
const phonyConfigObject = { ok: true };
@@ -17,7 +17,7 @@ describe("cli/config", function () {
beforeEach(function () {
const config = rewiremock.proxy(
- require.resolve("../../../lib/cli/config"),
+ require.resolve("../../../lib/cli/config.cjs"),
);
parsers = config.parsers;
loadConfig = config.loadConfig;
@@ -144,7 +144,7 @@ describe("cli/config", function () {
beforeEach(function () {
findup = { sync: sinon.stub().returns("/some/path/.mocharc.js") };
const config = rewiremock.proxy(
- require.resolve("../../../lib/cli/config"),
+ require.resolve("../../../lib/cli/config.cjs"),
(r) => ({
"find-up": r.by(() => findup),
}),
@@ -175,7 +175,7 @@ describe("cli/config", function () {
// Fixture exists, but fails loading.
// Prints correct error message without using fallback path.
expect(
- () => parsers.js(require.resolve("./fixtures/bad-require.fixture.js")),
+ () => parsers.js(require.resolve("./fixtures/bad-require.fixture.cjs")),
"to throw",
{ message: /Cannot find module 'fake'/, code: "MODULE_NOT_FOUND" },
);
diff --git a/test/node-unit/cli/fixtures/bad-require.fixture.js b/test/node-unit/cli/fixtures/bad-require.fixture.cjs
similarity index 100%
rename from test/node-unit/cli/fixtures/bad-require.fixture.js
rename to test/node-unit/cli/fixtures/bad-require.fixture.cjs
diff --git a/test/node-unit/cli/mocha-flags.spec.js b/test/node-unit/cli/mocha-flags.spec.cjs
similarity index 93%
rename from test/node-unit/cli/mocha-flags.spec.js
rename to test/node-unit/cli/mocha-flags.spec.cjs
index 6cb20187..dbfa7482 100644
--- a/test/node-unit/cli/mocha-flags.spec.js
+++ b/test/node-unit/cli/mocha-flags.spec.cjs
@@ -4,7 +4,7 @@ var { expect } = require("chai");
const {
types,
expectedTypeForFlag,
-} = require("../../../lib/cli/run-option-metadata.mjs");
+} = require("../../../lib/cli/run-option-metadata.cjs");
describe("mocha-flags", function () {
describe("expectedTypeForFlag()", function () {
diff --git a/test/node-unit/cli/node-flags.spec.js b/test/node-unit/cli/node-flags.spec.cjs
similarity index 98%
rename from test/node-unit/cli/node-flags.spec.js
rename to test/node-unit/cli/node-flags.spec.cjs
index 77061c6a..0d8d7a29 100644
--- a/test/node-unit/cli/node-flags.spec.js
+++ b/test/node-unit/cli/node-flags.spec.cjs
@@ -5,9 +5,9 @@ const {
isNodeFlag,
impliesNoTimeouts,
unparseNodeFlags,
-} = require("../../../lib/cli/node-flags.mjs");
+} = require("../../../lib/cli/node-flags.cjs");
-const { isMochaFlag } = require("../../../lib/cli/run-option-metadata.mjs");
+const { isMochaFlag } = require("../../../lib/cli/run-option-metadata.cjs");
describe("node-flags", function () {
describe("isNodeFlag()", function () {
diff --git a/test/node-unit/cli/options.spec.mjs b/test/node-unit/cli/options.spec.js
similarity index 98%
rename from test/node-unit/cli/options.spec.mjs
rename to test/node-unit/cli/options.spec.js
index 138f9485..4beb1f94 100644
--- a/test/node-unit/cli/options.spec.mjs
+++ b/test/node-unit/cli/options.spec.js
@@ -1,11 +1,15 @@
+import { createRequire } from "node:module";
import sinon from "sinon";
-import { proxy } from "rewiremock/node";
-import { ONE_AND_DONE_ARGS } from "../../../lib/cli/one-and-dones.mjs";
-import { constants } from "../../../lib/error-constants.mjs";
+import rewiremock from "rewiremock/node.js";
+import { ONE_AND_DONE_ARGS } from "../../../lib/cli/one-and-dones.js";
+import { constants } from "../../../lib/error-constants.js";
-const modulePath = require.resolve("../../../lib/cli/options.mjs");
+const require = createRequire(import.meta.url);
+const { proxy } = rewiremock;
+
+const modulePath = require.resolve("../../../lib/cli/options.cjs");
const mocharcPath = require.resolve("../../../lib/mocharc.json");
-const configPath = require.resolve("../../../lib/cli/config");
+const configPath = require.resolve("../../../lib/cli/config.cjs");
const proxyLoadOptions = ({
readFileSync = {},
@@ -148,7 +152,7 @@ describe("options", function () {
loadOptions("--package /something/wherever --require butts");
},
"to throw",
- "Unable to read /something/wherever: bad file message",
+ "Unable to read /something/wherever: bad file message: Sinon-provided bad file message",
);
});
});
diff --git a/test/node-unit/cli/run-helpers.spec.js b/test/node-unit/cli/run-helpers.spec.cjs
similarity index 96%
rename from test/node-unit/cli/run-helpers.spec.js
rename to test/node-unit/cli/run-helpers.spec.cjs
index eabb0b92..ba924546 100644
--- a/test/node-unit/cli/run-helpers.spec.js
+++ b/test/node-unit/cli/run-helpers.spec.cjs
@@ -1,7 +1,10 @@
"use strict";
-const { validateLegacyPlugin, list } = require("../../../lib/cli/run-helpers");
-const Mocha = require("../../../lib/mocha");
+const {
+ validateLegacyPlugin,
+ list,
+} = require("../../../lib/cli/run-helpers.cjs");
+const Mocha = require("../../../lib/mocha.cjs");
describe("helpers", function () {
describe("validateLegacyPlugin()", function () {
@@ -56,7 +59,7 @@ describe("helpers", function () {
});
describe("when used with a third-party interface", function () {
- // this test name is referenced in a comment in `lib/mocha.js`
+ // this test name is referenced in a comment in `lib/mocha.cjs`
// don't change here without also changing there
it('should add the interface to "Mocha.interfaces"', function () {
// let's suppose that `glob` is an interface
@@ -88,7 +91,7 @@ describe("helpers", function () {
() =>
validateLegacyPlugin(
{
- reporter: require.resolve("./fixtures/bad-require.fixture.js"),
+ reporter: require.resolve("./fixtures/bad-require.fixture.cjs"),
},
"reporter",
),
diff --git a/test/node-unit/cli/run.spec.js b/test/node-unit/cli/run.spec.cjs
similarity index 92%
rename from test/node-unit/cli/run.spec.js
rename to test/node-unit/cli/run.spec.cjs
index e76e94c7..1969b649 100644
--- a/test/node-unit/cli/run.spec.js
+++ b/test/node-unit/cli/run.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
-const { builder } = require("../../../lib/cli/run");
-const { types } = require("../../../lib/cli/run-option-metadata.mjs");
+const { builder } = require("../../../lib/cli/run.cjs");
+const { types } = require("../../../lib/cli/run-option-metadata.cjs");
describe("command", function () {
describe("run", function () {
diff --git a/test/node-unit/esm-utils.spec.js b/test/node-unit/esm-utils.spec.cjs
similarity index 97%
rename from test/node-unit/esm-utils.spec.js
rename to test/node-unit/esm-utils.spec.cjs
index 13e9baf4..1b855f71 100644
--- a/test/node-unit/esm-utils.spec.js
+++ b/test/node-unit/esm-utils.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-const esmUtils = require("../../lib/nodejs/esm-utils");
+const esmUtils = require("../../lib/nodejs/esm-utils.cjs");
const sinon = require("sinon");
const url = require("node:url");
@@ -10,13 +10,13 @@ describe("esm-utils", function () {
return expect(
() =>
esmUtils.requireOrImport(
- "../../test/node-unit/fixtures/broken-default-import.mjs",
+ "../../test/node-unit/fixtures/broken-default-import.js",
),
"to be rejected with error satisfying",
{
name: "SyntaxError",
message:
- "The requested module './module-without-default-export.mjs' does not provide an export named 'default'",
+ "The requested module './module-without-default-export.js' does not provide an export named 'default'",
},
);
});
diff --git a/test/node-unit/fixtures/broken-default-import.mjs b/test/node-unit/fixtures/broken-default-import.js
similarity index 86%
rename from test/node-unit/fixtures/broken-default-import.mjs
rename to test/node-unit/fixtures/broken-default-import.js
index 52310301..92795c77 100644
--- a/test/node-unit/fixtures/broken-default-import.mjs
+++ b/test/node-unit/fixtures/broken-default-import.js
@@ -1,3 +1,3 @@
-import moduleWithoutDefaultExport from './module-without-default-export.mjs';
+import moduleWithoutDefaultExport from './module-without-default-export.js';
moduleWithoutDefaultExport;
diff --git a/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts b/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts
index f1eed820..9898ba3c 100644
--- a/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts
+++ b/test/node-unit/fixtures/mock-mocha-forbidden-exclusivity-err.ts
@@ -2,7 +2,7 @@
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.mjs');
+const { createForbiddenExclusivityError } = require('../../../lib/errors.js');
// Simulate a mocha instance in worker mode
const mockMocha = { isWorker: true };
diff --git a/test/node-unit/fixtures/module-without-default-export.mjs b/test/node-unit/fixtures/module-without-default-export.js
similarity index 100%
rename from test/node-unit/fixtures/module-without-default-export.mjs
rename to test/node-unit/fixtures/module-without-default-export.js
diff --git a/test/node-unit/mocha.spec.js b/test/node-unit/mocha.spec.cjs
similarity index 96%
rename from test/node-unit/mocha.spec.js
rename to test/node-unit/mocha.spec.cjs
index fb12b5a7..057f60b8 100644
--- a/test/node-unit/mocha.spec.js
+++ b/test/node-unit/mocha.spec.cjs
@@ -62,15 +62,15 @@ describe("Mocha", function () {
stubs.Runner.constants = {};
Mocha = rewiremock.proxy(
- () => require("../../lib/mocha"),
+ () => require("../../lib/mocha.cjs"),
(r) => ({
- "../../lib/utils.js": r.with(stubs.utils).callThrough(),
- "../../lib/suite.mjs": { Suite: stubs.Suite },
- "../../lib/nodejs/parallel-buffered-runner.js":
+ "../../lib/utils.cjs": r.with(stubs.utils).callThrough(),
+ "../../lib/suite.js": { Suite: stubs.Suite },
+ "../../lib/nodejs/parallel-buffered-runner.cjs":
stubs.ParallelBufferedRunner,
- "../../lib/nodejs/esm-utils": stubs.esmUtils,
- "../../lib/runner.js": stubs.Runner,
- "../../lib/errors.mjs": stubs.errors,
+ "../../lib/nodejs/esm-utils.cjs": stubs.esmUtils,
+ "../../lib/runner.cjs": stubs.Runner,
+ "../../lib/errors.js": stubs.errors,
}),
);
delete require.cache[DUMB_FIXTURE_PATH];
@@ -264,7 +264,7 @@ describe("Mocha", function () {
it("should load from current working directory", function () {
expect(function () {
- mocha.reporter("./lib/reporters/spec.mjs");
+ mocha.reporter("./lib/reporters/spec.js");
}, "not to throw");
});
diff --git a/test/node-unit/parallel-buffered-runner.spec.js b/test/node-unit/parallel-buffered-runner.spec.cjs
similarity index 98%
rename from test/node-unit/parallel-buffered-runner.spec.js
rename to test/node-unit/parallel-buffered-runner.spec.cjs
index 9813c5a1..3f20cdd4 100644
--- a/test/node-unit/parallel-buffered-runner.spec.js
+++ b/test/node-unit/parallel-buffered-runner.spec.cjs
@@ -6,12 +6,12 @@ const {
EVENT_TEST_FAIL,
EVENT_SUITE_END,
EVENT_SUITE_BEGIN,
-} = require("../../lib/runner").constants;
+} = require("../../lib/runner.cjs").constants;
const rewiremock = require("rewiremock/node");
-const { Suite } = require("../../lib/suite.mjs");
-const Runner = require("../../lib/runner");
+const { Suite } = require("../../lib/suite.js");
+const Runner = require("../../lib/runner.cjs");
const sinon = require("sinon");
-const { constants } = require("../../lib/utils");
+const { constants } = require("../../lib/utils.cjs");
const { MOCHA_ID_PROP_NAME } = constants;
describe("parallel-buffered-runner", function () {
@@ -44,13 +44,13 @@ describe("parallel-buffered-runner", function () {
* @type {ParallelBufferedRunner}
*/
ParallelBufferedRunner = rewiremock.proxy(
- () => require("../../lib/nodejs/parallel-buffered-runner"),
+ () => require("../../lib/nodejs/parallel-buffered-runner.cjs"),
(r) => ({
- "../../lib/nodejs/buffered-worker-pool": {
+ "../../lib/nodejs/buffered-worker-pool.cjs": {
BufferedWorkerPool,
},
- "../../lib/utils": r.with({ warn }).callThrough(),
- "../../lib/errors": r
+ "../../lib/utils.cjs": r.with({ warn }).callThrough(),
+ "../../lib/errors.js": r
.with({
createFatalError: sinon.stub().returns(fatalError),
})
diff --git a/test/node-unit/reporters/parallel-buffered.spec.js b/test/node-unit/reporters/parallel-buffered.spec.cjs
similarity index 96%
rename from test/node-unit/reporters/parallel-buffered.spec.js
rename to test/node-unit/reporters/parallel-buffered.spec.cjs
index f11095e0..38359053 100644
--- a/test/node-unit/reporters/parallel-buffered.spec.js
+++ b/test/node-unit/reporters/parallel-buffered.spec.cjs
@@ -17,7 +17,7 @@ const {
EVENT_HOOK_BEGIN,
EVENT_HOOK_END,
EVENT_RUN_END,
-} = require("../../../lib/runner").constants;
+} = require("../../../lib/runner.cjs").constants;
const { EventEmitter } = require("node:events");
const sinon = require("sinon");
const rewiremock = require("rewiremock/node");
@@ -31,9 +31,9 @@ describe("ParallelBuffered", function () {
beforeEach(function () {
runner = new EventEmitter();
ParallelBuffered = rewiremock.proxy(
- () => require("../../../lib/nodejs/reporters/parallel-buffered"),
+ () => require("../../../lib/nodejs/reporters/parallel-buffered.cjs"),
{
- "../../../lib/nodejs/serializer": {
+ "../../../lib/nodejs/serializer.js": {
SerializableEvent: {
create: (eventName, runnable, err) => ({
eventName,
@@ -50,7 +50,7 @@ describe("ParallelBuffered", function () {
}),
},
},
- "../../../lib/reporters/base.mjs": { Base: class MockBase {} },
+ "../../../lib/reporters/base.js": { Base: class MockBase {} },
},
);
});
@@ -105,7 +105,7 @@ describe("ParallelBuffered", function () {
it("should remove all listeners", function () {
runner.emit(EVENT_RUN_END);
// Some node versions throw instead of returning `[]` due to a bug
- // Fix is in Node ^22.14 and ^24.0, but not yet backported to 20 as of writing
+ // Fix is in Node ^22.14 and ^24.0, but not backported to 20 (now EOL)
// Problem was introduced in 20.19.0, not present in 20.18.3
// https://github.com/nodejs/node/issues/56263
const nodeVersionThrows = semver.satisfies(
diff --git a/test/node-unit/serializer.spec.js b/test/node-unit/serializer.spec.cjs
similarity index 99%
rename from test/node-unit/serializer.spec.js
rename to test/node-unit/serializer.spec.cjs
index ceed79d9..d0341b51 100644
--- a/test/node-unit/serializer.spec.js
+++ b/test/node-unit/serializer.spec.cjs
@@ -6,7 +6,7 @@ const {
deserialize,
SerializableEvent,
SerializableWorkerResult,
-} = require("../../lib/nodejs/serializer.mjs");
+} = require("../../lib/nodejs/serializer.js");
describe("serializer", function () {
afterEach(function () {
diff --git a/test/node-unit/stack-trace-filter.spec.js b/test/node-unit/stack-trace-filter.spec.cjs
similarity index 93%
rename from test/node-unit/stack-trace-filter.spec.js
rename to test/node-unit/stack-trace-filter.spec.cjs
index c9e98b54..641c562f 100644
--- a/test/node-unit/stack-trace-filter.spec.js
+++ b/test/node-unit/stack-trace-filter.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var path = require("node:path");
-var utils = require("../../lib/utils");
+var utils = require("../../lib/utils.cjs");
describe("stackTraceFilter()", function () {
describe("on node", function () {
@@ -20,12 +20,12 @@ describe("stackTraceFilter()", function () {
"at EventEmitter.<anonymous> (/usr/local/dev/test.js:16:12)",
"at Context.<anonymous> (/usr/local/dev/test.js:19:5)",
"Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:244:7)",
- "Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:374:10)",
- "/usr/local/lib/node_modules/mocha/lib/runner.js:452:12",
- "next (/usr/local/lib/node_modules/mocha/lib/runner.js:299:14)",
- "/usr/local/lib/node_modules/mocha/lib/runner.js:309:7",
- "next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)",
- "Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)",
+ "Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.cjs:374:10)",
+ "/usr/local/lib/node_modules/mocha/lib/runner.cjs:452:12",
+ "next (/usr/local/lib/node_modules/mocha/lib/runner.cjs:299:14)",
+ "/usr/local/lib/node_modules/mocha/lib/runner.cjs:309:7",
+ "next (/usr/local/lib/node_modules/mocha/lib/runner.cjs:248:23)",
+ "Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.cjs:276:5)",
"at processImmediate [as _immediateCallback] (timers.js:321:17)",
];
expect(filter(stack.join("\n")), "to be", stack.slice(0, 3).join("\n"));
@@ -39,8 +39,8 @@ describe("stackTraceFilter()", function () {
"at yourFunction (/usr/local/dev/own/tmp/test1.js:24:13)",
"at Context.<anonymous> (/usr/local/dev/some-test-file:30:4)",
"Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:218:15)",
- "next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)",
- "Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)",
+ "next (/usr/local/lib/node_modules/mocha/lib/runner.cjs:248:23)",
+ "Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.cjs:276:5)",
"at processImmediate [as _immediateCallback] (timers.js:321:17)",
];
diff --git a/test/node-unit/utils.spec.js b/test/node-unit/utils.spec.cjs
similarity index 97%
rename from test/node-unit/utils.spec.js
rename to test/node-unit/utils.spec.cjs
index 2ff4e188..6c0c01cb 100644
--- a/test/node-unit/utils.spec.js
+++ b/test/node-unit/utils.spec.cjs
@@ -7,7 +7,7 @@ describe("utils", function () {
beforeEach(function () {
// add deps to be mocked as needed to second parameter
- utils = rewiremock.proxy("../../lib/utils", {});
+ utils = rewiremock.proxy("../../lib/utils.cjs", {});
});
describe("function", function () {
diff --git a/test/node-unit/worker.spec.js b/test/node-unit/worker.spec.cjs
similarity index 95%
rename from test/node-unit/worker.spec.js
rename to test/node-unit/worker.spec.cjs
index 783e27e3..c393e68e 100644
--- a/test/node-unit/worker.spec.js
+++ b/test/node-unit/worker.spec.cjs
@@ -2,10 +2,10 @@
const serializeJavascript = require("serialize-javascript");
const rewiremock = require("rewiremock/node");
-const { SerializableWorkerResult } = require("../../lib/nodejs/serializer.mjs");
+const { SerializableWorkerResult } = require("../../lib/nodejs/serializer.js");
const sinon = require("sinon");
-const WORKER_PATH = require.resolve("../../lib/nodejs/worker.js");
+const WORKER_PATH = require.resolve("../../lib/nodejs/worker.cjs");
describe("worker", function () {
let worker;
@@ -64,10 +64,10 @@ describe("worker", function () {
worker = rewiremock.proxy(WORKER_PATH, {
workerpool: stubs.workerpool,
- "../../lib/mocha": stubs.Mocha,
- "../../lib/nodejs/serializer.mjs": stubs.serializer,
- "../../lib/cli/run-helpers": stubs.runHelpers,
- "../../lib/plugin-loader.mjs": stubs.plugin,
+ "../../lib/mocha.cjs": stubs.Mocha,
+ "../../lib/nodejs/serializer.js": stubs.serializer,
+ "../../lib/cli/run-helpers.cjs": stubs.runHelpers,
+ "../../lib/plugin-loader.js": stubs.plugin,
});
});
diff --git a/test/only/bdd-require.spec.js b/test/only/bdd-require.spec.cjs
similarity index 91%
rename from test/only/bdd-require.spec.js
rename to test/only/bdd-require.spec.cjs
index 1abdf879..b7d973f5 100644
--- a/test/only/bdd-require.spec.js
+++ b/test/only/bdd-require.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-var mocha = require("../../lib/mocha");
+var mocha = require("../../lib/mocha.cjs");
var beforeEach = mocha.beforeEach;
var it = mocha.it;
diff --git a/test/only/global/bdd.spec.js b/test/only/global/bdd.spec.js
index 537a220c..48340129 100644
--- a/test/only/global/bdd.spec.js
+++ b/test/only/global/bdd.spec.js
@@ -1,5 +1,3 @@
-"use strict";
-
// Root-only test cases
it.only("#Root-Suite, should run this bdd test-case #1", function () {
expect(true, "to be", true);
diff --git a/test/only/global/qunit.spec.js b/test/only/global/qunit.spec.js
index a62e1880..61c7c3d6 100644
--- a/test/only/global/qunit.spec.js
+++ b/test/only/global/qunit.spec.js
@@ -1,5 +1,3 @@
-"use strict";
-
// Root-only test cases
test.only("#Root-Suite, should run this qunit test-case #1", function () {
expect(true, "to be", true);
diff --git a/test/only/global/tdd.spec.js b/test/only/global/tdd.spec.js
index 421bd859..6be3a915 100644
--- a/test/only/global/tdd.spec.js
+++ b/test/only/global/tdd.spec.js
@@ -1,5 +1,3 @@
-"use strict";
-
// Root-only test cases
test.only("#Root-Suite, should run this tdd test-case #1", function () {
expect(true, "to be", true);
diff --git a/test/reporters/base.spec.js b/test/reporters/base.spec.cjs
similarity index 99%
rename from test/reporters/base.spec.js
rename to test/reporters/base.spec.cjs
index d74e009e..f44b42a9 100644
--- a/test/reporters/base.spec.js
+++ b/test/reporters/base.spec.cjs
@@ -3,7 +3,7 @@
var assert = require("node:assert");
var chai = require("chai");
var sinon = require("sinon");
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var AssertionError = assert.AssertionError;
var Base = reporters.Base;
diff --git a/test/reporters/doc.spec.js b/test/reporters/doc.spec.cjs
similarity index 99%
rename from test/reporters/doc.spec.js
rename to test/reporters/doc.spec.cjs
index da543ebe..39fac9b5 100644
--- a/test/reporters/doc.spec.js
+++ b/test/reporters/doc.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Doc = reporters.Doc;
diff --git a/test/reporters/dot.spec.js b/test/reporters/dot.spec.cjs
similarity index 99%
rename from test/reporters/dot.spec.js
rename to test/reporters/dot.spec.cjs
index 4adef79d..30ce7cfd 100644
--- a/test/reporters/dot.spec.js
+++ b/test/reporters/dot.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Base = reporters.Base;
diff --git a/test/reporters/helpers.js b/test/reporters/helpers.cjs
similarity index 98%
rename from test/reporters/helpers.js
rename to test/reporters/helpers.cjs
index 4ae0df8b..761e0276 100644
--- a/test/reporters/helpers.js
+++ b/test/reporters/helpers.cjs
@@ -1,9 +1,9 @@
"use strict";
var sinon = require("sinon");
-var errors = require("../../lib/errors.mjs");
+var errors = require("../../lib/errors.js");
var createStatsCollector =
- require("../../lib/stats-collector.mjs").createStatsCollector;
+ require("../../lib/stats-collector.js").createStatsCollector;
var createUnsupportedError = errors.createUnsupportedError;
diff --git a/test/reporters/json-stream.spec.js b/test/reporters/json-stream.spec.cjs
similarity index 99%
rename from test/reporters/json-stream.spec.js
rename to test/reporters/json-stream.spec.cjs
index 059da3c3..5d571727 100644
--- a/test/reporters/json-stream.spec.js
+++ b/test/reporters/json-stream.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var JSONStream = reporters.JSONStream;
diff --git a/test/reporters/json.spec.mjs b/test/reporters/json.spec.js
similarity index 97%
rename from test/reporters/json.spec.mjs
rename to test/reporters/json.spec.js
index 097cef48..c0f729e6 100644
--- a/test/reporters/json.spec.mjs
+++ b/test/reporters/json.spec.js
@@ -1,8 +1,8 @@
import fs from "node:fs";
import sinon from "sinon";
-import { JSONReporter } from "../../lib/reporters/json.mjs";
-import utils from "../../lib/utils.js";
-import { Mocha, Suite, Runner, Test } from "../../index.mjs";
+import { JSONReporter } from "../../lib/reporters/json.js";
+import utils from "../../lib/utils.cjs";
+import { Mocha, Suite, Runner, Test } from "../../index.js";
describe("JSON reporter", function () {
var mocha;
diff --git a/test/reporters/landing.spec.js b/test/reporters/landing.spec.cjs
similarity index 98%
rename from test/reporters/landing.spec.js
rename to test/reporters/landing.spec.cjs
index c64fbf0a..44da877c 100644
--- a/test/reporters/landing.spec.js
+++ b/test/reporters/landing.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var states = require("../../").Runnable.constants;
diff --git a/test/reporters/list.spec.js b/test/reporters/list.spec.cjs
similarity index 99%
rename from test/reporters/list.spec.js
rename to test/reporters/list.spec.cjs
index 9c7b2684..92c5d22c 100644
--- a/test/reporters/list.spec.js
+++ b/test/reporters/list.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Base = reporters.Base;
diff --git a/test/reporters/markdown.spec.js b/test/reporters/markdown.spec.cjs
similarity index 98%
rename from test/reporters/markdown.spec.js
rename to test/reporters/markdown.spec.cjs
index e14a8474..19c618c0 100644
--- a/test/reporters/markdown.spec.js
+++ b/test/reporters/markdown.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Markdown = reporters.Markdown;
diff --git a/test/reporters/min.spec.js b/test/reporters/min.spec.cjs
similarity index 97%
rename from test/reporters/min.spec.js
rename to test/reporters/min.spec.cjs
index 74041e83..aaec2393 100644
--- a/test/reporters/min.spec.js
+++ b/test/reporters/min.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Min = reporters.Min;
diff --git a/test/reporters/nyan.spec.js b/test/reporters/nyan.spec.cjs
similarity index 99%
rename from test/reporters/nyan.spec.js
rename to test/reporters/nyan.spec.cjs
index 8be87748..7d8aaf66 100644
--- a/test/reporters/nyan.spec.js
+++ b/test/reporters/nyan.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Base = reporters.Base;
diff --git a/test/reporters/progress.spec.js b/test/reporters/progress.spec.cjs
similarity index 98%
rename from test/reporters/progress.spec.js
rename to test/reporters/progress.spec.cjs
index 3c953972..a3d8cb10 100644
--- a/test/reporters/progress.spec.js
+++ b/test/reporters/progress.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Base = reporters.Base;
diff --git a/test/reporters/spec.spec.js b/test/reporters/spec.spec.cjs
similarity index 99%
rename from test/reporters/spec.spec.js
rename to test/reporters/spec.spec.cjs
index e77dd3af..fabc286f 100644
--- a/test/reporters/spec.spec.js
+++ b/test/reporters/spec.spec.cjs
@@ -2,7 +2,7 @@
var sinon = require("sinon");
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var Base = reporters.Base;
diff --git a/test/reporters/tap.spec.js b/test/reporters/tap.spec.cjs
similarity index 99%
rename from test/reporters/tap.spec.js
rename to test/reporters/tap.spec.cjs
index 4fd4ccaa..3850739b 100644
--- a/test/reporters/tap.spec.js
+++ b/test/reporters/tap.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var events = require("../../").Runner.constants;
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var reporters = require("../../").reporters;
var TAP = reporters.TAP;
diff --git a/test/reporters/xunit.spec.js b/test/reporters/xunit.spec.cjs
similarity index 99%
rename from test/reporters/xunit.spec.js
rename to test/reporters/xunit.spec.cjs
index 7052075d..2a255b7a 100644
--- a/test/reporters/xunit.spec.js
+++ b/test/reporters/xunit.spec.cjs
@@ -5,14 +5,14 @@ var fs = require("fs");
var path = require("path");
var sinon = require("sinon");
var createStatsCollector =
- require("../../lib/stats-collector.mjs").createStatsCollector;
+ require("../../lib/stats-collector.js").createStatsCollector;
var events = require("../../").Runner.constants;
var reporters = require("../../").reporters;
var states = require("../../").Runnable.constants;
-const { createTempDir, touchFile } = require("../integration/helpers");
+const { createTempDir, touchFile } = require("../integration/helpers.cjs");
-var helpers = require("./helpers");
+var helpers = require("./helpers.cjs");
var createMockRunner = helpers.createMockRunner;
var makeRunReporter = helpers.createRunReporterFunction;
@@ -97,7 +97,7 @@ describe("XUnit reporter", function () {
let tmpdir;
/**
- * @type {import('../integration/helpers').RemoveTempDirCallback}
+ * @type {import('../integration/helpers.cjs').RemoveTempDirCallback}
*/
let cleanup;
var invalidPath;
diff --git a/test/require/c.js b/test/require/a.cjs
similarity index 64%
rename from test/require/c.js
rename to test/require/a.cjs
index b40624aa..594cb2ac 100644
--- a/test/require/c.js
+++ b/test/require/a.cjs
@@ -1,4 +1,4 @@
"use strict";
global.required = global.required || [];
-global.required.push("c.js");
+global.required.push("a.cjs");
diff --git a/test/require/a.js b/test/require/c.cjs
similarity index 64%
rename from test/require/a.js
rename to test/require/c.cjs
index 684bbf83..2616a0a0 100644
--- a/test/require/a.js
+++ b/test/require/c.cjs
@@ -1,4 +1,4 @@
"use strict";
global.required = global.required || [];
-global.required.push("a.js");
+global.required.push("c.cjs");
diff --git a/test/require/require.spec.js b/test/require/require.spec.cjs
similarity index 72%
rename from test/require/require.spec.js
rename to test/require/require.spec.cjs
index 5e000f00..eb238ac6 100644
--- a/test/require/require.spec.js
+++ b/test/require/require.spec.cjs
@@ -3,9 +3,9 @@
describe("require test", function () {
it("should require args in order", function () {
var req = global.required;
- expect(req.indexOf("a.js"), "to be", 0);
+ expect(req.indexOf("a.cjs"), "to be", 0);
expect(req.indexOf("b.coffee"), "to be", 1);
- expect(req.indexOf("c.js"), "to be", 2);
+ expect(req.indexOf("c.cjs"), "to be", 2);
expect(req.indexOf("d.coffee"), "to be", 3);
});
});
diff --git a/test/setup.js b/test/setup.cjs
similarity index 86%
rename from test/setup.js
rename to test/setup.cjs
index 0e3bc04a..c5f317f1 100644
--- a/test/setup.js
+++ b/test/setup.cjs
@@ -8,4 +8,4 @@ global.expect = unexpected
.use(require("unexpected-eventemitter"))
.use(require("unexpected-map"))
.use(require("unexpected-set"))
- .use(require("./assertions"));
+ .use(require("./assertions.cjs"));
diff --git a/test/smoke/smoke.spec.js b/test/smoke/smoke.spec.cjs
similarity index 100%
rename from test/smoke/smoke.spec.js
rename to test/smoke/smoke.spec.cjs
diff --git a/test/unit/context.spec.js b/test/unit/context.spec.cjs
similarity index 100%
rename from test/unit/context.spec.js
rename to test/unit/context.spec.cjs
diff --git a/test/unit/duration.spec.js b/test/unit/duration.spec.cjs
similarity index 100%
rename from test/unit/duration.spec.js
rename to test/unit/duration.spec.cjs
diff --git a/test/unit/errors.spec.js b/test/unit/errors.spec.cjs
similarity index 96%
rename from test/unit/errors.spec.js
rename to test/unit/errors.spec.cjs
index cabfb987..45d865d6 100644
--- a/test/unit/errors.spec.js
+++ b/test/unit/errors.spec.cjs
@@ -1,9 +1,9 @@
"use strict";
-var errors = require("../../lib/errors.mjs");
-var constants = require("../../lib/error-constants.mjs");
+var errors = require("../../lib/errors.js");
+var constants = require("../../lib/error-constants.js");
const sinon = require("sinon");
-const { createNoFilesMatchPatternError } = require("../../lib/errors.mjs");
+const { createNoFilesMatchPatternError } = require("../../lib/errors.js");
describe("Errors", function () {
afterEach(function () {
diff --git a/test/unit/globals.spec.js b/test/unit/globals.spec.cjs
similarity index 100%
rename from test/unit/globals.spec.js
rename to test/unit/globals.spec.cjs
diff --git a/test/unit/grep.spec.js b/test/unit/grep.spec.cjs
similarity index 97%
rename from test/unit/grep.spec.js
rename to test/unit/grep.spec.cjs
index 55fdd4f2..7c595d37 100644
--- a/test/unit/grep.spec.js
+++ b/test/unit/grep.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var { expect } = require("chai");
-var Mocha = require("../../lib/mocha");
+var Mocha = require("../../lib/mocha.cjs");
describe("Mocha", function () {
describe('"grep" option', function () {
diff --git a/test/unit/hook-async.spec.js b/test/unit/hook-async.spec.cjs
similarity index 100%
rename from test/unit/hook-async.spec.js
rename to test/unit/hook-async.spec.cjs
diff --git a/test/unit/hook-sync-nested.spec.js b/test/unit/hook-sync-nested.spec.cjs
similarity index 100%
rename from test/unit/hook-sync-nested.spec.js
rename to test/unit/hook-sync-nested.spec.cjs
diff --git a/test/unit/hook-sync.spec.js b/test/unit/hook-sync.spec.cjs
similarity index 100%
rename from test/unit/hook-sync.spec.js
rename to test/unit/hook-sync.spec.cjs
diff --git a/test/unit/hook-timeout.spec.js b/test/unit/hook-timeout.spec.cjs
similarity index 100%
rename from test/unit/hook-timeout.spec.js
rename to test/unit/hook-timeout.spec.cjs
diff --git a/test/unit/hook.spec.js b/test/unit/hook.spec.cjs
similarity index 96%
rename from test/unit/hook.spec.js
rename to test/unit/hook.spec.cjs
index 9326cbc7..2552bd95 100644
--- a/test/unit/hook.spec.js
+++ b/test/unit/hook.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
var sinon = require("sinon");
-var Mocha = require("../../lib/mocha");
+var Mocha = require("../../lib/mocha.cjs");
var Hook = Mocha.Hook;
var Runnable = Mocha.Runnable;
diff --git a/test/unit/mocha.spec.js b/test/unit/mocha.spec.cjs
similarity index 99%
rename from test/unit/mocha.spec.js
rename to test/unit/mocha.spec.cjs
index a2efc505..b27f6bec 100644
--- a/test/unit/mocha.spec.js
+++ b/test/unit/mocha.spec.cjs
@@ -2,8 +2,8 @@
var sinon = require("sinon");
var EventEmitter = require("node:events").EventEmitter;
-var Mocha = require("../../lib/mocha");
-var utils = require("../../lib/utils");
+var Mocha = require("../../lib/mocha.cjs");
+var utils = require("../../lib/utils.cjs");
describe("Mocha", function () {
/**
diff --git a/test/unit/overspecified-async.spec.js b/test/unit/overspecified-async.spec.cjs
similarity index 100%
rename from test/unit/overspecified-async.spec.js
rename to test/unit/overspecified-async.spec.cjs
diff --git a/test/unit/parse-query.spec.js b/test/unit/parse-query.spec.cjs
similarity index 89%
rename from test/unit/parse-query.spec.js
rename to test/unit/parse-query.spec.cjs
index 0c7cdd02..6eb7ce4a 100644
--- a/test/unit/parse-query.spec.js
+++ b/test/unit/parse-query.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var { expect } = require("chai");
-var { parseQuery } = require("../../lib/browser/parse-query.mjs");
+var { parseQuery } = require("../../lib/browser/parse-query.js");
describe("parseQuery()", function () {
it("should get queryString and return key-value object", function () {
diff --git a/test/unit/plugin-loader.spec.js b/test/unit/plugin-loader.spec.cjs
similarity index 99%
rename from test/unit/plugin-loader.spec.js
rename to test/unit/plugin-loader.spec.cjs
index 034b4a94..444c9989 100644
--- a/test/unit/plugin-loader.spec.js
+++ b/test/unit/plugin-loader.spec.cjs
@@ -1,9 +1,9 @@
"use strict";
-const { PluginLoader } = require("../../lib/plugin-loader.mjs");
+const { PluginLoader } = require("../../lib/plugin-loader.js");
const sinon = require("sinon");
const { INVALID_PLUGIN_DEFINITION, INVALID_PLUGIN_IMPLEMENTATION } =
- require("../../lib/error-constants.mjs").constants;
+ require("../../lib/error-constants.js").constants;
describe("plugin module", function () {
describe("class PluginLoader", function () {
diff --git a/test/unit/reporters/base-diff-protection.spec.js b/test/unit/reporters/base-diff-protection.spec.cjs
similarity index 100%
rename from test/unit/reporters/base-diff-protection.spec.js
rename to test/unit/reporters/base-diff-protection.spec.cjs
diff --git a/test/unit/required-tokens.spec.js b/test/unit/required-tokens.spec.cjs
similarity index 100%
rename from test/unit/required-tokens.spec.js
rename to test/unit/required-tokens.spec.cjs
diff --git a/test/unit/root.spec.js b/test/unit/root.spec.cjs
similarity index 100%
rename from test/unit/root.spec.js
rename to test/unit/root.spec.cjs
diff --git a/test/unit/runnable.spec.js b/test/unit/runnable.spec.cjs
similarity index 99%
rename from test/unit/runnable.spec.js
rename to test/unit/runnable.spec.cjs
index e4697c92..d4b34a00 100644
--- a/test/unit/runnable.spec.js
+++ b/test/unit/runnable.spec.cjs
@@ -1,10 +1,10 @@
"use strict";
-var Mocha = require("../../lib/mocha");
+var Mocha = require("../../lib/mocha.cjs");
var Runnable = Mocha.Runnable;
var Suite = Mocha.Suite;
var sinon = require("sinon");
-const { TIMEOUT } = require("../../lib/error-constants.mjs").constants;
+const { TIMEOUT } = require("../../lib/error-constants.js").constants;
var STATE_FAILED = Runnable.constants.STATE_FAILED;
describe("Runnable(title, fn)", function () {
diff --git a/test/unit/runner.spec.js b/test/unit/runner.spec.cjs
similarity index 98%
rename from test/unit/runner.spec.js
rename to test/unit/runner.spec.cjs
index eede3039..2edf99bb 100644
--- a/test/unit/runner.spec.js
+++ b/test/unit/runner.spec.cjs
@@ -2,12 +2,12 @@
const path = require("node:path");
const sinon = require("sinon");
-const Mocha = require("../../lib/mocha");
-const { PendingError } = require("../../lib/pending.mjs");
+const Mocha = require("../../lib/mocha.cjs");
+const { PendingError } = require("../../lib/pending.js");
const { Suite, Runner, Test, Hook, Runnable } = Mocha;
const { noop } = Mocha.utils;
const { FATAL, MULTIPLE_DONE, UNSUPPORTED } =
- require("../../lib/error-constants.mjs").constants;
+ require("../../lib/error-constants.js").constants;
const {
EVENT_HOOK_BEGIN,
@@ -577,12 +577,12 @@ describe("Runner", function () {
"at EventEmitter.<anonymous> (/usr/local/dev/test.js:16:12)",
"at Context.<anonymous> (/usr/local/dev/test.js:19:5)",
"Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:244:7)",
- "Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:374:10)",
- "/usr/local/lib/node_modules/mocha/lib/runner.js:452:12",
- "next (/usr/local/lib/node_modules/mocha/lib/runner.js:299:14)",
- "/usr/local/lib/node_modules/mocha/lib/runner.js:309:7",
- "next (/usr/local/lib/node_modules/mocha/lib/runner.js:248:23)",
- "Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:276:5)",
+ "Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.cjs:374:10)",
+ "/usr/local/lib/node_modules/mocha/lib/runner.cjs:452:12",
+ "next (/usr/local/lib/node_modules/mocha/lib/runner.cjs:299:14)",
+ "/usr/local/lib/node_modules/mocha/lib/runner.cjs:309:7",
+ "next (/usr/local/lib/node_modules/mocha/lib/runner.cjs:248:23)",
+ "Immediate._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.cjs:276:5)",
"at processImmediate [as _immediateCallback] (timers.js:321:17)",
];
diff --git a/test/unit/suite.spec.js b/test/unit/suite.spec.cjs
similarity index 99%
rename from test/unit/suite.spec.js
rename to test/unit/suite.spec.cjs
index daa4ae15..cb55d587 100644
--- a/test/unit/suite.spec.js
+++ b/test/unit/suite.spec.cjs
@@ -1,6 +1,6 @@
"use strict";
-const Mocha = require("../../lib/mocha");
+const Mocha = require("../../lib/mocha.cjs");
const { Suite, Test, Context } = Mocha;
const sinon = require("sinon");
diff --git a/test/unit/test.spec.js b/test/unit/test.spec.cjs
similarity index 98%
rename from test/unit/test.spec.js
rename to test/unit/test.spec.cjs
index c6a67708..d59095b3 100644
--- a/test/unit/test.spec.js
+++ b/test/unit/test.spec.cjs
@@ -1,7 +1,7 @@
"use strict";
var sinon = require("sinon");
-var mocha = require("../../lib/mocha");
+var mocha = require("../../lib/mocha.cjs");
var Test = mocha.Test;
var Runnable = mocha.Runnable;
diff --git a/test/unit/throw.spec.js b/test/unit/throw.spec.cjs
similarity index 99%
rename from test/unit/throw.spec.js
rename to test/unit/throw.spec.cjs
index 429f7337..a7088b07 100644
--- a/test/unit/throw.spec.js
+++ b/test/unit/throw.spec.cjs
@@ -3,7 +3,7 @@
/* eslint no-throw-literal: off */
var sinon = require("sinon");
-var Mocha = require("../../lib/mocha");
+var Mocha = require("../../lib/mocha.cjs");
var Suite = Mocha.Suite;
var Test = Mocha.Test;
var Runnable = Mocha.Runnable;
diff --git a/test/unit/timeout.spec.js b/test/unit/timeout.spec.cjs
similarity index 100%
rename from test/unit/timeout.spec.js
rename to test/unit/timeout.spec.cjs
diff --git a/test/unit/utils.spec.js b/test/unit/utils.spec.cjs
similarity index 99%
rename from test/unit/utils.spec.js
rename to test/unit/utils.spec.cjs
index cbe3b262..53e1ef10 100644
--- a/test/unit/utils.spec.js
+++ b/test/unit/utils.spec.cjs
@@ -1,7 +1,7 @@
/* global BigInt */
"use strict";
-var utils = require("../../lib/utils");
+var utils = require("../../lib/utils.cjs");
var sinon = require("sinon");
describe("lib/utils", function () {