From d633ba07e37763d8a384c63b01e001f5d12e3d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Arboleda?= Date: Sun, 24 Feb 2019 00:22:46 -0500 Subject: [PATCH] test: improve test coverage in child_process PR-URL: https://github.com/nodejs/node/pull/26282 Reviewed-By: Ruben Bridgewater Reviewed-By: Michael Dawson Reviewed-By: Yongsheng Zhang Reviewed-By: Rich Trott --- .../test-child-process-validate-stdio.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-child-process-validate-stdio.js b/test/parallel/test-child-process-validate-stdio.js index 23b3fe2c95a877..38d2f1c8187ee9 100644 --- a/test/parallel/test-child-process-validate-stdio.js +++ b/test/parallel/test-child-process-validate-stdio.js @@ -5,14 +5,13 @@ const common = require('../common'); const assert = require('assert'); const getValidStdio = require('internal/child_process').getValidStdio; -const expectedError = - common.expectsError({ code: 'ERR_INVALID_OPT_VALUE', type: TypeError }, 2); +const expectedError = { code: 'ERR_INVALID_OPT_VALUE', type: TypeError }; // Should throw if string and not ignore, pipe, or inherit -assert.throws(() => getValidStdio('foo'), expectedError); +common.expectsError(() => getValidStdio('foo'), expectedError); // Should throw if not a string or array -assert.throws(() => getValidStdio(600), expectedError); +common.expectsError(() => getValidStdio(600), expectedError); // Should populate stdio with undefined if len < 3 { @@ -30,6 +29,19 @@ common.expectsError(() => getValidStdio(stdio2, true), { code: 'ERR_IPC_SYNC_FORK', type: Error } ); +// Should throw if stdio is not a valid input +{ + const stdio = ['foo']; + common.expectsError(() => getValidStdio(stdio, false), + { code: 'ERR_INVALID_SYNC_FORK_INPUT', type: TypeError } + ); +} + +// Should throw if stdio is not a valid option +{ + const stdio = [{ foo: 'bar' }]; + common.expectsError(() => getValidStdio(stdio), expectedError); +} if (common.isMainThread) { const stdio3 = [process.stdin, process.stdout, process.stderr];