npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mocha-clean

v1.0.0

Published

Cleans up mocha stack traces.

Downloads

54,815

Readme

mocha-clean

Cleans up mocha test stack traces.

Loading screenshot...

Status

Purpose

Mocha stack traces are riddled with frames that you don't want to see, like code from modules and Mocha internals.

  1) Test:
     ReferenceError: someKey is not defined
      at Context.<anonymous> (/Users/rsc/Projects/mocha-clean/test/test.js:24:5)
      at callFn (/Users/rsc/Projects/mocha-clean/node_modules/mocha/lib/runnable.js:249:21)
      at Test.Runnable.run (/Users/rsc/Projects/mocha-clean/node_modules/mocha/lib/runnable.js:242:7)
      at Runner.runTest (/Users/rsc/Projects/mocha-clean/node_modules/mocha/lib/runner.js:373:10)
      ...

This is better:

  1) Test:
     ReferenceError: someKey is not defined
      at myFunction (test/test:7:1)
      at test/test.js:24:5

It strips away mocha internals, node_modules, absolute paths (based on cwd), and other unneccessary cruft.

Usage (Node.js)

npm version Available via npm.

$ npm i --save-dev mocha-clean

Add this to your test/mocha.opts:

--require mocha-clean

Usage (browser)

Experimental browser support is available. Get the latest version here:

<script src="//cdn.rawgit.com/rstacruz/mocha-clean/v0.4.0/index.js"></script>

In the browser, use mocha.traceIgnores to define files to be excluded. Your setup will likely look like this (with chai.js in this example):

<script src="mocha.js"></script>
<script src="chai.js"></script>
<script src="mocha-clean.js"></script>
<script>mocha.setup('bdd')</script>
<script>mocha.traceIgnores = ['mocha.js', 'chai.js']</script>
<script src="tests.js"></script>
<script>mocha.run()</script>

Brief mode

To display brief format error messages similar to C++, Ruby and so on, add this to test/mocha.opts:

--require mocha-clean/brief

This displays the filenames first (file:n:n: function), which is reformatted from the JavaScript-style at function (file:n:n).

1) error:
   ReferenceError: xyz is not defined
    test/fail.js:12:4: myfunction
    test/fail.js:9:9: Context.<anonymous>

Showing node_modules

By default, mocha-clean removes anything under node_modules. To disable this behavior, add this to test/mocha.opts:

--require mocha-clean/show_node_modules

Using with Gulp, Grunt, Karma, et al

See: Using with mocha loaders ▸

Showing absolute paths

By default, mocha-clean removes the current working directory from the beginning of paths. To disable this behavior, add this to test/mocha.opts:

--require mocha-clean/absolute_paths

Related discussions

There was talk in 2012 to bring this feature to mocha itself (see mocha#545), which eventually was merged around v2.2.5. It's been updated eversince to only affect mocha's internals. In contrast, mocha-clean cleans up all your node_modules's stack frames.

mocha-clean has been tested with mocha 1.21.x and will likely work for the entire mocha 1.x series.

Thanks

mocha-clean © 2014+, Rico Sta. Cruz. Released under the MIT License. Authored and maintained by Rico Sta. Cruz with help from contributors (list).

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz