You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

stream-mock

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stream-mock

Node stream mock module

2.0.2
Source
npmnpm
Version published
Weekly downloads
51K
-8.53%
Maintainers
1
Weekly downloads
 
Created
Source

Stream Mock

Build Status Test Coverage Maintainability Greenkeeper badge

Mock nodejs streams.

Features

  • Create a readable stream from any iterable.
  • Create a writable stream that puts its data at your disposal.
  • Create a duplex stream that combines a readable and writable stream together.
  • Can operate both in object and normal ( Buffer ) mode.

Quick start

yarn add stream-mock

Or, if you are more a npm person

npm i stream-mock

Basic usage

You are building an awesome brand new Transform stream that rounds all your values.

import { Transform } from 'stream';

export default class Rounder extends Transform {
  _transform(chunk, encoding, callback) {
    this.push(Math.round(chunk));
    callback();
  }
}

Now you need / want to test it.

import {ObjectReadableMock, ObjectWritableMock, DuplexMock } from 'stream-mock';
import chai from 'chai';

import Rounder from 'the/seven/bloody/hells';

chai.should();

describe('Test me if you can', (done) => {
    it('Round me like one of your french girls', {
        // Given
        const input = [1.2, 2.6, 3.7];
        const transform = new Rounder({objectMode: true});
        const reader = new ObjectReadableMock(input);
        const writer = new ObjectWritableMock();
        // When
        reader.pipe(transform).pipe(writer);
        // Then
        writer.on('finish', ()=>{
            writer.data.should.deep.equal(input.map(Math.round));
        })
    });
});

magic

API documentation

Full API doc is hosted here

Contributing

stream-mock is currently on early stage. I'm happily receiving new PR or discussing about new features, improvement or bug report. If you need something that this module is lacking (related to Nodejs stream mock obviously), do not hesitate to raise an issue.

Developper side

To run test :

yarn run test

Linter is run on commit hook base.

Thats all folks

License

MIT

Keywords

stream

FAQs

Package last updated on 13 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts