Cleaner Mocha stack traces

Mocha is a great way to test JavaScript, but its stack traces are riddled with useless frames from Mocha internals and 3rd-party modules. Let's try and clean it up.

Comparison screenshot

Introducing mocha-clean

mocha-clean is a plugin for Mocha. It strips away mocha internals, node_modules, absolute paths (based on cwd), and other unneccessary cruft from stack traces.


Simply invoke Mocha with -r mocha-clean. The easiest way to do this is to add it to your test/mocha.opts file.

--require mocha-clean


It's available via npm, and works with Mocha 1.x in Node.js and in the browser. The source is available in GitHub: rstacruz/mocha-clean.

npm install --save-dev mocha-clean

Merging into Mocha?

A pull request is currently open in Mocha to integrate this functionality into Mocha itself. Check out #1564 and offer your support and comments.