Skip to content

Instantly share code, notes, and snippets.

@jaredatron
Last active May 17, 2018 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatron/1549dc177d0a673c791a2570ca5dc2da to your computer and use it in GitHub Desktop.
Save jaredatron/1549dc177d0a673c791a2570ca5dc2da to your computer and use it in GitHub Desktop.
A subclass of the Spec reporter that prints the details of a test failure as soon as it fails

Customer Mocha Reporter

…that prints the details of the test failure error as soon as a test fails.

Why? I hate having to wait until my long test suite finishes to begin debugging why a test fails.

// ./test/mocha.opts
--reporter test/reporter.js
// ./test/reporter.js
'use strict'
const inherits = require('util').inherits
const { Base, Spec } = require('mocha').reporters
const Reporter = function(runner) {
Spec.call(this, runner)
runner.on('fail', function (test, error) {
Base.list([test])
})
}
inherits(Reporter, Spec)
exports = module.exports = Reporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment