MochaReporter

About

To produce any output from a test run, you must supply MochaRunner with a reporter delegate class which is responsible for generating a report. Reporter delegates are event-based and implement the mochaopen in new window event model.

By itself, this class only keeps track of how many tests have passed and failed and how long the test run takes. It is up to a delegate class to respond to report events and produce the actual report.

TIP

js.component comes with two reporter delegate classes: MochaHtmlReporter and MochaMultiReporter. MochaHtmlReporter is the default.

Reporter events

The following events are emitted during a test run:

EventDescription
startExecution of a test run started
endExecution of a test run complete
suiteTest suite execution started
suite endAll tests (and sub-suites) have finished
testTest execution started
test endTest completed
hookHook execution started
hook endHook completed
passTest passed
failTest failed

The interface for each event is documented in the MochaReporterDelegate interface. For a complete example of how to listen to these events to write a reporter delegate, see the source of the MochaHtmlReporter class.

API

constructor()

cs.js.MochaReporter.new(
   runner : cs.js.MochaRunner;
   delegateClass : 4D.Class
   { ; delegateOptions : Object }
)

Creates a new MochaReporter instance and a new instance of delegateClass, passing delegateOptions to the delegate’s constructor. If delegateOptions is not passed or is null, it defaults to an empty object. See the delegate interface for more information.

If delegateClass implements a .reporterDidReset() function, it is called after the delegate is created.


.failCount

.failCount : Integer

Returns the number of selected tests that have been failed. This is incremented for you by the "fail" event handler. This property is read-only.


.passCount

.passCount : Integer

Returns the number of selected tests that have passed. This is incremented for you by the "pass" event handler. This property is read-only.


.reset()

.reset()

Sets .passCount and .failCount to 0 and sets .startMs to the current Milliseconds. This function is called by the test runner at the start of a test run.

NOTE

If the delegate implements a .reporterDidReset() function, it is called after this function.


.skipCount

.skipCount : Integer

Returns the number of selected tests that were skipped. This property is read-only.


.startMs

.startMs : Integer

Returns the millisecond time at which the test runner started. This property is read-only.


.testCount

.testCount : Integer

Returns the total number of tests that have been run. This property is read-only.


.timing

.timing : Integer

Returns the time (in milliseconds) it took to run the tests. This does not include the time to select test classes and tests, or the time to build a report. This property is read-only.

NOTE

This value is 0 until the test run has completed.

Last Updated:
Contributors: Aparajita