Skip to content

Mock node stdout and stderr without pain.

License

Notifications You must be signed in to change notification settings

gregberge/std-mocks

Repository files navigation

std-mocks

Mock node stdout and stderr without pain.

Install

npm install std-mocks

Usage

var stdMocks = require("std-mocks");

stdMocks.use();
process.stdout.write("ok");
console.log("log test\n");
stdMocks.restore();

var output = stdMocks.flush();
console.log(output.stdout); // ['ok', 'log test\n']

stdMocks.use([options])

Start mocking std output, by default both are mocked.

Options:

@param {object} [options] Options
@param {boolean} [options.stdout=true] Mock stdout
@param {boolean} [options.stderr=true] Mock stderr
@param {boolean} [options.print=false] Also print to std

stdMocks.restore([options])

Restore std output, by default both are restored.

Options:

@param {object} [options] Options
@param {boolean} [options.stdout=true] Mock stdout
@param {boolean} [options.stderr=true] Mock stderr

stdMocks.flush([options])

Flush collected data, by default both are collected.

Options:

@param {object} [options] Options
@param {boolean} [options.stdout=true] Mock stdout
@param {boolean} [options.stderr=true] Mock stderr
@returns {object} Object containing two array corresponding to outputs.

License

MIT

About

Mock node stdout and stderr without pain.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •