Skip to content

Commit

Permalink
Document usages of Runner.constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-wiemer committed Jan 3, 2025
1 parent 08b5ae1 commit 8893870
Showing 1 changed file with 40 additions and 2 deletions.
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

0 comments on commit 8893870

Please # to comment.