Mocha Reporters

REPORTERS

Mocha reporters adjust to the terminal window, and always disable ANSI-escape coloring when the stdio streams are not associated with a TTY.

SPEC

This is the default reporter. The “spec” reporter outputs a hierarchical view nested just as the test cases are.

spec reporter spec reporter with failure

DOT MATRIX

The dot matrix (or “dot”) reporter is simply a series of characters which represent test cases. Failures highlight in red exclamation marks (!), pending tests with a blue comma (,), and slow tests as yellow. Good if you prefer minimal output.

dot matrix reporter

NYAN

The “nyan” reporter is exactly what you might expect:

js nyan cat reporter

TAP

The TAP reporter emits lines for a Test-Anything-Protocol consumer.

test anything protocol

LANDING STRIP

The Landing Strip (landing) reporter is a gimmicky test reporter simulating a plane landing 🙂 unicode ftw

landing strip plane reporter landing strip with failure

LIST

The “list” reporter outputs a simple specifications list as test cases pass or fail, outputting the failure details at the bottom of the output.

list reporter

PROGRESS

The “progress” reporter implements a simple progress-bar:

progress bar

JSON

The “JSON” reporter outputs a single large JSON object when the tests have completed (failures or not).

json reporter

JSON STREAM

The “JSON stream” reporter outputs newline-delimited JSON “events” as they occur, beginning with a “start” event, followed by test passes or failures, and then the final “end” event.

json stream reporter

MIN

The “min” reporter displays the summary only, while still outputting errors on failure. This reporter works great with –watch as it clears the terminal in order to keep your test summary at the top.

min reporter

DOC

The “doc” reporter outputs a hierarchical HTML body representation of your tests. Wrap it with a header, footer, and some styling, then you have some fantastic documentation!

doc reporter

For example, suppose you have the following JavaScript:

describe(‘Array’, function() {
describe(‘#indexOf()’, function() {
it(‘should return -1 when the value is not present’, function() {
[1,2,3].indexOf(5).should.equal(-1);
[1,2,3].indexOf(0).should.equal(-1);
});
});
});
The command mocha –reporter doc array would yield:

Array

#indexOf()

should return -1 when the value is not present

The SuperAgent request library test documentation was generated with Mocha’s doc reporter using this simple make target:

test-docs:
$(MAKE) test REPORTER=doc \
| cat docs/head.html – docs/tail.html \
> docs/test.html
View the entire Makefile for reference.

MARKDOWN

The “markdown” reporter generates a markdown TOC and body for your test suite. This is great if you want to use the tests as documentation within a Github wiki page, or a markdown file in the repository that Github can render. For example here is the Connect test output.

HTML

The “HTML” reporter is currently the only browser reporter supported by Mocha, and it looks like this:

HTML test reporter

UNDOCUMENTED REPORTERS

The “XUnit” reporter is also available. By default, it will output to the console. To write directly to a file, use –reporter-options output=filename.xml.

THIRD PARTY REPORTERS

Mocha allows you to define custom third-party reporters. For more information see the wiki. An example is the TeamCity reporter.

Questions