Skip to content

Commit f70764c

Browse files
TG199mark-wiemer
andauthored
docs: migrate third party reporters wiki page to docs (#5433)
Co-authored-by: Mark Wiemer <[email protected]>
1 parent 1dc4aa9 commit f70764c

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed

docs-next/astro.config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ export default defineConfig({
111111
label: "Test fixture decision tree",
112112
slug: "explainers/test-fixture-decision-tree",
113113
},
114+
{
115+
label: "Third party reporters",
116+
slug: "explainers/third-party-reporters",
117+
},
114118
],
115119
label: "Explainers",
116120
},
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
description: Create custom reporters.
3+
title: Third party reporters
4+
---
5+
6+
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`.
7+
8+
Here is a minimalistic sample reporter, which you can use by executing: `mocha --reporter my-reporter.js`
9+
10+
```js
11+
// my-reporter.js
12+
var mocha = require('mocha');
13+
module.exports = MyReporter;
14+
15+
function MyReporter(runner) {
16+
mocha.reporters.Base.call(this, runner);
17+
var passes = 0;
18+
var failures = 0;
19+
20+
runner.on('pass', function (test) {
21+
passes++;
22+
console.log('pass: %s', test.fullTitle());
23+
});
24+
25+
runner.on('fail', function (test, err) {
26+
failures++;
27+
console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
28+
});
29+
30+
runner.on('end', function () {
31+
console.log('end: %d/%d', passes, passes + failures);
32+
});
33+
}
34+
35+
// To have this reporter "extend" a built-in reporter uncomment the following line:
36+
// mocha.utils.inherits(MyReporter, mocha.reporters.Spec);
37+
```
38+
39+
For details look at the implementations in [lib/reporters/*](https://github.com/mochajs/mocha/tree/main/lib/reporters).
40+
41+
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).
42+
43+
Mocha provides the following events:
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

docs/api-tutorials/jsdoc.tutorials.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
"custom-reporter": {
33
"title": "Create a Custom Reporter"
44
},
5+
"shared-behaviours": {
6+
"title": "Shared behaviours"
7+
},
58
"spies": {
69
"title": "Spies"
710
},
8-
"shared-behaviours": {
9-
"title": "Shared behaviours"
11+
"third-party-reporters": {
12+
"title": "Third party reporters"
1013
}
1114
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
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`.
2+
3+
Here is a minimalistic sample reporter, which you can use by executing: `mocha --reporter my-reporter.js`
4+
5+
```js
6+
// my-reporter.js
7+
var mocha = require('mocha');
8+
module.exports = MyReporter;
9+
10+
function MyReporter(runner) {
11+
mocha.reporters.Base.call(this, runner);
12+
var passes = 0;
13+
var failures = 0;
14+
15+
runner.on('pass', function (test) {
16+
passes++;
17+
console.log('pass: %s', test.fullTitle());
18+
});
19+
20+
runner.on('fail', function (test, err) {
21+
failures++;
22+
console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
23+
});
24+
25+
runner.on('end', function () {
26+
console.log('end: %d/%d', passes, passes + failures);
27+
});
28+
}
29+
30+
// To have this reporter "extend" a built-in reporter uncomment the following line:
31+
// mocha.utils.inherits(MyReporter, mocha.reporters.Spec);
32+
```
33+
34+
For details look at the implementations in [lib/reporters/\*](https://github.com/mochajs/mocha/tree/main/lib/reporters).
35+
36+
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).
37+
38+
Mocha provides the following events:
39+
40+
- **start**: Execution started
41+
- **waiting**: Execution of root `Suite` delayed
42+
- **ready**: Execution of root `Suite` started
43+
- **end**: Execution complete
44+
- **suite**: Test suite execution started
45+
- **suite end**: All tests (and sub-suites) have finished
46+
- **test**: Test execution started
47+
- **test end**: Test completed
48+
- **hook**: Hook execution started
49+
- **hook end**: Hook complete
50+
- **pass**: Test passed
51+
- **fail**: Test failed
52+
- **pending**: Test pending
53+
- **retry**: Test failed and retries

0 commit comments

Comments
 (0)