Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

streamtest

nfroidure22.3kMIT3.0.1TypeScript support: included

Streams test library

test, streams, stream1, stream2

readme

streamtest

Streams test library

GitHub license

streamtest is a set of utils to test your stream based modules simply.

In fact, this repository's tests is a perfect example of its own usage ;).

Installation

First install streamtest in your project:

npm install --save-dev streamtest

Getting started

Then, use it:

import StreamTest from 'streamtest';

describe('My Stream Lib', () => {

  // here goes your code
  it('should work', async (done) => {
    const [outputStream, resultPromise] = StreamTest.toText();

    StreamTest.fromChunks(['a ', 'chunk', 'and', 'another'])
      .pipe(myTestedStream)
      .pipe(outputStream);

    assert.equal(await resultPromise, 'the text as i should be')
  });

});

Contribute

Feel free to submit us your improvements. To do so, you must accept to publish your code under the MIT license.

To start contributing, first run the following to setup the development environment:

git clone git@github.com:nfroidure/streamtest.git
cd streamtest
npm install

Then, run the tests:

npm test

API

StreamTest : object

Kind: global namespace

StreamTest.fromObjects(objects, timeout) ⇒

Create a readable stream streaming objects each timeout milliseconds and then end. Usefull for testing objectMode based streams.

Kind: static method of StreamTest
Returns: Readable

Param Description
objects Array<Object>
timeout number

StreamTest.fromErroredObjects(err, objects, timeout) ⇒

Create a readable stream streaming objects each timeout milliseconds, emit the err error and then end. Usefull for testing objectMode based streams.

Kind: static method of StreamTest
Returns: Readable

Param Description
err Error
objects Object[]
timeout number

StreamTest.fromChunks(chunks, timeout) ⇒

Create a readable stream streaming chunks each timeout milliseconds and then end. Usefull for testing buffer based streams.

Kind: static method of StreamTest
Returns: Readable

Param Description
chunks Buffer[]
timeout number

StreamTest.fromErroredChunks(err, objects, timeout) ⇒

Create a readable stream streaming chunks each timeout milliseconds, emit the err error and then end. Usefull for testing buffer based streams.

Kind: static method of StreamTest
Returns: Readable

Param Description
err Error
objects Object[]
timeout number

StreamTest.toObjects() ⇒

Create a writable stream collecting written objects and a promise that resolves when it finishes with the objects collected.

Kind: static method of StreamTest
Returns: [Writable, Promise<Object>]

StreamTest.toChunks() ⇒

Create a writable stream collecting written chunks and a promise that resolves when it finishes with the chunks collected.

Kind: static method of StreamTest
Returns: [Writable, Promise<Buffer[]>]

StreamTest.toText() ⇒

Create a writable stream collecting written text and a promise that resolves when it finishes with the whole text content.

Kind: static method of StreamTest
Returns: [Writable, Promise<string>]

Authors

License

MIT

changelog

3.0.1 (2024-07-17)

Bug Fixes

  • core: fix for errored streams (05390be)

3.0.0 (2024-07-16)

2.0.0 (2020-07-27)

1.2.4 (2018-06-09)

1.2.3 (2017-12-03)

v1.2.2 (2016/03/19 15:59 +00:00)

  • e147252 Bump version to 1.2.2. (@bitzl)
  • 556a4b6 Fixed internal naming. (@bitzl)
  • d998e82 Added recent versions of Node for Travis CI builds. (@bitzl)
  • 2b5d202 Replaced more strange byte value and newline combination with a regular newline (hex C2 20 --> 20). (@bitzl)
  • 1d2f53d Replaced strange byte value and newline combination with a regular newline (hex C2 20 --> 20). (@bitzl)
  • 378f6d8 Added missing semicolons. (@bitzl)
  • #1 Improved documentation. (@bitzl)
  • #2 Update dependencies to recent versions. (@bitzl)
  • 884a6d3 Update dependencies to recent veresions. (@bitzl)
  • 7be477f Improved documentation. (@bitzl)

v1.2.1 (2015/06/20 08:24 +00:00)

  • 871e169 1.2.1 (@nfroidure)
  • 21c28b0 Add mission docs on toText (@nfroidure)
  • 614b2f3 Fix toChunks behavior for v2 streams (@nfroidure)

v1.2.0 (2015/02/14 14:34 +00:00)

  • 95def34 1.2.0 (@nfroidure)
  • 0983eb1 Quickly adding sync test undocumented features (and untested) (@nfroidure)

v1.1.1 (2015/02/10 20:28 +00:00)

  • e44d7cf 1.1.1 (@nfroidure)
  • b8b696e Typo fix + better doc (@nfroidure)

v1.1.0 (2015/02/08 21:09 +00:00)

  • 774ac60 1.1.0 (@nfroidure)
  • 8fe3edb Attempt to fix node10 tests (@nfroidure)
  • fe2bc73 Triggering travis/coveralls... (@nfroidure)

v1.0.0 (2015/02/08 19:19 +00:00)

  • 035a0b6 1.0.0 (@nfroidure)
  • fe236a4 Preparing first version (@nfroidure)
  • e528d1a Adding a note (@nfroidure)
  • 1406f4b First cmmit (@nfroidure)