Capture stream output.
Install with npm
$ npm i capture-stream --save
Usage
var capture = ;var restore = ; console;console; var output = ;console;//=> [ [ 'Hello, world!!!\n' ], [ 'foo bar\n' ] ]
Pass true
to restore
to return a string instead of an array of output.
var capture = ;var restore = ; console;console; var output = ;console;//=> Hello, world!!!//=> foo bar//=>
This module has been built to be used in unit tests to easily capture output from process.stdout
and process.stderr
and test the results.
;
API
captureStream
Capture the output from a stream and store later.
Params
stream
{Stream}: A stream to capture output from (e.g.process.stdout
,process.stderr
)returns
{Function}restore
: function that restores normal output and returns an array of output.
Example
var restore = ;console;console; var output = ;console;//=> [ [ 'Hello, world!!!\n' ], [ 'foo bar\n' ] ]
Related projects
- composer-errors: Listen for and output Composer errors. | homepage
- composer-runtimes: Write composer task start and end times to a stream. | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm test
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Brian Woodward
License
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb-cli on September 28, 2015.