{"library":"streamtest","title":"Streamtest","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install streamtest"],"cli":null},"imports":["import StreamTest from 'streamtest';","StreamTest.fromChunks(['hello']);","const [outputStream, resultPromise] = StreamTest.toText();"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/nfroidure/streamtest","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/streamtest","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import StreamTest from 'streamtest';\nimport { Transform } from 'stream';\nimport assert from 'assert';\n\ndescribe('My Stream Lib', () => {\n  it('should capture text output from a stream', async () => {\n    // A simple passthrough stream, representing your stream-under-test\n    const myTestedStream = new Transform({\n      transform(chunk, encoding, callback) {\n        this.push(chunk.toString().toUpperCase()); // Example transformation\n        callback();\n      }\n    });\n\n    const [outputStream, resultPromise] = StreamTest.toText();\n\n    // Create a readable stream from an array of chunks,\n    // pipe it through your tested stream, then into streamtest's collecting stream.\n    StreamTest.fromChunks(['hello ', 'world', '!'])\n      .pipe(myTestedStream)\n      .pipe(outputStream);\n\n    // Await the collected text and assert against the expected output.\n    assert.equal(await resultPromise, 'HELLO WORLD!');\n  });\n\n  it('should create a stream from objects and collect processed objects', async () => {\n    const [objectOutputStream, objectResultPromise] = StreamTest.toObjects();\n\n    const myObjectStream = new Transform({\n      objectMode: true,\n      transform(obj, encoding, callback) {\n        this.push({ ...obj, processed: true, timestamp: Date.now() });\n        callback();\n      }\n    });\n\n    StreamTest.fromObjects([{ id: 1, value: 'A' }, { id: 2, value: 'B' }])\n      .pipe(myObjectStream)\n      .pipe(objectOutputStream);\n\n    const expected = [\n      { id: 1, value: 'A', processed: true, timestamp: (await objectResultPromise)[0].timestamp },\n      { id: 2, value: 'B', processed: true, timestamp: (await objectResultPromise)[1].timestamp }\n    ];\n\n    assert.deepStrictEqual(await objectResultPromise, expected);\n  });\n});","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}