diff options
author | Tobias Nießen <tniessen@tnie.de> | 2017-06-30 20:46:11 +0200 |
---|---|---|
committer | Tobias Nießen <tniessen@tnie.de> | 2017-07-03 16:33:03 +0200 |
commit | fe730d34ce5d93e61341915007ef2a6504e63e2e (patch) | |
tree | 422bccaa64369e26183a20b1fee1c2e39d6f0534 /test/parallel/test-child-process-constructor.js | |
parent | 44256bb0aaa54df60ec3d2c53bcfe7004fb61427 (diff) | |
download | android-node-v8-fe730d34ce5d93e61341915007ef2a6504e63e2e.tar.gz android-node-v8-fe730d34ce5d93e61341915007ef2a6504e63e2e.tar.bz2 android-node-v8-fe730d34ce5d93e61341915007ef2a6504e63e2e.zip |
child_process: use internal/errors
PR-URL: https://github.com/nodejs/node/pull/14009
Refs: https://github.com/nodejs/node/issues/11273
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Diffstat (limited to 'test/parallel/test-child-process-constructor.js')
-rw-r--r-- | test/parallel/test-child-process-constructor.js | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/test/parallel/test-child-process-constructor.js b/test/parallel/test-child-process-constructor.js index 54052d9f71..ea81f80606 100644 --- a/test/parallel/test-child-process-constructor.js +++ b/test/parallel/test-child-process-constructor.js @@ -5,51 +5,71 @@ const assert = require('assert'); const { ChildProcess } = require('child_process'); assert.strictEqual(typeof ChildProcess, 'function'); +function typeName(value) { + return value === null ? 'null' : typeof value; +} + { // Verify that invalid options to spawn() throw. const child = new ChildProcess(); - const re = /^TypeError: "options" must be an object$/; [undefined, null, 'foo', 0, 1, NaN, true, false].forEach((options) => { assert.throws(() => { child.spawn(options); - }, re); + }, common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options" argument must be of type object. Received type ' + + typeName(options) + })); }); } { // Verify that spawn throws if file is not a string. const child = new ChildProcess(); - const re = /^TypeError: "file" must be a string$/; [undefined, null, 0, 1, NaN, true, false, {}].forEach((file) => { assert.throws(() => { child.spawn({ file }); - }, re); + }, common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options.file" property must be of type string. Received ' + + 'type ' + typeName(file) + })); }); } { // Verify that spawn throws if envPairs is not an array or undefined. const child = new ChildProcess(); - const re = /^TypeError: "envPairs" must be an array$/; [null, 0, 1, NaN, true, false, {}, 'foo'].forEach((envPairs) => { assert.throws(() => { child.spawn({ envPairs, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] }); - }, re); + }, common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options.envPairs" property must be of type array. ' + + 'Received type ' + typeName(envPairs) + })); }); } { // Verify that spawn throws if args is not an array or undefined. const child = new ChildProcess(); - const re = /^TypeError: "args" must be an array$/; [null, 0, 1, NaN, true, false, {}, 'foo'].forEach((args) => { assert.throws(() => { child.spawn({ file: 'foo', args }); - }, re); + }, common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "options.args" property must be of type array. Received ' + + 'type ' + typeName(args) + })); }); } |