パッケージの詳細

stream-mock

BastienAr229.7kMIT2.0.5

Node stream mock module

stream, mock, test, writable

readme

Stream Mock

Travis (.org) npm Snyk Vulnerabilities for GitHub Repo Code Climate coverage Code Climate maintainability Greenkeeper badge node npm type definitions GitHub

Mock nodejs streams.

Features

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 } 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


License

MIT

更新履歴

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

Unreleased

2.0.5 - 2019-07-01

Changed

  • travis config to deploy

2.0.4 - 2019-07-01

Added

  • This changelog file
  • Tests
  • Link to generate types in package.json /@RAnders00

Removed

  • _writev method as pushing to an array is always sequential
  • some duplicate code with super constructors (settings encoding, objecMode, etc...)

2.0.3 - 2019-06-27

Added

  • Node.js 12.x.x now tests in CI

Fixed

  • Stop using [readable/writable]ObjectMode as they are used has readonly properties in Node.js >= 12

2.0.2 - 2019-04-13

Changed

  • Refactor the entire project in typescript

1.2.0 - 2018-05-07

Added

  • Duplex stream mock

1.1.0 - 2018-05-07

Added

  • new flatData property added to WritableMock

1.0.2 - 2018-03-12

Added

  • more tests

Fixed

  • babel-runtime dependency
  • README lint (after codeclimate report)

1.0.1 - 2018-03-12

Fixed

  • typo in README

1.0.0 - 2018-03-12

Added

  • Create a readable stream for any iterable
  • Create a writable stream that puts its datas at your disposal
  • Can operate both in object and normal (Buffer) mode