Output formats

When running tests from the command-line you can make jstest produce a variety of output formats using the FORMAT environment variable. For example:

Where possible, it will detect whether stdout is a TTY and will not print colored output otherwise. If you need to manually disable colored output, set NO_COLOR=1.

As well as specifying this on the command-line, you can use the reporter API to programmatically set the output format. You will usually want to add the ExitStatus reporter after whichever text reporter you select. For example to get spec output you can do this:

JS.Test.autorun(function(runner) {
  runner.setReporter(new JS.Test.Reporters.Spec())
  runner.addReporter(new JS.Test.Reporters.ExitStatus())

The following lists all the available text output formats and their reporter classes. Note that all these reporters (except progress) work on every platform supported by jstest. In the terminal they print to stdout, and in the browser they print using console.log(). Here’s the above spec format rendered in the WebKit inspector:

dot, JS.Test.Reporters.Dot

Prints a dot for every passing test, F for assertion failures and E for errors. Prints a summary including error details at the end.

error, JS.Test.Reporters.Error

Prints nothing for passing tests, and prints error details as soon as the error happens rather than waiting until the end.

json, JS.Test.Reporters.JSON

This is a literal serialization of the reporter event data, which is useful for sending test results via an I/O stream for formatting somewhere else. For example, the PhantomJS reporter uses this to send results from the browser to the terminal.

It prints one reporter event per line using the format:

{"jstest": [eventName, data]}

progress, JS.Test.Reporters.Progress

Prints an animated progress bar. Only works in TTYs.

spec, JS.Test.Reporters.Spec

Prints the results as a nested set of specs, mirroring the tests’ structure. Prints a summary including error details at the end.

tap, JS.Test.Reporters.TAP

Prints TAP representation of the results.

tap-j, JS.Test.Reporters.TAP_JSON

Prints TAP-J output than can be piped into tapout.

tap-y, JS.Test.Reporters.TAP_YAML

Prints TAP-Y output than can be piped into tapout.

xml, JS.Test.Reporters.XML

Prints a JUnit-style XML report to stdout.