Mocha reporter without console funkyness
This is a Spec
-style console reporter for mocha that doesn't confuse lesser console environments with funky display modes, cursor tricks or weird control characters.
Use-case is running mocha's in basic console views embedded in IDE's or setups with text buffered output (like travis-ci). The default config uses only some ANSI console colour codes and writes with console.log() but has option to be tuned up or down for your specific unfunky use-case.
- The reporter does not extend mocha's default Base prototype because that is a main source of funkyness. This means not all of mocha's reporter features are supported.
- There are many features to ease testing usability, like aggressive attempts at getting a sensible error message or a stack filter that attempts to compact the stack trace by dropping mocha function calls.
- Object & string diffs by unfunk-diff.
- Output by ministyle & miniwrite.
Install from npm:
$ npm install mocha-unfunk-reporter --save-dev
Then use 'mocha-unfunk-reporter'
as reporter
parameter in your favourite mocha runner.
For example in grunt-mocha-test
:
grunt.initConfig({
// ...
mochaTest: {
options: {
reporter: 'mocha-unfunk-reporter'
},
any: {
src: ['test/**/*.test.js']
}
}
});
There are multiple ways to set global options:
//on module using .option() method
require('mocha-unfunk-reporter').option('<option_name>', <option_value>);
//or on env with prefixed name
process.env['mocha-unfunk-<option_name>'] = <option_value>;
//env also work Bash-style: upper-cased and underscores instead of dashes
process.env['MOCHA_UNFUNK_<OPTION_NAME>'] = <option_value>;
These are equivalent:
process.env['MOCHA_UNFUNK_REPORTPENDING'] = true;
process.env['mocha-unfunk-reportPending'] = true;
require('mocha-unfunk-reporter').option('reportPending', true);
require('mocha-unfunk-reporter').option({reportPending: true});
The package also expose a grunt task mocha_unfunk
to set reporter options.
grunt.initConfig({
mocha_unfunk: {
myStyle: {
options: {
style: 'plain'
}
}
}
}
Report styling: style
'ansi'
- plain with ansi color codes (default)'plain'
- plain text'none'
- even plainer text'html'
- html span's with css colors'css'
- html span's with css classes'dev'
- style development codes
Output mode: writer
'log'
- buffer and stream per line toconsole.log()
(default)'stdio'
- stream toprocess.stdout
'bulk'
- single bufferedconsole.log()
'null'
- ignore output
Report details about pending specs, alongside failures: reportPending
false
(default) ortrue
Use custom stream: stream
- any standard
WritableStream
(only usable viarequire()
)
Filter internals from stack: stackFilter
true
(default) orfalse
Something like this: (full version)
If you got development install you can use $ grunt demo
to get a quick demo overview.
Tested with:
- Chai Assertion Libary (best of the best, but no IE < 9)
- Proclaim (Chai-like
'assert'
, supports IE < 9) - CommonJS-style
'assert'
(Node.js, browserify etc)
Should work with any assertion library, like:
- Expect.js (minimal reporting, use Chai's expect-style)
- Should.js (untested, use Chai's should-style)
Create an issue if you got a tip or see bugs.
Testing on:
- mocha (bin cli)
- grunt-mocha (grunt + phantomJS)
- grunt-mocha-test (grunt + node)
Known to work:
- grunt-simple-mocha (grunt + node)
- grunt-mocha-spawn (grunt + node)
- grunt-cafe-mocha (grunt + node)
Create an issue if you got a tip or request for more.
Unfunk-reporter is written in TypeScript and built using grunt and powered by gruntfile-gtx.
Install development dependencies in your git checkout:
$ npm install
You need the global grunt command:
$ npm install grunt-cli -g
Build and run tests:
// build & display demo (handy for development)
$ grunt -h
// build & full test
$ grunt
// show gtx alias
$ grunt -h
// run test sub module
$ grunt gtx:diff
See the Gruntfile
for additional commands.
- 0.4.0 - externalised unfunk-diff, using ministyle, miniwrite, dropped obsolete code.
- 0.3.7 - fixed some bugs
- 0.3.6 - relaxed string encoding, cleaned stack code, support Q longStack, support multi-line messages, fixed bugs & hardened output, added
q
andnode.js
to stack filter. - 0.3.0 - improved diffs (speed, linebreaks, escape with jsesc), added output testing, added grunt task to set options, updated project
- 0.2.3 - support bash style uppercased+underscore-style ENV options (tip by @reydelamirienda), skip diff excessively lengthy objects (strings/arrays/arguments/buffers)
- 0.2.2 - fixed regular Error (stack) reporting, added
chai-as-promised
&mocha-as-promised
to stack filter, updated screenshot - 0.2.1 - tweaked display, added pending test report (by @geekdave)
- 0.2.0 - added string diff, more assertions and runner compatibility, changed default to
style='ansi'
- 0.1.13 - fix for grunt-mocha duration stats compatibility
- 0.1.12 - refactored options; added style and writer
- 0.1.11 - added mocha bin command test, improved reporting
- 0.1.10 - objectDiff fix, added option() methods
- 0.1.8 - compatible with grunt-mocha (PhantomJS)
Copyright (c) 2013 Bart van der Schoor
Licensed under the MIT license.