Registry / testing / node-test-reporter

node-test-reporter

JSON →
library1.2.0jsnpmunverified

node-test-reporter is an opinionated, actively maintained test reporter for Node.js's built-in test runner, providing a clean, Ava-inspired output experience. Its current stable version is 1.2.0, with minor releases frequently addressing bugs and adding small features. It differentiates itself by offering enhanced error formatting for `equal` and `strictEqual` assertions via `concordance`, improved stack trace reporting, and an early error display mechanism for tests that hang due to unclosed resources. The reporter also integrates with Node.js's experimental code coverage features and provides a distinct visual style, including flipped plus/minus signs for diffs compared to the default Node.js reporter. It is designed for Node.js environments version 18 and newer, with specific recommendations for v22+ for optimal coverage reporting.

npm install node-test-reporter
INSTALL
IMPORT
SIG · NODE-TEST-REPORTER
N
node-test-reporter
testingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NodeTestReporter CLI Usage
node --test --test-reporter node-test-reporter 'src/**/*.test.js'
import reporter from 'node-test-reporter'; // This package is a CLI reporter, not a library to be imported directly.
This package is a CLI test reporter. Its functionality is activated by passing it as a `--test-reporter` flag to the Node.js built-in test runner, not by importing symbols within test files.
TypeScript Test Execution
node --import tsx --test --enable-source-maps --test-reporter node-test-reporter 'src/**/*.test.ts'
node --test --test-reporter node-test-reporter 'src/**/*.test.ts'; // Omitting `tsx` and source maps will lead to runtime errors or incorrect line numbers.
For running TypeScript tests, an additional loader like `tsx` is required, along with `--enable-source-maps` to ensure correct stack trace line numbers in the output.
package.json Test Script
"test": "node --test --test-reporter node-test-reporter 'src/**/*.test.js'"
The recommended method for consistent execution is to define a 'test' script in your `package.json`.

This quickstart provides runnable JavaScript test code to demonstrate passing and failing assertions, including a deep equality diff, and how to execute it with the `node-test-reporter`.

import assert from 'node:assert'; import { test } from 'node:test'; test('My passing test example', () => { assert.strictEqual(1, 1, 'Expected 1 to be 1'); }); test('My failing test to demonstrate diff and error reporting', () => { const actual = { id: 1, data: { name: 'Alice', age: 30 } }; const expected = { id: 1, data: { name: 'Alice', age: 31 } }; assert.deepStrictEqual(actual, expected, 'Expected objects to be deeply equal but age differs'); }); test('Another passing asynchronous test', async (t) => { await new Promise(resolve => setTimeout(resolve, 100)); // Simulate async work assert.ok(true, 'Asynchronous operation successfully completed'); }); // To run this after `npm install node-test-reporter -D`: // 1. Save this content as `my.test.js`. // 2. Execute in your terminal: `node --test --test-reporter node-test-reporter my.test.js`
Debug
Known issues
breakingNode.js glob pattern handling for `**` changed in v21. Glob patterns like `'src/**/*.test.js'` now require surrounding quotes, otherwise they may not resolve correctly or expand to unexpected files.
fix
For Node.js v21+, ensure glob patterns with `**` are enclosed in single quotes. For older versions, you may need to specify the directory without globs (e.g., `src`) or use a custom globbing solution.
affects: <v21
gotchaThe reporter intentionally flips the convention for plus and minus signs in diff outputs compared to Node.js's default. Added lines are prefixed with '-', removed lines with '+'.
fix
No direct fix if you prefer Node.js's default; this is a design choice of the reporter. Consider if this visual style aligns with your team's preferences.
affects: >=1.0.0
gotchaThere is a known bug in Node.js v20 where using `--experimental-test-coverage` can lead to errors in some scenarios when reporting coverage.
fix
It is recommended to use Node.js v22 or newer when enabling experimental test coverage (`--experimental-test-coverage`) to avoid this issue.
affects: =20.x
gotchaTests that start servers, intervals, or timers without proper cleanup can cause the Node.js test runner to hang indefinitely. While `node-test-reporter` outputs errors after a 5-second idle period, it doesn't automatically identify the specific hanging test.
fix
Ensure all resources (e.g., HTTP servers, `setInterval`, `setTimeout`) are properly closed or cleared in your test cleanup logic, especially in `after` hooks or test tear-down phases.
affects: >=1.0.0
breakingThis package relies on Node.js's built-in test runner, which was introduced in Node.js v18. Therefore, the `node-test-reporter` requires Node.js v18 or newer.
fix
Upgrade your Node.js environment to version 18 or higher to use this test reporter.
affects: <18.0.0
Errors
Common errors & fixes
TypeError: Invalid module 'tsx' imported (or similar module loading errors)
Attempting to run TypeScript tests without the necessary `tsx` loader or incorrect Node.js import flag.
fix
Ensure `tsx` is installed (`npm install tsx -D`) and invoke Node.js with `node --import tsx --test ...` for TypeScript files.
Error: Cannot find module 'my-test-file.js' (or glob patterns not resolving)
Incorrect glob pattern usage, especially with `**` in Node.js v21+ where quotes are now mandatory.
fix
Ensure your glob pattern is enclosed in single quotes, e.g., `node --test 'src/**/*.test.js'`. For Node.js versions older than v21, you might need to omit quotes or specify directories directly.
SyntaxError: Unexpected token ':' (or similar errors pointing to TypeScript syntax in runtime)
Trying to execute TypeScript files directly with Node.js without a transpiler/loader.
fix
Use a TypeScript execution environment like `tsx` with the Node.js `--import` flag: `node --import tsx --test --enable-source-maps ...`
Test suite does not exit, or hangs indefinitely without reporting all errors.
A test has started an asynchronous operation (e.g., a server, interval, or timer) but failed to clean it up, preventing the Node.js event loop from emptying.
fix
Review tests for unclosed resources. Ensure all servers are `close()`d, `setInterval`s are `clearInterval()`ed, and `setTimeout`s are `clearTimeout()`ed in `after` or `afterEach` hooks.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
tsxoptionalRequired as an optional loader for running TypeScript tests with source maps.
Agent activity
2 hits · last 30 days
node
2
Resources
node-test-reporter — npm install node-test-reporter · libregistry