Skip to content

armgit / mocha

Public Imported from GitHub
0

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

docs: fix minor correctness issues (#6215)

Mostafa Nazarie6b9ee773481
diff --git a/docs/src/content/docs/explainers/compilers-deprecation.mdx b/docs/src/content/docs/explainers/compilers-deprecation.mdx
index b9157d8f..ed6a49c9 100644
--- a/docs/src/content/docs/explainers/compilers-deprecation.mdx
+++ b/docs/src/content/docs/explainers/compilers-deprecation.mdx
@@ -1,17 +1,9 @@
---
-description: Compilers deprecation notice.
+description: Moving off the removed `--compilers` option.
title: Compilers deprecation
---
-If you're here, you probably hit the deprecation notice. Sorry about that!
-
-## Will it break?
-
-This is a _soft_ deprecation, which means you get nagged about it, but it won't break (yet).
-
-## Make it go away
-
-To suppress this warning, execute `mocha` with the `--no-deprecation` flag (though you won't get notice of any _other_ deprecations you may encounter either).
+`--compilers` was deprecated in v4.0.0 and removed in v6.0.0. As of v12.0.0, Mocha treats it as normal text, not as an option.
## ... but why?
@@ -40,7 +32,7 @@ You'll have to handle file extensions as well. Mocha, by default, only loads `.j
$ mocha --compilers coffee:coffee-script/register --recursive ./test
```
-Then this is how you'd accomplish the same thing (`**` roughly means "recursive") in v4:
+Then this is how you'd accomplish the same thing (`**` roughly means "recursive") in v4 and later:
```bash
$ mocha --require coffeescript/register "test/**/*.js"
@@ -59,6 +51,6 @@ $ mocha --require coffeescript/register "test/**/*.{js,coffee}"
When using `--watch`, you will also need to specify the extension(s) to watch via `--watch-extensions`, e.g.:
-```js
+```bash
$ mocha --require coffeescript/register --watch --watch-extensions js,coffee "test/**/*.{js,coffee}"
```
diff --git a/docs/src/content/docs/explainers/environment-variables.mdx b/docs/src/content/docs/explainers/environment-variables.mdx
index e9218ec7..ee3b58d4 100644
--- a/docs/src/content/docs/explainers/environment-variables.mdx
+++ b/docs/src/content/docs/explainers/environment-variables.mdx
@@ -23,7 +23,9 @@ env CI=STAGE mocha
Then in your test or code reference it via `process.env.CI`. e.g.
```javascript
-if (process.env.CI === "STAGE") // do something
+if (process.env.CI === "STAGE") {
+ // do something
+}
```
The value is available from anywhere in a spec file allowing you to set values from it before the tests run. e.g.
diff --git a/docs/src/content/docs/explainers/nodejs-native-esm-support.mdx b/docs/src/content/docs/explainers/nodejs-native-esm-support.mdx
index c0fc25ee..e09ac07e 100644
--- a/docs/src/content/docs/explainers/nodejs-native-esm-support.mdx
+++ b/docs/src/content/docs/explainers/nodejs-native-esm-support.mdx
@@ -1,5 +1,5 @@
---
-description: A mid-level outline of Mocha's "flow of execution".
+description: Writing your tests as ES modules instead of CommonJS.
title: Node.js Native ESM Support
---
@@ -27,7 +27,7 @@ More information can be found in the [Node.js documentation](https://nodejs.org/
### Current Limitations
- [Watch mode](/running/cli#--watch--w) does not support ES Module test files
-- [Custom reporters](/reporters/third-party) and [custom interfaces](/interfaces/third-party) can only be CommonJS files
+- [Custom reporters](/reporters/third-party) and [custom interfaces](/interfaces/third-party) can be ES modules but Mocha loads them with `require` so they cannot use top-level `await`
- Mocha in Node.js version 24.4.0 or older [silently ignored top level errors in ESM files](https://github.com/mochajs/mocha/issues/5396).
If you cannot upgrade to a newer Node.js version, you can add `--no-experimental-require-module` to the `NODE_OPTIONS` environment variable.
- When using module-level mocks via libs like `proxyquire`, `rewiremock` or `rewire`, hold off on using ES modules for your test files.
diff --git a/docs/src/content/docs/explainers/stub-stdout.mdx b/docs/src/content/docs/explainers/stub-stdout.mdx
index 2e36c67b..f21f8fa7 100644
--- a/docs/src/content/docs/explainers/stub-stdout.mdx
+++ b/docs/src/content/docs/explainers/stub-stdout.mdx
@@ -11,9 +11,9 @@ i.e.
it("should do, but it do not", function () {
// user wants to hide output generated by console.log calls in fn 'foo'
console.log = function () {};
- foo();
+ const result = foo();
- expect(...);
+ expect(result).to.equal("bar");
});
```
@@ -24,10 +24,10 @@ The correct way to handle this is to stub before and restore after the function
```javascript
it("will do", function () {
const consoleLogStub = sinon.stub(console, "log");
- foo();
+ const result = foo();
consoleLogStub.restore();
- expect(...);
+ expect(result).to.equal("bar");
});
```
diff --git a/docs/src/content/docs/explainers/test-duration.mdx b/docs/src/content/docs/explainers/test-duration.mdx
index 7d007dcd..4bf4d227 100644
--- a/docs/src/content/docs/explainers/test-duration.mdx
+++ b/docs/src/content/docs/explainers/test-duration.mdx
@@ -1,5 +1,5 @@
---
-description: A mid-level outline of Mocha's "flow of execution".
+description: How reporters show test duration and flag slow tests.
title: Test Duration
---
diff --git a/docs/src/content/docs/running/browsers.mdx b/docs/src/content/docs/running/browsers.mdx
index e93d928b..cc155077 100644
--- a/docs/src/content/docs/running/browsers.mdx
+++ b/docs/src/content/docs/running/browsers.mdx
@@ -58,11 +58,11 @@ Examples:
```js
// Use "tdd" interface. This is a shortcut to setting the interface;
// any other options must be passed via an object.
-mocha.setup('tdd');
+mocha.setup("tdd");
// This is equivalent to the above.
mocha.setup({
- ui: 'tdd'
+ ui: "tdd",
});
// Examples of options:
@@ -75,12 +75,17 @@ mocha.setup({
failZero: true,
forbidOnly: true,
forbidPending: true,
- global: ['MyLib'],
+ global: ["MyLib"],
retries: 3,
- rootHooks: { beforeEach(done) { ... done();} },
- slow: '100',
- timeout: '2000',
- ui: 'bdd'
+ rootHooks: {
+ beforeEach(done) {
+ // your setup here
+ done();
+ },
+ },
+ slow: "100",
+ timeout: "2000",
+ ui: "bdd",
});
```