tape-drain
v0.1.0
Published
Consume readable streams automatically for tape testing
Downloads
5
Maintainers
Readme
tape-drain
Plugin for tape that adds wrappers for assertion methods that automatically consume streams in the argument position.
Write
t.drain.equal(stream, 'data');
instead of
stream.pipe({ encoding: 'string' }, function (data) {
t.equal(data, 'data');
});
Less boilerplate, cleaner tests!
Example
var tape = require('tape');
var test = require('tape-drain')(tape);
test('subject', function (t) {
// Consume stream and make an assertion.
t.drain.equal(stream, 'content');
// Consume both streams and make an assertion.
t.drain.looseEqual(stream1, stream2);
// Consume stream in "buffer mode" and make an assertion.
t.drain({ buffer: true }).same(stream, data);
});
API
tape = tapeDrain(tape)
Adds tape.Test.prototype.drain
and returns modified tape
instance.
t.drain['method']
'method'
— any method of atape.Test
instance (most of the tape's API, includingequal
,deepEqual
,looseEqual
and other methods and aliases).
Consumes any streams passed in the arguments and calls the original method
with stream arguments replaced with their actual content.
Note that the drain wrapper is asynchronous, and so you should use t.plan
rather than t.end
when using it.
t.drain([opts])['method']
Options:
opts.buffer
Type: Boolean
Default: false
Replace streams with buffers rather than with strings.
Install
npm install tape-drain
License
MIT