{"id":13671,"library":"node-test-parser","title":"Node.js Test Report Stream Parser","description":"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.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/nearform/node-test-parser","tags":["javascript","test","report","typescript"],"install":[{"cmd":"npm install node-test-parser","lang":"bash","label":"npm"},{"cmd":"yarn add node-test-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-test-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { parseReport } from 'node-test-parser'","symbol":"parseReport","correct":"import parseReport from 'node-test-parser'"},{"note":"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.","wrong":"const parseReport = require('node-test-parser')","symbol":"parseReport","correct":"import parseReport from 'node-test-parser'"},{"note":"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.","symbol":"jsonReporter","correct":"export default async function* jsonReporter(source) { /* ... */ }"}],"quickstart":{"code":"import parseReport from 'node-test-parser'\nimport { test } from 'node:test'\n\n// reporter.js\nexport default async function* customJsonReporter(source) {\n  const report = await parseReport(source)\n  yield JSON.stringify(report, null, 2)\n}\n\n// In your terminal, you would run your tests with this custom reporter:\n// node --test --test-reporter ./reporter.js\n\n// Example of a simple test file (tests.js) to generate output for the reporter:\n// test('synchronous passing test', (t) => {\n//   t.ok(true, 'this passes')\n// });\n//\n// test('asynchronous failing test', async (t) => {\n//   await new Promise(resolve => setTimeout(resolve, 100));\n//   t.ok(false, 'this fails after a delay');\n// });\n//\n// test('skipped test', { skip: true }, (t) => {\n//   t.ok(true, 'this should be skipped');\n// });\n","lang":"javascript","description":"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."},"warnings":[{"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`.","message":"Version 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.","severity":"breaking","affected_versions":">=3.0.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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()`.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'3.1.0':64 'address':71 'analysi':52 'approach':111 'around':87 'break':84 'built':25 'built-in':24 'chang':85 'compat':76 'core':118 'creation':47 'current':60 'custom':49 'depend':72 'design':14 'develop':113 'differenti':93 'experi':121 'extend':116 'extern':125 'facilit':45 'focus':98 'framework':127 'generat':20 'integr':55 'interfac':34 'introduc':82 'javascript':43,128 'key':92 'librari':13 'lie':94 'look':114 'major':77 'minor':69 'nativ':27,104 'node':7 'node-test-pars':6 'node.js':1,22,75,88,105,119 'object':44 'offer':108 'optim':100 'output':18,107 'pars':16,101 'parser':5,9 'patch':67 'primarili':86 'programmat':33 'provid':31 'raw':37 'regular':66 'releas':70 'reli':123 'report':3,39,51,130 'runner':29 'runtim':89 'signific':83 'specif':97 'stabl':61 'stream':4,19,40 'streamlin':110 'structur':42 'support':90 'system':58 'test':2,8,28,38,50,106,120,126,129 'tool':53 'transform':36 'typescript':131 'updat':73 'util':12 'v3.0.0':81 'version':62,78 'without':122","created_at":"2026-04-20T01:55:42.727141+00:00","updated_at":"2026-04-20T01:55:42.727141+00:00","problems":[{"fix":"Change the import statement to `import parseReport from 'node-test-parser'`.","cause":"Attempting to import `parseReport` as a named export when it is a default export.","error":"SyntaxError: Named export 'parseReport' not found. The requested module 'node-test-parser' does not provide an export named 'parseReport'"},{"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).","cause":"Attempting to use CommonJS `require()` to import `node-test-parser`, which is an ES Module (ESM).","error":"ERR_REQUIRE_ESM: require() of ES Module ...node-test-parser/index.js from ... not supported."},{"fix":"Verify that `import parseReport from 'node-test-parser'` is used and that no other variable or function named `parseReport` is shadowing it.","cause":"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.","error":"TypeError: parseReport is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/nearform/node-test-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/node-test-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}