diff options
author | James M Snell <jasnell@gmail.com> | 2018-08-22 09:17:19 -0700 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-08-24 09:53:58 -0700 |
commit | 5da834f685f85af477afcb193d283f14a5244025 (patch) | |
tree | 1d86045f11e1cad9622be34a8a907b4972493624 /test/common/README.md | |
parent | ea8b932f30665436796c7e5abd485f048a0f41c8 (diff) | |
download | android-node-v8-5da834f685f85af477afcb193d283f14a5244025.tar.gz android-node-v8-5da834f685f85af477afcb193d283f14a5244025.tar.bz2 android-node-v8-5da834f685f85af477afcb193d283f14a5244025.zip |
test: move hijackstdio out of require('common')
Move the hijackstdio functions out of common so that they are
imported only into the tests that actually need them
PR-URL: https://github.com/nodejs/node/pull/22462
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Diffstat (limited to 'test/common/README.md')
-rw-r--r-- | test/common/README.md | 78 |
1 files changed, 48 insertions, 30 deletions
diff --git a/test/common/README.md b/test/common/README.md index e44dcd299c..487c252af3 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -173,24 +173,6 @@ Indicates whether `IPv6` is supported on this platform. Indicates if there are multiple localhosts available. -### hijackStderr(listener) -* `listener` [<Function>]: a listener with a single parameter - called `data`. - -Eavesdrop to `process.stderr.write` calls. Once `process.stderr.write` is -called, `listener` will also be called and the `data` of `write` function will -be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of -the number of calls. - -### hijackStdout(listener) -* `listener` [<Function>]: a listener with a single parameter - called `data`. - -Eavesdrop to `process.stdout.write` calls. Once `process.stdout.write` is -called, `listener` will also be called and the `data` of `write` function will -be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of -the number of calls. - ### inFreeBSDJail * [<boolean>] @@ -355,16 +337,6 @@ A port number for tests to use if one is needed. Logs '1..0 # Skipped: ' + `msg` -### restoreStderr() - -Restore the original `process.stderr.write`. Used to restore `stderr` to its -original state after calling [`common.hijackStdErr()`][]. - -### restoreStdout() - -Restore the original `process.stdout.write`. Used to restore `stdout` to its -original state after calling [`common.hijackStdOut()`][]. - ### rootDir * [<string>] @@ -596,6 +568,52 @@ validateSnapshotNodes('TLSWRAP', [ ]); ``` +## hijackstdio Module + +The `hijackstdio` module provides utility functions for temporarily redirecting +`stdout` and `stderr` output. + +<!-- eslint-disable no-undef, node-core/required-modules --> +```js +const { hijackStdout, restoreStdout } = require('../common/hijackstdio'); + +hijackStdout((data) => { + /* Do something with data */ + restoreStdout(); +}); + +console.log('this is sent to the hijacked listener'); +``` + +### hijackStderr(listener) +* `listener` [<Function>]: a listener with a single parameter + called `data`. + +Eavesdrop to `process.stderr.write()` calls. Once `process.stderr.write()` is +called, `listener` will also be called and the `data` of `write` function will +be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of +the number of calls. + +### hijackStdout(listener) +* `listener` [<Function>]: a listener with a single parameter + called `data`. + +Eavesdrop to `process.stdout.write()` calls. Once `process.stdout.write()` is +called, `listener` will also be called and the `data` of `write` function will +be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of +the number of calls. + +### restoreStderr() + +Restore the original `process.stderr.write()`. Used to restore `stderr` to its +original state after calling [`hijackstdio.hijackStdErr()`][]. + +### restoreStdout() + +Restore the original `process.stdout.write()`. Used to restore `stdout` to its +original state after calling [`hijackstdio.hijackStdOut()`][]. + + ## HTTP/2 Module The http2.js module provides a handful of utilities for creating mock HTTP/2 @@ -773,6 +791,6 @@ implementation with tests from [<boolean>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type [<number>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type [<string>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type -[`common.hijackStdErr()`]: #hijackstderrlistener -[`common.hijackStdOut()`]: #hijackstdoutlistener +[`hijackstdio.hijackStdErr()`]: #hijackstderrlistener +[`hijackstdio.hijackStdOut()`]: #hijackstdoutlistener [internationalization]: https://github.com/nodejs/node/wiki/Intl |