Skip to content

Commit

Permalink
test: improve test coverage in child_process
Browse files Browse the repository at this point in the history
PR-URL: #26282
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
juanarbol authored and BethGriggs committed Feb 6, 2020
1 parent 8dc4e4e commit d633ba0
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions test/parallel/test-child-process-validate-stdio.js
Expand Up @@ -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
{
Expand All @@ -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];
Expand Down

0 comments on commit d633ba0

Please sign in to comment.