-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: add string shortcut for fork stdio
Add string shortcut option for stdio parameter. Fixes: #10793 PR-URL: #10866 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Brian White <mscdex@mscdex.net>
- Loading branch information
1 parent
b6d2fc9
commit 3268863
Showing
3 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
test/parallel/test-child-process-fork-stdio-string-variant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
// Ensures that child_process.fork can accept string | ||
// variant of stdio parameter in options object and | ||
// throws a TypeError when given an unexpected string | ||
|
||
const assert = require('assert'); | ||
const fork = require('child_process').fork; | ||
|
||
const childScript = `${common.fixturesDir}/child-process-spawn-node`; | ||
const errorRegexp = /^TypeError: Unknown stdio option$/; | ||
const malFormedOpts = {stdio: '33'}; | ||
const payload = {hello: 'world'}; | ||
const stringOpts = {stdio: 'pipe'}; | ||
|
||
assert.throws(() => fork(childScript, malFormedOpts), errorRegexp); | ||
|
||
const child = fork(childScript, stringOpts); | ||
|
||
child.on('message', (message) => { | ||
assert.deepStrictEqual(message, {foo: 'bar'}); | ||
}); | ||
|
||
child.send(payload); | ||
|
||
child.on('exit', common.mustCall((code) => assert.strictEqual(code, 0))); |