Runner

Mocha. Runner

new Runner(suiteopt, delayopt)

Source:

Initialize a Runner for the given suite. Derived from EventEmitter

Events:

  • start execution started
  • end execution complete
  • suite (suite) test suite execution started
  • suite end (suite) all tests (and sub-suites) have finished
  • test (test) test execution started
  • test end (test) test completed
  • hook (hook) hook execution started
  • hook end (hook) hook complete
  • pass (test) test passed
  • fail (test, err) test failed
  • pending (test) test pending
Parameters:
NameTypeAttributesDescription
suiteSuite<optional>

Root suite

delayboolean<optional>

Whether or not to delay execution of root suite
until ready.

Members

(static) immediately

Source:

Wrapper for setImmediate, process.nextTick, or browser polyfill.

Methods

(static) Runner#abort() → {Runner}

Source:

Cleanly abort execution.

Returns:

Runner instance.

Type
Runner

(static) Runner#globals(arr) → {Runner}

Source:

Allow the given arr of globals.

Parameters:
NameTypeDescription
arrArray
Returns:

Runner instance.

Type
Runner

(static) 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

(static) Runner#grepTotal(suite) → {number}

Source:

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

Parameters:
NameTypeDescription
suiteSuite
Returns:
Type
number

(static) Runner#run(fn) → {Runner}

Source:

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

Parameters:
NameTypeDescription
fnfunction
Returns:

Runner instance.

Type
Runner

checkGlobals()

Source:

Check for global variable leaks.

fail(test, err)

Source:

Fail the given test.

Parameters:
NameTypeDescription
testTest
errError

failHook(hook, err)

Source:

Fail the given hook with err.

Hook failures work in the following pattern:

  • If bail, then exit
  • Failed before hook skips all tests in a suite and subsuites,
    but jumps to corresponding after hook
  • Failed before each hook skips remaining tests in a
    suite and jumps to corresponding after each hook,
    which is run only once
  • Failed after hook does not alter
    execution order
  • Failed after each hook skips remaining tests in a
    suite and subsuites, but executes other after each
    hooks
Parameters:
NameTypeDescription
hookHook
errError

globalProps() → {Array}

Source:

Return a list of global properties.

Returns:
Type
Array

hook(name, fn)

Source:

Run hook name callbacks and then invoke fn().

Parameters:
NameTypeDescription
namestring
fnfunction

hookDown(name, fn)

Source:

Run hooks from the bottom up.

Parameters:
NameTypeDescription
nameString
fnfunction

hooks(name, suites, fn)

Source:

Run hook name for the given array of suites
in order, and callback fn(err, errSuite).

Parameters:
NameTypeDescription
namestring
suitesArray
fnfunction

hookUp(name, fn)

Source:

Run hooks from the top level down.

Parameters:
NameTypeDescription
nameString
fnfunction

parents() → {Array}

Source:

Return an array of parent Suites from
closest to furthest.

Returns:
Type
Array

runSuite(suite, fn)

Source:

Run the given suite and invoke the callback fn() when complete.

Parameters:
NameTypeDescription
suiteSuite
fnfunction

runTest(fn)

Source:

Run the current test and callback fn(err).

Parameters:
NameTypeDescription
fnfunction

runTests(suite, fn)

Source:

Run tests in the given suite and invoke the callback fn() when complete.

Parameters:
NameTypeDescription
suiteSuite
fnfunction

uncaught(err)

Source:

Handle uncaught exceptions.

Parameters:
NameTypeDescription
errError