summaryrefslogtreecommitdiff
path: root/test/parallel/test-common.js
diff options
context:
space:
mode:
authorXadillaX <admin@xcoder.in>2017-08-06 14:16:05 +0800
committerJames M Snell <jasnell@gmail.com>2017-08-29 10:48:53 -0700
commit1ffd01cf7fbf66b1bd9bdf5ae6630cdf228f0a3b (patch)
treea970dd709a519da32c11cc2c1f3e05ac61d16331 /test/parallel/test-common.js
parent5c0d64ea11fe559f6309c3eff82c4f4f3904e808 (diff)
downloadandroid-node-v8-1ffd01cf7fbf66b1bd9bdf5ae6630cdf228f0a3b.tar.gz
android-node-v8-1ffd01cf7fbf66b1bd9bdf5ae6630cdf228f0a3b.tar.bz2
android-node-v8-1ffd01cf7fbf66b1bd9bdf5ae6630cdf228f0a3b.zip
test: fix hijackStdout behavior in console
`console.log` and some other function will swallow the exception in `stdout.write`. So an asynchronous exception is needed, or `common.hijackStdout` won't detect some exception. Refs: https://github.com/nodejs/node/blob/v8.2.1/lib/console.js#L87 PR-URL: https://github.com/nodejs/node/pull/14647 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test/parallel/test-common.js')
-rw-r--r--test/parallel/test-common.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/parallel/test-common.js b/test/parallel/test-common.js
index 7fee3e0b84..647c39d939 100644
--- a/test/parallel/test-common.js
+++ b/test/parallel/test-common.js
@@ -108,3 +108,26 @@ const HIJACK_TEST_ARRAY = [ 'foo\n', 'bar\n', 'baz\n' ];
common[`restoreStd${txt}`]();
assert.strictEqual(originalWrite, stream.write);
});
+
+// hijackStderr and hijackStdout again
+// for console
+[[ 'err', 'error' ], [ 'out', 'log' ]].forEach(([ type, method ]) => {
+ common[`hijackStd${type}`](common.mustCall(function(data) {
+ assert.strictEqual(data, 'test\n');
+
+ // throw an error
+ throw new Error(`console ${type} error`);
+ }));
+
+ console[method]('test');
+ common[`restoreStd${type}`]();
+});
+
+let uncaughtTimes = 0;
+process.on('uncaughtException', common.mustCallAtLeast(function(e) {
+ assert.strictEqual(uncaughtTimes < 2, true);
+ assert.strictEqual(e instanceof Error, true);
+ assert.strictEqual(
+ e.message,
+ `console ${([ 'err', 'out' ])[uncaughtTimes++]} error`);
+}, 2));