☕️ Classic, reliable, trusted test framework for Node.js and the browser
docs: migrate third party reporters wiki page to docs (#5433)
Kelechi Ebirif70764c9a56f
diff --git a/docs-next/astro.config.ts b/docs-next/astro.config.tsindex 4416b5e3..3d50540a 100644--- a/docs-next/astro.config.ts+++ b/docs-next/astro.config.ts@@ -111,6 +111,10 @@ export default defineConfig({label: "Test fixture decision tree",slug: "explainers/test-fixture-decision-tree",},+ {+ label: "Third party reporters",+ slug: "explainers/third-party-reporters",+ },],label: "Explainers",},diff --git a/docs-next/src/content/docs/explainers/third-party-reporters.mdx b/docs-next/src/content/docs/explainers/third-party-reporters.mdxnew file mode 100644index 00000000..c7dd3175--- /dev/null+++ b/docs-next/src/content/docs/explainers/third-party-reporters.mdx@@ -0,0 +1,57 @@+---+description: Create custom reporters.+title: Third party reporters+---++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`.++Here is a minimalistic sample reporter, which you can use by executing: `mocha --reporter my-reporter.js`++```js+// my-reporter.js+var mocha = require('mocha');+module.exports = MyReporter;++function MyReporter(runner) {+ mocha.reporters.Base.call(this, runner);+ var passes = 0;+ var failures = 0;++ runner.on('pass', function (test) {+ passes++;+ console.log('pass: %s', test.fullTitle());+ });++ runner.on('fail', function (test, err) {+ failures++;+ console.log('fail: %s -- error: %s', test.fullTitle(), err.message);+ });++ runner.on('end', function () {+ console.log('end: %d/%d', passes, passes + failures);+ });+}++// To have this reporter "extend" a built-in reporter uncomment the following line:+// mocha.utils.inherits(MyReporter, mocha.reporters.Spec);+```++For details look at the implementations in [lib/reporters/*](https://github.com/mochajs/mocha/tree/main/lib/reporters).++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).++Mocha provides the following events:+- **start**: Execution started+- **waiting**: Execution of root `Suite` delayed+- **ready**: Execution of root `Suite` started+- **end**: Execution complete+- **suite**: Test suite execution started+- **suite end**: All tests (and sub-suites) have finished+- **test**: Test execution started+- **test end**: Test completed+- **hook**: Hook execution started+- **hook end**: Hook complete+- **pass**: Test passed+- **fail**: Test failed+- **pending**: Test pending+- **retry**: Test failed and retriesdiff --git a/docs/api-tutorials/jsdoc.tutorials.json b/docs/api-tutorials/jsdoc.tutorials.jsonindex 383d3daa..80f83f01 100644--- a/docs/api-tutorials/jsdoc.tutorials.json+++ b/docs/api-tutorials/jsdoc.tutorials.json@@ -2,10 +2,13 @@"custom-reporter": {"title": "Create a Custom Reporter"},+ "shared-behaviours": {+ "title": "Shared behaviours"+ },"spies": {"title": "Spies"},- "shared-behaviours": {- "title": "Shared behaviours"+ "third-party-reporters": {+ "title": "Third party reporters"}}diff --git a/docs/api-tutorials/third-party-reporters.md b/docs/api-tutorials/third-party-reporters.mdnew file mode 100644index 00000000..bef513c6--- /dev/null+++ b/docs/api-tutorials/third-party-reporters.md@@ -0,0 +1,53 @@+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`.++Here is a minimalistic sample reporter, which you can use by executing: `mocha --reporter my-reporter.js`++```js+// my-reporter.js+var mocha = require('mocha');+module.exports = MyReporter;++function MyReporter(runner) {+ mocha.reporters.Base.call(this, runner);+ var passes = 0;+ var failures = 0;++ runner.on('pass', function (test) {+ passes++;+ console.log('pass: %s', test.fullTitle());+ });++ runner.on('fail', function (test, err) {+ failures++;+ console.log('fail: %s -- error: %s', test.fullTitle(), err.message);+ });++ runner.on('end', function () {+ console.log('end: %d/%d', passes, passes + failures);+ });+}++// To have this reporter "extend" a built-in reporter uncomment the following line:+// mocha.utils.inherits(MyReporter, mocha.reporters.Spec);+```++For details look at the implementations in [lib/reporters/\*](https://github.com/mochajs/mocha/tree/main/lib/reporters).++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).++Mocha provides the following events:++- **start**: Execution started+- **waiting**: Execution of root `Suite` delayed+- **ready**: Execution of root `Suite` started+- **end**: Execution complete+- **suite**: Test suite execution started+- **suite end**: All tests (and sub-suites) have finished+- **test**: Test execution started+- **test end**: Test completed+- **hook**: Hook execution started+- **hook end**: Hook complete+- **pass**: Test passed+- **fail**: Test failed+- **pending**: Test pending+- **retry**: Test failed and retries