Registry / testing / streamtest

streamtest

JSON →
library1.0b1jsnpmunverified

Streamtest is a JavaScript library providing a robust set of utilities specifically designed for testing Node.js stream-based modules. It simplifies the creation of test input streams and the collection of output from streams under test. Developers can easily generate readable streams from arrays of data chunks or objects using methods like `fromChunks` and `fromObjects`, and then collect results from writable streams into promises that resolve with processed text, raw chunks, or objects via `toText`, `toChunks`, and `toObjects`. The current stable version is 4.0.0, and it primarily targets modern Node.js environments (v24.14.0+). Its key differentiator is providing a concise and intuitive API for stream testing, significantly reducing boilerplate compared to manually managing stream events and states, making it an ideal choice for projects with extensive stream processing logic.

npm install streamtest
INSTALL
IMPORT
SIG · STREAMTEST
S
streamtest
testingjavascriptv1.0b1
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.

StreamTest
import StreamTest from 'streamtest';
const StreamTest = require('streamtest');
The package is ESM-only since v4. The default export is an object containing all utility methods.
fromChunks
StreamTest.fromChunks(['hello']);
import { fromChunks } from 'streamtest';
Methods like `fromChunks` are properties of the default `StreamTest` object, not named exports.
toText
const [outputStream, resultPromise] = StreamTest.toText();
new StreamTest.toText();
`toText` returns a tuple of a writable stream and a promise, it is not a constructor.

Demonstrates creating input streams with `fromChunks` and `fromObjects`, piping data through a test stream, and capturing the processed output with `toText` and `toObjects` for assertion.

import StreamTest from 'streamtest'; import { Transform } from 'stream'; import assert from 'assert'; describe('My Stream Lib', () => { it('should capture text output from a stream', async () => { // A simple passthrough stream, representing your stream-under-test const myTestedStream = new Transform({ transform(chunk, encoding, callback) { this.push(chunk.toString().toUpperCase()); // Example transformation callback(); } }); const [outputStream, resultPromise] = StreamTest.toText(); // Create a readable stream from an array of chunks, // pipe it through your tested stream, then into streamtest's collecting stream. StreamTest.fromChunks(['hello ', 'world', '!']) .pipe(myTestedStream) .pipe(outputStream); // Await the collected text and assert against the expected output. assert.equal(await resultPromise, 'HELLO WORLD!'); }); it('should create a stream from objects and collect processed objects', async () => { const [objectOutputStream, objectResultPromise] = StreamTest.toObjects(); const myObjectStream = new Transform({ objectMode: true, transform(obj, encoding, callback) { this.push({ ...obj, processed: true, timestamp: Date.now() }); callback(); } }); StreamTest.fromObjects([{ id: 1, value: 'A' }, { id: 2, value: 'B' }]) .pipe(myObjectStream) .pipe(objectOutputStream); const expected = [ { id: 1, value: 'A', processed: true, timestamp: (await objectResultPromise)[0].timestamp }, { id: 2, value: 'B', processed: true, timestamp: (await objectResultPromise)[1].timestamp } ]; assert.deepStrictEqual(await objectResultPromise, expected); }); });
Debug
Known issues
breakingVersion 4.0.0 and above of streamtest explicitly requires Node.js version 24.14.0 or higher due to its `engines` field in `package.json`. Running it on older Node.js versions will result in an error or unexpected behavior.
fix
Upgrade your Node.js environment to version 24.14.0 or newer. Consider using `nvm` or `volta` to manage Node.js versions.
affects: >=4.0.0
breakingStreamtest v4.0.0 is an ECMAScript Module (ESM) only package. Attempting to use `require()` for CommonJS imports will fail with `SyntaxError: Cannot use import statement outside a module` or similar errors.
fix
Ensure your project is configured for ESM (e.g., `"type": "module"` in `package.json`) and use `import StreamTest from 'streamtest';` for all imports.
affects: >=4.0.0
gotchaThe `done` callback pattern used in some older test frameworks for asynchronous operations is often discouraged in favor of `async/await` with modern test runners. While `streamtest` supports both, using `async/await` with its promise-based collectors (`resultPromise`) provides cleaner and more readable test code.
fix
Refactor asynchronous test blocks to be `async` functions and `await` the `resultPromise` returned by `toText()`, `toChunks()`, or `toObjects()`.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Attempting to use `import StreamTest from 'streamtest';` in a CommonJS module context (e.g., a `.js` file without `"type": "module"` in `package.json`, or a `.cjs` file).
fix
Configure your project to use ESM by adding `"type": "module"` to your `package.json` or by using `.mjs` file extensions for modules that use `import`.
TypeError: StreamTest is not a constructor
Trying to instantiate `StreamTest` with `new StreamTest()` or similar, when it's an object containing static utility methods, not a class.
fix
Access `streamtest` utilities directly as properties of the imported `StreamTest` object, e.g., `StreamTest.fromChunks()` or `StreamTest.toText()`.
TypeError: Cannot read properties of undefined (reading 'fromChunks')
This error often occurs when `StreamTest` is `undefined` because `require('streamtest')` was used in an ESM-only package, or the `import` failed silently.
fix
Verify that your environment is configured for ESM and you are using `import StreamTest from 'streamtest';`. Also, check your Node.js version meets the `>=24.14.0` requirement.
Upgrade
Version history
1.0b1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
streamtest — npm install streamtest · libregistry