Using and Writing Reporters - msssk/intern GitHub Wiki

Information about the state of a test run needs to be produced in many different formats depending upon how the user wishes to consume the information. In order to faciliate this, Intern publishes specific information about each stage of a test run using a pub/sub mechanism, and registers reporters that listen for these topics and output information in the correct format.

Included Reporters

The following reporters are included in a standard Intern installation and can be used by passing the name of the reporter to the reporters array:

Reporter Platform Description
cobertura client (Node.js), runner New in Intern 1.4 This reporter generates a Cobertura-compatible XML report from collated coverage data.
console client This reporter outputs test pass/fail messages to the console, grouped by suite.
lcov client (Node.js), runner This reporter generates an lcov.info from collated coverage data.
lcovhtml client (Node.js), runner New in Intern 1.4 This reporter generates a set of illustrated HTML reports from collated coverage data.
runner runner This reporter outputs information to the console about the current state of the runner, code coverage and test results for each environment tested, and a total test result.
teamcity client (Node.js), runner New in Intern 1.4 This reporter outputs test result information to the console in a TeamCity-compatible format.
webdriver client This reporter proxies test results from a client back to the test runner via the instrumentation proxy. It also displays very basic running test output as HTML to provide improved state information when watching a test run via Sauce Labs live view. This reporter is used automatically when the test runner runs unit tests in a browser and should typically never be specified directly.

Custom reporters

If none of the built-in reporters provide the information you need, you can write a custom reporter and reference it using an absolute module ID (i.e. myProject/tests/customReporter). The reporter itself is a single JavaScript object that uses topic names as keys and functions as values:

define([], function () {
	return {
		'/test/start': function (test) {
			console.log(test.id + ' started');
		},
		'/test/end': function (test) {
			console.log(test.id + ' ended');
		}
	};
});

Reporters can also include optional start and stop methods for performing any additional arbitrary work when a reporter is started or stopped:

define([
	'dojo/aspect',
	'intern/lib/Suite'
], function (aspect, Suite) {
	var handles = [];
	return {
		start: function () {
			function augmentJsonValue() {
				/* … */
			}

			handles.push(aspect.after(Suite.prototype, 'toJSON', augmentJsonValue));
		},

		stop: function () {
			var handle;
			while ((handle = handles.pop())) {
				handle.remove();
			}
		}
	}
});

Available reporter topics

Topic Platform Parameters Description
/client/end client, runner sessionId - a string representing the remote client’s session ID This method is called when a client has finished executing all of its unit tests. It is used primarily as an indicator to start running functional tests.
/coverage runner sessionId - a string representing the remote environment’s session ID
coverage - an Object containing instrumentation coverage usable by Istanbul
This method is called when code coverage data has been retrieved from an environment under test. This will occur once for each remote environment when all unit tests have completed, and again at the end of each functional suite.
/error runner error - an Error object or string generated by Error#toString() This method is called whenever an error occurs anywhere within Intern. These errors may be test failures, or they may be more serious errors from outside the test code itself.
/session/end runner remote - A PromisedWebDriver instance This method is called after a test environment has finished running all of its tests and has been cleaned up.
/session/start runner remote - A PromisedWebDriver instance This method is called after a test environment has been successfully initialised but before it has been instructed to run any tests.
/runner/end runner (none) This method is called after the runner has finished running all test suites and is ready to shut down.
/runner/start runner (none) This method is called after the runner has finished its configuration process and has started the Sauce Connect server, if one is being used. It is called immediately before the test suite starts running.
/suite/end client, runner suite - A Suite instance This method is called when a suite has finished running. It is called regardless of whether or not an error has occurred. If an error occurred, it will exist at suite.error. If suite.publishAfterSetup is true, this method will be called before suite teardown occurs; otherwise, it will be called after teardown has completed.
/suite/error client, runner suite - A Suite instance This method is called when an error occurs within a test suite. The error that was thrown can be found at suite.error.
/suite/start client, runner suite - A Suite instance This method is called when a suite is about to start executing. If suite.publishAfterSetup is true, this method will be called after suite setup has completed; otherwise, it will be called before setup has started.
/suite/new client, runner suite - A Suite instance This method is called when new suite is created.
/test/end client, runner test - A Test instance This method is called after a test has finished executing. The error that caused the failure can be found at test.error.
/test/fail client, runner test - A Test instance This method is called when a test fails. The error that caused the failure can be found at test.error.
/test/new client, runner test - A Test instance This method is called when a new test is created.
/test/pass client, runner test - A Test instance This method is called when a test passes.
/test/start client, runner test - A Test instance This method is called immediately before a test starts.
⚠️ **GitHub.com Fallback** ⚠️