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 🙏

© 2026 – Pkg Stats / Ryan Hefner

node-test-mocha-reporter

v1.0.1

Published

A custom reporter for the Node.js built-in test runner (node:test) that prints results like mocha's default spec reporter. Zero dependencies.

Downloads

343

Readme

CI npm

node-test-mocha-reporter

A custom reporter for the Node.js built-in test runner (node:test) that prints results like mocha's default spec reporter. Zero dependencies.

Why

I replaced mocha with node:test to have fewer dependencies to keep updating. The built-in spec reporter of node:test works, but it's noisy: every line has a timing, suites are marked with ▶, and each suite is repeated after its tests. I found mocha's output much easier to read, so this reporter brings it back.

If I ever don't want to maintain it, switching back to --test-reporter=spec is a one-word change.

Usage

Install it as a dev dependency:

npm install --save-dev node-test-mocha-reporter

Then pass it to node --test, for example in the test script of package.json:

{
  "scripts": {
    "test": "node --test --test-reporter=node-test-mocha-reporter"
  }
}

It requires Node.js 22 or later.

Output

This is the output for three of the test fixtures, failing.js, pending.js and slow.js:


  suite
    ✔ passes
    1) fails
    2) fails with a multiline message

  suite
    - is skipped
    - is todo
    - skips itself
    ✔ passes

  suite
    ✔ takes a while (102ms)


  3 passing (144ms)
  3 pending
  2 failing

  1) suite
       fails:
     Error: boom
      at failing.js:5:3

  2) suite
       fails with a multiline message:
     Error: first line
     second line
      at failing.js:8:3

What it supports, the same way mocha does:

  • Failures are numbered in the tree, and listed after the summary with their suite path, error and location.
  • Skipped and todo tests (it.skip, it.todo, t.skip()) are shown as - name and counted as pending.
  • Failed hooks are reported with their own error, e.g. "before all" hook or "before each" hook for "test name". Tests cancelled because of a failed before hook aren't listed separately.
  • Test files that crash while loading are listed as a failure, e.g. test file exited with code 1, see its output above. The crash itself is in the file's output, printed before the results.
  • Slow tests show their duration: yellow above 37ms, red above 75ms, as with mocha's default slow: 75.
  • Colors are used when the output is a terminal. FORCE_COLOR=1 and NO_COLOR=1 work as usual.

Differences from mocha

  • Console output of a test file is printed before that file's results, not next to the test that logged it. Node runs each test file in a separate process and reports its output first, so there's no way around it.
  • Locations point to where the failed test is declared, not to the line that threw. The location is relative to the working directory when the file is inside it, and absolute otherwise.
  • Thresholds for slow tests are fixed at mocha's defaults, there's no --slow option.

How it works

node:test emits events like test:start, test:pass and test:fail, and the reporter turns them into lines of output. The only non-obvious part is suite headers: test:start doesn't tell suites from tests, so a suite's name is printed right before the first result inside it.

Tests

The tests run each file in fixtures/ under node --test with the reporter, and compare the whole output. They cover passing and failing tests, pending tests, failed hooks, crashing test files, console output, slow tests, locations, colors and exit codes. Test durations are removed before comparing, so a slow machine doesn't make the tests fail.

npm test

The test script names index.test.js explicitly, so the fixtures never run as tests of their own. Node's default patterns also match every file in a test/ folder, so they could pick up the fixtures if they were moved there.

Credits

Only the output format follows mocha (MIT licensed), none of its code is used.