MochaReporterDelegate (Interface)

About

Classes that conform to this interface can be used as a delegate for MochaReporter. The delegate is responsible for handling the various events that are emitted during the execution of a test suite and building a report accordingly.

API

constructor()

cs.MyDelegate.new(reporter : cs.js.MochaReporter; options : Object)

The delegate constructor is called by the reporter when it is created. In your delegate class constructor you will usually want to:

  • Store a reference to the reporter so you can retrieve pass/fail counts.
  • Use any options passed in.
  • Subscribe to the events you want to handle.

Example

Class constructor($reporter : cs.MochaReporter; $options : Object)
  This.reporter:=$reporter

  var $this : cs.MochaHtmlReporter
  var $runner : cs.MochaRunner

  // We need to use a local var to capture This in formulas
  $this:=This
  $runner:=$reporter.runner
  $runner.on("suite"; Formula($this.onSuiteStart($1)))
  $runner.on("suite end"; Formula($this.onSuiteEnd($1)))
  $runner.on("pass"; Formula($this.onPass($1)))
  $runner.on("fail"; Formula($this.onFail($1)))

NOTE

Although the constructor is not strictly required, a delegate will not be of much use unless you subscribe to the events you want to handle.


.report()

.report()

This function is called by the test runner at the end of a test run, after all of the test results have been collected. In your delegate class you will typically use this function to set up the report, allocate any resources necessary, and then produce the report from information you have gathered by handling events.

For example, MochaHtmlReporter uses this function to:

  • Read the HTML report template from disk.
  • Fill in template placeholders with test results.
  • Display the resulting HTML in a dialog window.

IMPORTANT

You must define this function in your delegate class.


.reporterDidReset()

.reporterDidReset()

If defined, this function is called by the test runner at the start of a test run. Typically you will use this function to reset any state your delegate uses.

Events

Each event emitted during a test run is listed below along with a function that represents a potential handler for the event with the parameters it will receive. The events are listed in the order they are emitted.

NOTE

The delegate will only receive the events it has subscribed to.

start

.onStart()

The test runner is about to start a test run.


hook (beforeAll)

.onHook(runner : cs.js.MochaRunner; "beforeAll" : Text; hook : Callable)

The test runner is about to start executing one of its .beforeAll() hooks.


hook end (beforeAll)

.onHookEnd(runner : cs.js.MochaRunner; "beforeAll" : Text; hook : Callable)

The test runner has finished executing one of its .beforeAll() hooks.


suite

.onSuite(suite : cs.js.MochaSuite)

A suite is about to start executing its tests.


hook (before)

.onHook(suite : cs.js.MochaSuite; "before" : Text; hook : Callable)

A suite is about to start executing one of its .before() hooks.


hook end (before)

.onHookEnd(suite : cs.js.MochaSuite; "before" : Text; hook : Callable)

A suite has finished executing one of its .before() hooks.


hook (beforeEach)

.onHook(suite : cs.js.MochaSuite; "beforeEach" : Text; hook : Callable)

A suite is about to start executing one of its .beforeEach() hooks.


hook end (beforeEach)

.onHookEnd(suite : cs.js.MochaSuite; "beforeEach" : Text; hook : Callable)

A suite has finished executing one of its .beforeEach() hooks.


test

.onTest(test : cs.js.MochaTest)

A suite is about to start executing test.


pass

.onPass(test : cs.js.MochaTest)

An assertion in test passed.


fail

.onFail(test : cs.js.MochaTest)

An assertion in test failed. test.error will contain a ChaiAssertionError.


test end

.onTestEnd(test : cs.js.MochaTest)

A suite has finished executing test.


hook (afterEach)

.onHook(suite : cs.js.MochaSuite; "afterEach" : Text; hook : Callable)

A suite is about to start executing one of its .afterEach() hooks.


hook end (afterEach)

.onHookEnd(suite : cs.js.MochaSuite; "afterEach" : Text; hook : Callable)

A suite has finished executing one of its .afterEach() hooks.


hook (after)

.onHook(suite : cs.js.MochaSuite; "after" : Text; hook : Callable)

A suite is about to start executing one of its .after() hooks.


hook end (after)

.onHookEnd(suite : cs.js.MochaSuite; "after" : Text; hook : Callable)

A suite has finished executing one of its .after() hooks.


suite end

.onSuiteEnd(suite : cs.js.MochaSuite)

A suite has finished executing its tests.


hook (afterAll)

.onHook(runner : cs.js.MochaRunner; "afterAll" : Text; hook : Callable)

The test runner is about to start executing one of its .afterAll() hooks.


hook end (afterAll)

.onHookEnd(runner : cs.js.MochaRunner; "afterAll" : Text; hook : Callable)

The test runner has finished executing one of its .afterAll() hooks.


end

.onEnd()

The test runner has finished a test run and is about to call .report() produce a report.

Last Updated:
Contributors: Aparajita