You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mocha 1.3.0 allows you to define custom third-party reporters within your own test suite, or by using npm modules. For example if "lcov-reporter" was published to npm, you would simply add it to your package.json in `devDependencies` and use `--reporter lcov-reporter`.
6
+
Mocha allows you to define custom third-party reporters within your own test suite, or by using npm modules. For example if "lcov-reporter" was published to npm, you would simply add it to your package.json in `devDependencies` and use `--reporter lcov-reporter`.
7
7
8
-
Here is a minimalistic sample reporter, which you can use by executing: `mocha --reporter my-reporter.js`
8
+
:::note[New in v12.0.0]
9
+
In Mocha 12, the extension logic is switched to modern `class`es instead of `util.inherits`.
10
+
If you're on Mocha 11 or older, use `mocha.util.inherits`. See [v11.mochajs.org](https://v11.mochajs.org/explainers/third-party-reporters/) for details.
11
+
:::
12
+
13
+
Here is a minimalistic sample reporter for Mocha 12, which you can use by executing: `mocha --reporter my-reporter.js`
9
14
10
15
```js
11
16
// my-reporter.js
12
17
importmochafrom"mocha";
13
18
14
-
exportdefaultfunctionMyReporter(runner) {
15
-
mocha.reporters.Base.call(this, runner);
16
-
let passes =0;
17
-
let failures =0;
19
+
// You can extend other reporters by changing the class you extend:
20
+
// export default class MyReporter extends mocha.reporters.Spec {
For details look at the implementations in [lib/reporters/\*](https://github.com/mochajs/mocha/tree/main/lib/reporters).
45
+
For details, look at the implementations in [lib/reporters/\*](https://github.com/mochajs/mocha/tree/main/lib/reporters).
39
46
40
-
Another sample implementation can be found at [mocha-examples: third-party-reporter (GitHub)](https://github.com/mochajs/mocha-examples/tree/main/packages/third-party-reporter).
47
+
[mocha-examples: third-party-reporter (GitHub)](https://github.com/mochajs/mocha-examples/tree/main/packages/third-party-reporter) is another sample implementation.
41
48
42
49
Mocha provides the following events:
43
50
44
-
-**start**: Execution started
45
-
-**waiting**: Execution of root `Suite` delayed
46
-
-**ready**: Execution of root `Suite` started
47
-
-**end**: Execution complete
48
-
-**suite**: Test suite execution started
49
-
-**suite end**: All tests (and sub-suites) have finished
50
-
-**test**: Test execution started
51
-
-**test end**: Test completed
52
-
-**hook**: Hook execution started
53
-
-**hook end**: Hook complete
54
-
-**pass**: Test passed
55
-
-**fail**: Test failed
56
-
-**pending**: Test pending
57
-
-**retry**: Test failed and retries
51
+
-`start`: Execution started
52
+
-`waiting`: Execution of root `Suite` delayed
53
+
-`ready`: Execution of root `Suite` started
54
+
-`end`: Execution complete
55
+
-`suite`: Test suite execution started
56
+
-`suite end`: All tests (and sub-suites) have finished
0 commit comments