diff options
author | XadillaX <admin@xcoder.in> | 2017-06-03 13:24:05 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-06-09 13:57:24 -0400 |
commit | d00e5f1a04fa4bcf15bbeb6c0f1f6de1e8f8afd4 (patch) | |
tree | f681b9be83d5eb60910a2492c8f07d6a0a6df6ab /test/parallel/test-common.js | |
parent | 27de36926bc8c4c6937a371257039cf17f16fb0e (diff) | |
download | android-node-v8-d00e5f1a04fa4bcf15bbeb6c0f1f6de1e8f8afd4.tar.gz android-node-v8-d00e5f1a04fa4bcf15bbeb6c0f1f6de1e8f8afd4.tar.bz2 android-node-v8-d00e5f1a04fa4bcf15bbeb6c0f1f6de1e8f8afd4.zip |
test: add hijackStdout and hijackStderr
Add `common.hijackStdout` and `common.hijackStderr` to provide monitor
for console output.
PR-URL: https://github.com/nodejs/node/pull/13439
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'test/parallel/test-common.js')
-rw-r--r-- | test/parallel/test-common.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js index 0a4e1d72f0..47ed7d9f31 100644 --- a/test/parallel/test-common.js +++ b/test/parallel/test-common.js @@ -88,3 +88,23 @@ for (const p of failFixtures) { assert.strictEqual(firstLine, expected); })); } + +// hijackStderr and hijackStdout +const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ]; +[ 'err', 'out' ].forEach((txt) => { + const stream = process[`std${txt}`]; + const originalWrite = stream.write; + + common[`hijackStd${txt}`](common.mustCall(function(data) { + assert.strictEqual(data, HIJACK_TEST_ARRAY[stream.writeTimes]); + }, HIJACK_TEST_ARRAY.length)); + assert.notStrictEqual(originalWrite, stream.write); + + HIJACK_TEST_ARRAY.forEach((val) => { + stream.write(val, common.mustCall(common.noop)); + }); + + assert.strictEqual(HIJACK_TEST_ARRAY.length, stream.writeTimes); + common[`restoreStd${txt}`](); + assert.strictEqual(originalWrite, stream.write); +}); |