Today I learned

Cleaner Mocha stack traces

Update (2018): Much has changed in Mocha since this post was written in 2015.

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.

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.

Usage

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

Installation

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.

You have just read Cleaner Mocha stack traces, written on March 06, 2015. This is Today I Learned, a collection of random tidbits I've learned through my day-to-day web development work. I'm Rico Sta. Cruz, @rstacruz on GitHub (and Twitter!).

← More articles