Registry / testing / node-test-parser

node-test-parser

JSON →
library3.1.0jsnpmunverified

node-test-parser is a utility library designed to parse the output streams generated by Node.js's built-in native test runner. It provides a programmatic interface to transform raw test report streams into structured JavaScript objects, facilitating the creation of custom test reporters, analysis tools, or integration with other systems. The current stable version is 3.1.0, with regular patch and minor releases addressing dependency updates and Node.js compatibility. Major versions, such as v3.0.0, introduce significant breaking changes, primarily around Node.js runtime support. Its key differentiator lies in its specific focus and optimized parsing for the native Node.js test output, offering a streamlined approach for developers looking to extend the core Node.js testing experience without relying on external test frameworks.

npm install node-test-parser
INSTALL
IMPORT
SIG · NODE-TEST-PARSER
N
node-test-parser
testingjavascriptv3.1.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.

parseReport
import parseReport from 'node-test-parser'
import { parseReport } from 'node-test-parser'
The primary parsing function is exported as the default export of the module. Attempting to destructure it as a named export will result in an error.
parseReport
import parseReport from 'node-test-parser'
const parseReport = require('node-test-parser')
Since version 3.x, the library is distributed as an ES Module (ESM). CommonJS `require()` is not directly supported without ESM compatibility layers or bundlers and will typically lead to errors.
jsonReporter
export default async function* jsonReporter(source) { /* ... */ }
When creating a custom test reporter as shown in the quickstart, you typically export a default async generator function. The `parseReport` function then consumes the `source` stream passed to your reporter.

This quickstart demonstrates how to create a custom Node.js test reporter using `node-test-parser`. It shows how to import and use `parseReport` to consume the raw test stream and output a formatted JSON report. The example includes instructions for running tests with the custom reporter.

import parseReport from 'node-test-parser' import { test } from 'node:test' // reporter.js export default async function* customJsonReporter(source) { const report = await parseReport(source) yield JSON.stringify(report, null, 2) } // In your terminal, you would run your tests with this custom reporter: // node --test --test-reporter ./reporter.js // Example of a simple test file (tests.js) to generate output for the reporter: // test('synchronous passing test', (t) => { // t.ok(true, 'this passes') // }); // // test('asynchronous failing test', async (t) => { // await new Promise(resolve => setTimeout(resolve, 100)); // t.ok(false, 'this fails after a delay'); // }); // // test('skipped test', { skip: true }, (t) => { // t.ok(true, 'this should be skipped'); // });
Debug
Known issues
breakingVersion 3.0.0 introduced a breaking change by requiring Node.js version 22 or higher. Older Node.js runtimes are no longer supported and will likely result in runtime errors.
fix
Upgrade your Node.js runtime environment to version 22 or newer to ensure compatibility. If an upgrade is not feasible, use `node-test-parser@2.x`.
affects: >=3.0.0
gotchaThe `node-test-parser` library is specifically designed to parse the output of Node.js's native `node:test` runner. It is not intended for parsing reports from other test frameworks like Jest, Mocha, or Vitest, and attempting to do so will yield incorrect or no results.
fix
Ensure that the input `source` stream provided to `parseReport` originates solely from `node --test` command output. For other test runners, use their specific reporting or parsing utilities.
affects: >=1.0.0
gotchaThe `parseReport` function expects a readable stream as input. Providing a non-stream object or attempting to parse synchronous string data directly will result in a runtime error or unexpected behavior, as it relies on stream processing semantics.
fix
Always pass a Node.js `Readable` stream to the `parseReport` function. If you have string data, convert it into a stream using utilities like `Readable.from()` or `new Readable()`.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Named export 'parseReport' not found. The requested module 'node-test-parser' does not provide an export named 'parseReport'
Attempting to import `parseReport` as a named export when it is a default export.
fix
Change the import statement to `import parseReport from 'node-test-parser'`.
ERR_REQUIRE_ESM: require() of ES Module ...node-test-parser/index.js from ... not supported.
Attempting to use CommonJS `require()` to import `node-test-parser`, which is an ES Module (ESM).
fix
Refactor your code to use ES Module `import` syntax (`import parseReport from 'node-test-parser'`) and ensure your environment supports ESM (e.g., set `"type": "module"` in `package.json` or use `.mjs` file extension).
TypeError: parseReport is not a function
This can occur if the module was incorrectly imported (e.g., using `require` for an ESM default export that returns `Module { default: ... }`) or if the `parseReport` symbol was overridden.
fix
Verify that `import parseReport from 'node-test-parser'` is used and that no other variable or function named `parseReport` is shadowing it.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-test-parser — npm install node-test-parser · libregistry