Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.11 KB

.verb.md

File metadata and controls

51 lines (39 loc) · 1.11 KB

Usage

var capture = require('{%= name %}');
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('{%= name %}');
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);
  });
});

API

{%= apidocs("index.js") %}