Skip to content

armgit / mocha

Public Imported from GitHub
0

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

feat!: remove `bin/_mocha` and convert `bin/` and entry points to ESM (#6017)

Josh Goldberg ✨930972a9a705
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index fbc6ef6d..3daa7b8f 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -88,7 +88,7 @@ Then:
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)
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.js`.
+ - Your changes will likely be somewhere in `lib/`, `bin/`, or (if your changes are browser-specific) `browser-entry.mjs`.
- 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 10993214..a6408e3f 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 --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.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?
label: Versions
type: textarea
validations:
diff --git a/.gitignore b/.gitignore
index fe41aea0..f65edbea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,7 +3,7 @@ docs/images/supporters
mocha.js
mocha.js.map
.karma/
-!bin/mocha.js
+!bin/mocha.mjs
!lib/mocha.js
# Bundle debugging
diff --git a/.knip.jsonc b/.knip.jsonc
index d3521d2c..01baefbc 100644
--- a/.knip.jsonc
+++ b/.knip.jsonc
@@ -1,11 +1,6 @@
{
"$schema": "https://unpkg.com/knip@6/schema-jsonc.json",
- "entry": [
- "bin/_mocha!",
- "docs/_data/supporters.cjs",
- "index.js!",
- "lib/cli/index.js!",
- ],
+ "entry": ["docs/_data/supporters.cjs", "index.mjs!", "lib/cli/index.js!"],
"project": ["{bin,lib,scripts,test}/**/*.{js,ts,mjs,cjs}"],
"ignore": [
"test/integration/fixtures/esm/type-module/test-that-imports-non-existing-module.fixture.js",
diff --git a/AGENTS.md b/AGENTS.md
index 6dc9703c..46aa3438 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -28,7 +28,7 @@ Agent onboarding for the `mochajs/mocha` repository.
## Repository map (quick)
- `lib/` — core runtime (runner, suite, hooks, reporters, CLI internals)
-- `bin/` — CLI entrypoints (`mocha`, `_mocha`)
+- `bin/` — CLI entrypoints (`mocha`)
- `test/` — unit, integration, node-only, browser-specific, smoke
- `docs/` — Astro/Starlight docs app with separate lockfile/scripts
- `mocha.js` / `mocha.js.map` — browser bundle outputs (generated)
diff --git a/bin/_mocha b/bin/_mocha
deleted file mode 100755
index 9572d94c..00000000
--- a/bin/_mocha
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/usr/bin/env node
-"use strict";
-
-/**
- * This file remains for backwards compatibility only.
- * Don't put stuff in this file.
- * @see module:lib/cli
- */
-
-require("../lib/cli").main();
diff --git a/bin/mocha.js b/bin/mocha.mjs
similarity index 88%
rename from bin/mocha.js
rename to bin/mocha.mjs
index f0e486b1..a21e989e 100755
--- a/bin/mocha.js
+++ b/bin/mocha.mjs
@@ -1,7 +1,5 @@
#!/usr/bin/env node
-"use strict";
-
/**
* This wrapper executable checks for known node flags and appends them when found,
* before invoking the "real" executable (`lib/cli/cli.mjs`)
@@ -10,16 +8,22 @@
* @private
*/
-const os = require("node:os");
-const { loadOptions } = require("../lib/cli/options.mjs");
-const {
+import d from "debug";
+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 {
unparseNodeFlags,
isNodeFlag,
impliesNoTimeouts,
-} = require("../lib/cli/node-flags.mjs");
-const unparse = require("yargs-unparser");
-const debug = require("debug")("mocha:cli:mocha");
-const { aliases } = require("../lib/cli/run-option-metadata.mjs");
+} from "../lib/cli/node-flags.mjs";
+import { aliases } from "../lib/cli/run-option-metadata.mjs";
+import { fileURLToPath } from "node:url";
+
+const debug = d.debug("mocha:cli:mocha");
const mochaArgs = {};
const nodeArgs = {};
@@ -80,8 +84,7 @@ if (mochaArgs._) {
}
if (mochaArgs["node-option"] || Object.keys(nodeArgs).length || hasInspect) {
- const { spawn } = require("node:child_process");
- const mochaPath = require.resolve("../lib/cli/cli.mjs");
+ const mochaPath = fileURLToPath(import.meta.resolve("../lib/cli/cli.mjs"));
const nodeArgv =
(mochaArgs["node-option"] &&
@@ -146,5 +149,5 @@ if (mochaArgs["node-option"] || Object.keys(nodeArgs).length || hasInspect) {
});
} else {
debug("running Mocha in-process");
- require("../lib/cli/cli.mjs").main([], mochaArgs);
+ main([], mochaArgs);
}
diff --git a/browser-entry.js b/browser-entry.mjs
similarity index 91%
rename from browser-entry.js
rename to browser-entry.mjs
index dc2a4576..92628f34 100644
--- a/browser-entry.js
+++ b/browser-entry.mjs
@@ -1,16 +1,13 @@
-"use strict";
+import BrowserStdout from "browser-stdout";
-/* eslint no-unused-vars: off */
+import { parseQuery } from "./lib/browser/parse-query.mjs";
+import { highlightTags } from "./lib/browser/highlight-tags.mjs";
+import Mocha from "./lib/mocha.js";
/**
* Shim process.stdout.
*/
-
-process.stdout = require("browser-stdout")({ label: false });
-
-var parseQuery = require("./lib/browser/parse-query.mjs").parseQuery;
-var highlightTags = require("./lib/browser/highlight-tags.mjs").highlightTags;
-var Mocha = require("./lib/mocha");
+process.stdout = BrowserStdout({ label: false });
/**
* Create a Mocha instance.
@@ -26,9 +23,6 @@ var mocha = new Mocha({ reporter: "html" });
var Date = global.Date;
var setTimeout = global.setTimeout;
-var setInterval = global.setInterval;
-var clearTimeout = global.clearTimeout;
-var clearInterval = global.clearInterval;
var uncaughtExceptionHandlers = [];
@@ -214,7 +208,7 @@ global.mocha = mocha;
// for bundlers: enable `import {describe, it} from 'mocha'`
// `bdd` interface only
// prettier-ignore
-[
+[
'describe', 'context', 'it', 'specify',
'xdescribe', 'xcontext', 'xit', 'xspecify',
'before', 'beforeEach', 'afterEach', 'after'
@@ -222,4 +216,4 @@ global.mocha = mocha;
mocha[key] = global[key];
});
-module.exports = mocha;
+export default mocha;
diff --git a/docs/package-lock.json b/docs/package-lock.json
index ed8e0237..7c00cf56 100644
--- a/docs/package-lock.json
+++ b/docs/package-lock.json
@@ -1536,9 +1536,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1556,9 +1553,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1576,9 +1570,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1596,9 +1587,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1616,9 +1604,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1636,9 +1621,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1656,9 +1638,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1676,9 +1655,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
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 55571d9d..144091e7 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 mocha.test.js
+$ ./node_modules/.bin/mocha.mjs mocha.test.js
✓ double done
diff --git a/eslint.config.js b/eslint.config.js
index 0942d7c9..0335b4d8 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -30,6 +30,17 @@ module.exports = defineConfig(
"n/no-unsupported-features/node-builtins": "off",
strict: ["error", "global"],
},
+ settings: {
+ "import/extensions": [".js", ".mjs"],
+ "import/resolver": {
+ node: {
+ extensions: [".js", ".mjs"],
+ },
+ },
+ node: {
+ tryExtensions: [".js", ".json", ".node", ".mjs"],
+ },
+ },
},
{
files: [
diff --git a/index.js b/index.js
deleted file mode 100644
index 6c972d99..00000000
--- a/index.js
+++ /dev/null
@@ -1,3 +0,0 @@
-"use strict";
-
-module.exports = require("./lib/mocha");
diff --git a/index.mjs b/index.mjs
new file mode 100644
index 00000000..9a71216f
--- /dev/null
+++ b/index.mjs
@@ -0,0 +1,2 @@
+export { default } from "./lib/mocha.js";
+export * from "./lib/mocha.js";
diff --git a/lib/mocha.js b/lib/mocha.js
index 3917eb0a..a90f0d86 100644
--- a/lib/mocha.js
+++ b/lib/mocha.js
@@ -34,8 +34,12 @@ var debug = require("debug")("mocha:mocha");
* @typedef {import('./types.d.ts').Reporter} Reporter
*/
+// Legacy CJS-style require() export, as well as default in ESM
exports = module.exports = Mocha;
+// Modern property-based / ESM named export
+module.exports.Mocha = Mocha;
+
/**
* A Mocha instance is a finite state machine.
* These are the states it can be in.
diff --git a/package-lock.json b/package-lock.json
index db58824c..8796d3f3 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -31,8 +31,7 @@
"yargs-unparser": "^2.0.0"
},
"bin": {
- "_mocha": "bin/_mocha",
- "mocha": "bin/mocha.js"
+ "mocha": "bin/mocha.mjs"
},
"devDependencies": {
"@eslint/js": "^10.0.0",
@@ -1135,9 +1134,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1155,9 +1151,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1175,9 +1168,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1195,9 +1185,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1215,9 +1202,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1235,9 +1219,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1255,9 +1236,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -1275,9 +1253,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2038,9 +2013,6 @@
"arm"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2055,9 +2027,6 @@
"arm"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2072,9 +2041,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2089,9 +2055,6 @@
"arm64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2106,9 +2069,6 @@
"loong64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2123,9 +2083,6 @@
"loong64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2140,9 +2097,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2157,9 +2111,6 @@
"ppc64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2174,9 +2125,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2191,9 +2139,6 @@
"riscv64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2208,9 +2153,6 @@
"s390x"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2225,9 +2167,6 @@
"x64"
],
"dev": true,
- "libc": [
- "glibc"
- ],
"license": "MIT",
"optional": true,
"os": [
@@ -2242,9 +2181,6 @@
"x64"
],
"dev": true,
- "libc": [
- "musl"
- ],
"license": "MIT",
"optional": true,
"os": [
diff --git a/package.json b/package.json
index 6a4ec450..01bc4a32 100644
--- a/package.json
+++ b/package.json
@@ -32,8 +32,7 @@
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
"notifyLogo": "https://ibin.co/4QuRuGjXvl36.png",
"bin": {
- "mocha": "./bin/mocha.js",
- "_mocha": "./bin/_mocha"
+ "mocha": "./bin/mocha.mjs"
},
"directories": {
"lib": "./lib",
@@ -65,8 +64,8 @@
"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.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-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:interfaces:bdd": "npm run -s test-node-run -- --ui bdd test/interfaces/bdd.spec",
@@ -74,17 +73,17 @@
"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.js",
+ "test-node:jsapi": "node test/jsapi/index.mjs",
"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\"",
+ "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": "run-s test-coverage-clean test-node:* test-coverage-generate",
- "test-smoke": "node ./bin/mocha --no-config test/smoke/smoke.spec.js",
+ "test-smoke": "node ./bin/mocha.mjs --no-config test/smoke/smoke.spec.js",
"test": "run-s lint test-node test-browser",
"tsc": "tsc",
"version:linkify-changelog": "node scripts/linkify-changelog.mjs",
@@ -161,16 +160,19 @@
},
"files": [
"bin/*mocha*",
- "lib/**/*.{js,mjs,html,json}",
- "index.js",
+ "lib/**/*.html",
+ "lib/**/*.js",
+ "lib/**/*.json",
+ "lib/**/*.mjs",
+ "index.mjs",
"mocha.css",
"mocha.js",
"mocha.js.map",
"mocha.mjs",
- "browser-entry.js"
+ "browser-entry.mjs"
],
"browser": {
- "./index.js": "./browser-entry.js",
+ "./index.mjs": "./browser-entry.mjs",
"fs": false,
"path": false,
"supports-color": false,
diff --git a/rollup.config.mjs b/rollup.config.mjs
index 9b574d08..965a6d9e 100644
--- a/rollup.config.mjs
+++ b/rollup.config.mjs
@@ -11,7 +11,7 @@ import pickFromPackageJson from "./scripts/pick-from-package-json.mjs";
import packageJson from "./package.json" with { type: "json" };
const config = {
- input: "./browser-entry.js",
+ input: "./browser-entry.mjs",
strictDeprecations: true,
output: {
file: "./mocha.js",
diff --git a/test/integration/fixtures/parallel/circular-error-array.mjs b/test/integration/fixtures/parallel/circular-error-array.mjs
index 5e3787b8..1695c7ff 100644
--- a/test/integration/fixtures/parallel/circular-error-array.mjs
+++ b/test/integration/fixtures/parallel/circular-error-array.mjs
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.js";
+import {describe,it} from "../../../../index.mjs";
describe('test1', () => {
it('test', () => {
diff --git a/test/integration/fixtures/parallel/circular-error-object.mjs b/test/integration/fixtures/parallel/circular-error-object.mjs
index 45ba68a2..34c5d1c3 100644
--- a/test/integration/fixtures/parallel/circular-error-object.mjs
+++ b/test/integration/fixtures/parallel/circular-error-object.mjs
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.js";
+import {describe,it} from "../../../../index.mjs";
describe('test1', () => {
it('test', () => {
diff --git a/test/integration/fixtures/parallel/getter-error-object.mjs b/test/integration/fixtures/parallel/getter-error-object.mjs
index 477427e6..086d469d 100644
--- a/test/integration/fixtures/parallel/getter-error-object.mjs
+++ b/test/integration/fixtures/parallel/getter-error-object.mjs
@@ -1,4 +1,4 @@
-import {describe, it} from '../../../../index.js';
+import {describe, it} from '../../../../index.mjs';
describe('test1', () => {
it('test', async () => {
diff --git a/test/integration/fixtures/parallel/non-circular-error.mjs b/test/integration/fixtures/parallel/non-circular-error.mjs
index 251a58b0..f76d51e2 100644
--- a/test/integration/fixtures/parallel/non-circular-error.mjs
+++ b/test/integration/fixtures/parallel/non-circular-error.mjs
@@ -1,4 +1,4 @@
-import {it} from '../../../../index.js';
+import {it} from '../../../../index.mjs';
it('test', () => {
throw new Error('Foo');
diff --git a/test/integration/fixtures/parallel/test1.mjs b/test/integration/fixtures/parallel/test1.mjs
index 5be1220a..c153f097 100644
--- a/test/integration/fixtures/parallel/test1.mjs
+++ b/test/integration/fixtures/parallel/test1.mjs
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.js";
+import {describe,it} from "../../../../index.mjs";
describe('test1', () => {
it('should pass', () => {});
diff --git a/test/integration/fixtures/parallel/test2.mjs b/test/integration/fixtures/parallel/test2.mjs
index abd1f97a..5d566d3a 100644
--- a/test/integration/fixtures/parallel/test2.mjs
+++ b/test/integration/fixtures/parallel/test2.mjs
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.js";
+import {describe,it} from "../../../../index.mjs";
describe('test2', () => {
it('should pass', () => {});
diff --git a/test/integration/fixtures/parallel/test3.mjs b/test/integration/fixtures/parallel/test3.mjs
index 5210bd9b..a290cfce 100644
--- a/test/integration/fixtures/parallel/test3.mjs
+++ b/test/integration/fixtures/parallel/test3.mjs
@@ -1,4 +1,4 @@
-import {describe,it} from "../../../../index.js";
+import {describe,it} from "../../../../index.mjs";
describe('test3', () => {
it('should fail', () => {
diff --git a/test/integration/helpers.js b/test/integration/helpers.js
index cbbea0e4..fa06b2a4 100644
--- a/test/integration/helpers.js
+++ b/test/integration/helpers.js
@@ -13,7 +13,7 @@ const SIGNAL_OFFSET = 128;
/**
* Path to `mocha` executable
*/
-const MOCHA_EXECUTABLE = require.resolve("../../bin/mocha");
+const MOCHA_EXECUTABLE = require.resolve("../../bin/mocha.mjs");
/**
* regular expression used for splitting lines based on new line / dot symbol.
diff --git a/test/jsapi/index.js b/test/jsapi/index.mjs
similarity index 89%
rename from test/jsapi/index.js
rename to test/jsapi/index.mjs
index 38193eba..df4f4266 100644
--- a/test/jsapi/index.js
+++ b/test/jsapi/index.mjs
@@ -1,6 +1,4 @@
-"use strict";
-
-var Mocha = require("../../");
+import Mocha from "../../index.mjs";
var mocha = new Mocha({
ui: "bdd",
@@ -8,7 +6,7 @@ var mocha = new Mocha({
growl: true,
});
-require("../setup");
+import "../setup.js";
mocha.addFile("test/unit/suite.spec.js");
mocha.addFile("test/unit/runner.spec.js");
diff --git a/test/reporters/json.spec.js b/test/reporters/json.spec.mjs
similarity index 95%
rename from test/reporters/json.spec.js
rename to test/reporters/json.spec.mjs
index ca2a413e..097cef48 100644
--- a/test/reporters/json.spec.js
+++ b/test/reporters/json.spec.mjs
@@ -1,13 +1,8 @@
-"use strict";
-
-var fs = require("node:fs");
-var sinon = require("sinon");
-var JSONReporter = require("../../lib/reporters/json.mjs").JSONReporter;
-var utils = require("../../lib/utils");
-var Mocha = require("../../");
-var Suite = Mocha.Suite;
-var Runner = Mocha.Runner;
-var Test = Mocha.Test;
+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";
describe("JSON reporter", function () {
var mocha;