{"library":"stream-mock","title":"Node.js Stream Mocking Utilities","type":"library","description":"stream-mock is a Node.js library designed for creating mock Readable, Writable, and Duplex streams, primarily for testing purposes. The current stable version is 2.0.5, with a release cadence that shows active maintenance and feature additions, such as the introduction of Duplex stream support in v1.2.0 and a complete refactoring to TypeScript in v2.0.2. This refactoring enhances type safety and developer experience for TypeScript users. Key differentiators include its ability to create readable streams from any iterable, provide direct access to data written to a mock writable stream through properties like `data` or `flatData`, and support for both object and buffer modes. It simplifies unit testing of custom stream transformations by providing controllable input and verifiable output mechanisms.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install stream-mock"],"cli":null},"imports":["import { ObjectReadableMock } from 'stream-mock'","import { ObjectWritableMock } from 'stream-mock'","import { DuplexMock } from 'stream-mock'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/BastienAr/stream-mock","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stream-mock","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { Transform } from 'stream';\nimport { ObjectReadableMock, ObjectWritableMock } from 'stream-mock';\nimport chai from 'chai';\n\n// Imagine this is your custom Transform stream to test\nclass Rounder extends Transform {\n  _transform(chunk, encoding, callback) {\n    this.push(Math.round(chunk));\n    callback();\n  }\n}\n\nchai.should();\n\ndescribe('Test Rounder Transform Stream', () => {\n  it('should round numbers piped through it', (done) => {\n    // Given\n    const input = [1.2, 2.6, 3.7];\n    const transform = new Rounder({ objectMode: true });\n    const reader = new ObjectReadableMock(input);\n    const writer = new ObjectWritableMock();\n\n    // When\n    reader.pipe(transform).pipe(writer);\n\n    // Then\n    writer.on('finish', () => {\n      writer.data.should.deep.equal(input.map(Math.round));\n      done();\n    });\n  });\n});","lang":"javascript","description":"Demonstrates how to test a custom Transform stream using `ObjectReadableMock` for input and `ObjectWritableMock` to capture output, asserting the transformed data.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}