https://github.com/jchip/xstdout
capture stdout
https://github.com/jchip/xstdout
Last synced: over 1 year ago
JSON representation
capture stdout
- Host: GitHub
- URL: https://github.com/jchip/xstdout
- Owner: jchip
- Created: 2017-06-14T16:25:26.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-14T18:39:46.000Z (about 9 years ago)
- Last Synced: 2025-02-21T16:48:45.348Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
[![Dependency Status][daviddm-image]][daviddm-url] [![devDependency Status][daviddm-dev-image]][daviddm-dev-url]
# xstdout
capture stdout
# Usage
Example:
```js
const xstdout = require("xstdout");
const intercept = xstdout.intercept(true);
console.log("hello, world");
intercept.restore();
expect(intercept.stdout[0]).to.equal("hello, world\n");
```
## APIs
### `xstdout.intercept(silent, [silentErr])`
Returns an object:
```js
{
restore,
stdout,
stderr
}
```
- `stdout`/`stderr` are arrays of strings that captured stdout/stderr
- `restore` is a function that restores the original stdout/stderr
#### Params
- `silent` - if `true`, then omit actual output to console and only capture
- `silentErr` - if not `undefined`, then independently controls output of stderr to console
[travis-image]: https://travis-ci.org/jchip/xstdout.svg?branch=master
[travis-url]: https://travis-ci.org/jchip/xstdout
[npm-image]: https://badge.fury.io/js/xstdout.svg
[npm-url]: https://npmjs.org/package/xstdout
[daviddm-image]: https://david-dm.org/jchip/xstdout/status.svg
[daviddm-url]: https://david-dm.org/jchip/xstdout
[daviddm-dev-image]: https://david-dm.org/jchip/xstdout/dev-status.svg
[daviddm-dev-url]: https://david-dm.org/jchip/xstdout?type=dev