Skip to content

Using and Writing Reporters

csnover edited this page Sep 5, 2014 · 7 revisions

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 This reporter generates a Cobertura-compatible XML report from collated coverage data.
combined client (Node.js) + runner New in Intern 2.0 This reporter stores coverage data generated by the Node.js client in an intermediate file, and then merges in data generated by the WebDriver runner to generate a combined coverage report.
console client This reporter outputs test pass/fail messages to the console, grouped by suite.
html client (browser) This reporter generates a basic HTML report of unit test results.
lcov client (Node.js), runner This reporter generates an lcov.info from collated coverage data.
lcovhtml client (Node.js), runner 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 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 topic is published 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 topic is published 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.
/deprecated runner name - a deprecated method name
replacement - the replacement method name
extra - any extra information
This topic is published once for each deprecated method that is called on the WebDriver client instance.
/error runner error - an Error object or string generated by Error#toString() This topic is published 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 Command instance This topic is published after a test environment has finished running all of its tests and has been cleaned up.
/session/start runner remote - A Command instance This topic is published after a test environment has been successfully initialised but before it has been instructed to run any tests.
/runner/end runner (none) This topic is published after the runner has finished running all test suites and is ready to shut down.
/runner/start runner (none) This topic is published 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 topic is published 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 the suite’s publishAfterSetup property 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 topic is published 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 topic is published when a suite is about to start executing. If the suite’s publishAfterSetup property 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 topic is published when new suite is created.
/test/end client, runner test - A Test instance This topic is published 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 topic is published 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 topic is published when a new test is created.
/test/pass client, runner test - A Test instance This topic is published when a test passes.
/test/start client, runner test - A Test instance This topic is published immediately before a test starts.
/tunnel/download/progress runner tunnel - A Tunnel instance
progress - An object with progress information
This topic is published repeatedly while the WebDriver tunnel application is being downloaded. The progress object contains received (bytes received) and total (bytes to download) properties.
/tunnel/start runner tunnel - A Tunnel instance This topic is published immediately before the WebDriver tunnel is started.
/tunnel/status runner tunnel - A Tunnel instance
status - A status message
This topic is published when the WebDriver tunnel's status changes.
/tunnel/stop runner tunnel - A Tunnel instance This topic is published immediately after the WebDriver tunnel is stopped.
Clone this wiki locally