Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve third-party reporter docs #5285

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ var MAX_TIMEOUT = Math.pow(2, 31) - 1;

module.exports = Runnable;

// "Additional properties" doc comment added for hosted docs (mochajs.org/api)
/**
* Initialize a new `Runnable` with the given `title` and callback `fn`.
* Additional properties, like `getFullTitle()` and `slow()`, can be viewed in the `Runnable` source.
*
* @class
* @extends external:EventEmitter
Expand Down
42 changes: 40 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,39 @@ var globals = [

var constants = utils.defineConstants(
/**
* {@link Runner}-related constants.
* {@link Runner}-related constants. Used by reporters. Each event emits the corresponding object, unless otherwise indicated.
* @example
* const Mocha = require('mocha');
* const Base = Mocha.reporters.Base;
* const {
* EVENT_HOOK_BEGIN,
* EVENT_TEST_PASS,
* EVENT_TEST_FAIL,
* EVENT_TEST_END
* } = Mocha.Runner.constants
*
* function MyReporter(runner, options) {
* Base.call(this, runner, options);
*
* runner.on(EVENT_HOOK_BEGIN, function(hook) {
* console.log('hook called: ', hook.title);
* });
*
* runner.on(EVENT_TEST_PASS, function(test) {
* console.log('pass: %s', test.fullTitle());
* });
*
* runner.on(EVENT_TEST_FAIL, function(test, err) {
* console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
* });
*
* runner.on(EVENT_TEST_END, function() {
* console.log('end: %d/%d', runner.stats.passes, runner.stats.tests);
* });
* }
*
* module.exports = MyReporter;
*
* @public
* @memberof Runner
* @readonly
Expand Down Expand Up @@ -97,7 +129,13 @@ var constants = utils.defineConstants(
*/
EVENT_TEST_END: 'test end',
/**
* Emitted when {@link Test} execution fails
* Emitted when {@link Test} execution fails. Includes an `err` object of type `Error`.
* @example
* runner.on(EVENT_TEST_FAIL, function(test, err) {
* console.log('fail: %s -- error: %s', test.fullTitle(), err.message);
* });
*
*
*/
EVENT_TEST_FAIL: 'fail',
/**
Expand Down
Loading