Capture stream output.
Install with npm:
$ npm install capture-stream --savevar capture = require('capture-stream');
var restore = capture(process.stdout);
console.log('Hello, world!!!');
console.log('foo', 'bar');
var output = restore();
console.log(output);
//=> [ [ 'Hello, world!!!\n' ], [ 'foo bar\n' ] ]Pass true to restore to return a string instead of an array of output.
var capture = require('capture-stream');
var restore = capture(process.stdout);
console.log('Hello, world!!!');
console.log('foo', 'bar');
var output = restore(true);
console.log(output);
//=> 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.
describe('awesome module', function () {
function log () {
console.log.apply(console, arguments);
}
it('should write "Hello, world!!!" to stdout', function () {
var restore = capture(process.stdout);
log('Hello, world!!!');
var output = restore();
assert.equal(output.length, 1);
assert(output[0][0].indexOf('Hello, world!!!') === 0);
});
});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 = capture(process.stdout);
console.log('Hello, world!!!');
console.log('foo', 'bar');
var output = restore();
console.log(output);
//=> [ [ 'Hello, world!!!\n' ], [ 'foo bar\n' ] ]- composer-errors: Listen for and output Composer errors. | homepage
- composer-runtimes: Write composer task start and end times to a stream. | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Generate readme and API documentation with [verb][]:
$ npm install verb && npm run docsOr, if [verb][] is installed globally:
$ verbInstall dev dependencies:
$ npm install -d && npm testBrian Woodward
Copyright © 2016 Brian Woodward Released under the MIT license.
This file was generated by verb, v0.9.0, on March 19, 2016.