fixture-stdout
A test fixture to intercept writes to stdout.
Last updated 6 years ago by balderdashy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fixture-stdout 
SYNC missed versions from official npm registry.

fixture-stdout

A test fixture to intercept writes to stdout.

Install:

npm install fixture-stdout

Example Usage:

var StdOutFixture = require('fixture-stdout');
var fixture = new StdOutFixture();

// Keep track of writes so we can check them later..
var _writes = [];

// Capture a write to stdout
fixture.capture( function onWrite (string, encoding, fd) {
  _writes.push({
    string: string,
    encoding: encoding,
    fd: fd
  });


  // If you return `false`, you'll prevent the write to the original stream (useful for preventing log output during tests.)
  return false;

});

// Uses intercepted version of stdout
console.log('a');
console.log('b');

fixture.release();

// Now we're back to the original version of stdout
console.log('c');
console.log('d');

// Voila!
// Only the first two logs ("a" and "b") are in our `_writes` array

Watch streams other than stdout:

var Fixture = require('fixture-stdout');

var fixture = new Fixture({
	stream: process.stderr
});

fixture.capture();
console.error('hello world');
fixture.release();
console.error('world');

Credit

Based on @pguillory's example.

License

MIT

Current Tags

  • 0.0.0                                ...           beta (6 years ago)
  • 0.2.1                                ...           latest (6 years ago)

4 Versions

  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 6
Last Day 0
Last Week 5
Last Month 22
Dependencies (0)
None
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |