Skip to content

armgit / mocha

Public Imported from GitHub
0

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

feat: add mocha.mjs export (#5527)

Brett Zamire1cf23cbc204
diff --git a/eslint.config.js b/eslint.config.js
index 5733194a..68c6ddf0 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -89,7 +89,7 @@ module.exports = [
},
},
{
- files: ["test/**/*.mjs"],
+ files: ["**/*.mjs"],
languageOptions: {
sourceType: "module",
},
diff --git a/mocha.mjs b/mocha.mjs
new file mode 100644
index 00000000..430d2ee2
--- /dev/null
+++ b/mocha.mjs
@@ -0,0 +1,68 @@
+// this built file is not committed to the repo
+/* eslint-disable-next-line n/no-missing-import */
+import "./mocha.js";
+
+const {mocha, Mocha} = globalThis;
+
+const mochaExports = {
+ after: (...args) => globalThis.after?.(...args),
+ afterEach: (...args) => globalThis.afterEach?.(...args),
+ before: (...args) => globalThis.before?.(...args),
+ beforeEach: (...args) => globalThis.beforeEach?.(...args),
+ context: (...args) => globalThis.context?.(...args),
+ describe: (...args) => globalThis.describe?.(...args),
+ it: (...args) => globalThis.it?.(...args),
+ run: mocha.run.bind(mocha),
+ setup: (...args) => mocha.setup?.(...args),
+ suite: (...args) => globalThis.suite?.(...args),
+ suiteSetup: (...args) => globalThis.suiteSetup?.(...args),
+ suiteTeardown: (...args) => globalThis.suiteTeardown?.(...args),
+ teardown: (...args) => globalThis.teardown?.(...args),
+ test: (...args) => globalThis.test?.(...args),
+ specify: (...args) => globalThis.specify?.(...args),
+ xcontext: (...args) => globalThis.xcontext?.(...args),
+ xdescribe: (...args) => globalThis.xdescribe?.(...args),
+ xit: (...args) => globalThis.xit?.(...args),
+ xspecify: (...args) => globalThis.xspecify?.(...args),
+};
+
+export default Mocha;
+
+// Export the mocha instance (in browser, this has setup/run methods)
+export { mocha };
+
+// Re-export class/utility exports from the Mocha module
+export const {
+ utils,
+ interfaces,
+ reporters,
+ Runnable,
+ Context,
+ Runner,
+ Suite,
+ Hook,
+ Test,
+} = Mocha;
+
+// Re-export test interface functions
+export const {
+ after,
+ afterEach,
+ before,
+ beforeEach,
+ context,
+ describe,
+ it,
+ run,
+ setup,
+ suite,
+ suiteSetup,
+ suiteTeardown,
+ teardown,
+ test,
+ specify,
+ xcontext,
+ xdescribe,
+ xit,
+ xspecify,
+} = mochaExports;
diff --git a/package.json b/package.json
index 68f4b92a..85ac274c 100644
--- a/package.json
+++ b/package.json
@@ -189,6 +189,7 @@
"mocha.css",
"mocha.js",
"mocha.js.map",
+ "mocha.mjs",
"browser-entry.js"
],
"browser": {