Runner

Runner

new Runner(suite, optsopt)

Source:

Initialize a Runner at the Root Suite, which represents a hierarchy of Suites and Tests.

Parameters:
NameTypeAttributesDescription
suiteSuite

Root suite

optsObject<optional>

Settings object

Properties
NameTypeAttributesDescription
cleanReferencesAfterRunboolean<optional>

Whether to clean references to test fns and hooks when a suite is done.

delayboolean<optional>

Whether to delay execution of root suite until ready.

dryRunboolean<optional>

Whether to report tests without running them.

failZeroboolean<optional>

Whether to fail test run if zero tests encountered.

Extends

Members

(static, readonly) constants :string

Source:
Properties:
NameTypeDescription
EVENT_HOOK_BEGINstring

Emitted when Hook execution begins

EVENT_HOOK_ENDstring

Emitted when Hook execution ends

EVENT_RUN_BEGINstring

Emitted when Root Suite execution begins (all files have been parsed and hooks/tests are ready for execution)

EVENT_DELAY_BEGINstring

Emitted when Root Suite execution has been delayed via delay option

EVENT_DELAY_ENDstring

Emitted when delayed Root Suite execution is triggered by user via global.run()

EVENT_RUN_ENDstring

Emitted when Root Suite execution ends

EVENT_SUITE_BEGINstring

Emitted when Suite execution begins

EVENT_SUITE_ENDstring

Emitted when Suite execution ends

EVENT_TEST_BEGINstring

Emitted when Test execution begins

EVENT_TEST_ENDstring

Emitted when Test execution ends

EVENT_TEST_FAILstring

Emitted when Test execution fails

EVENT_TEST_PASSstring

Emitted when Test execution succeeds

EVENT_TEST_PENDINGstring

Emitted when Test becomes pending

EVENT_TEST_RETRYstring

Emitted when Test execution has failed, but will retry

STATE_IDLEstring

Initial state of Runner

STATE_RUNNINGstring

State set to this value when the Runner has started running

STATE_STOPPEDstring

State set to this value when the Runner has stopped

Runner-related constants.

Type:
  • string

_eventListeners :Map:.<EventEmitter:, Map:.<string:, Set:.<EventListener:>>>

Source:
Type:

Methods

abort() → {Runner}

Source:

Cleanly abort execution.

Returns:

Runner instance.

Type
Runner

dispose()

Source:

Removes all event handlers set during a run on this instance.
Remark: this does not clean/dispose the tests or suites themselves.

globals(arr) → {Runner}

Source:

Allow the given arr of globals.

Parameters:
NameTypeDescription
arrArray
Returns:

Runner instance.

Type
Runner

grep(re, invert) → {Runner}

Source:

Run tests with full titles matching re. Updates runner.total
with number of tests matched.

Parameters:
NameTypeDescription
reRegExp
invertboolean
Returns:

Runner instance.

Type
Runner

grepTotal(suite) → {number}

Source:

Returns the number of tests matching the grep search for the
given suite.

Parameters:
NameTypeDescription
suiteSuite
Returns:
Type
number

isParallelMode() → {false}

Source:

Returns true if Mocha is running in parallel mode. For reporters.

Subclasses should return an appropriate value.

Returns:
Type
false

(abstract) linkPartialObjects(valueopt) → {Runner}

Source:

Toggle partial object linking behavior; used for building object references from
unique ID's. Does nothing in serial mode, because the object references already exist.
Subclasses can implement this (e.g., ParallelBufferedRunner)

Example
// this reporter needs proper object references when run in parallel mode
class MyReporter() {
  constructor(runner) {
    this.runner.linkPartialObjects(true)
      .on(EVENT_SUITE_BEGIN, suite => {
           // this Suite may be the same object...
      })
      .on(EVENT_TEST_BEGIN, test => {
        // ...as the `test.parent` property
      });
  }
}
Parameters:
NameTypeAttributesDescription
valueboolean<optional>

If true, enable partial object linking, otherwise disable

Returns:
Type
Runner

run(fn, optsopt) → {Runner}

Source:

Run the root suite and invoke fn(failures)
on completion.

Parameters:
NameTypeAttributesDescription
fnfunction

Callback when finished

optsObject<optional>

For subclasses

Properties
NameTypeDescription
filesArray:.<string:>

Files to run

optionsOptions

command-line options

Returns:

Runner instance.

Type
Runner

(abstract) workerReporter(path) → {Runner}

Source:

Configures an alternate reporter for worker processes to use. Subclasses
using worker processes should implement this.

Parameters:
NameTypeDescription
pathstring

Absolute path to alternate reporter for worker processes to use

Throws:

When in serial mode

Returns:
Type
Runner