2017-01-18 02:22:37 -05:00
|
|
|
'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`;
|
2017-01-30 13:52:09 -08:00
|
|
|
const errorRegexp = /^TypeError: Incorrect value of stdio option:/;
|
2017-01-18 02:22:37 -05:00
|
|
|
const malFormedOpts = {stdio: '33'};
|
|
|
|
const payload = {hello: 'world'};
|
|
|
|
|
|
|
|
assert.throws(() => fork(childScript, malFormedOpts), errorRegexp);
|
|
|
|
|
2017-03-09 23:15:14 -08:00
|
|
|
function test(stringVariant) {
|
|
|
|
const child = fork(childScript, {stdio: stringVariant});
|
2017-01-18 02:22:37 -05:00
|
|
|
|
2017-03-09 23:15:14 -08:00
|
|
|
child.on('message', common.mustCall((message) => {
|
|
|
|
assert.deepStrictEqual(message, {foo: 'bar'});
|
|
|
|
}));
|
2017-01-18 02:22:37 -05:00
|
|
|
|
2017-03-09 23:15:14 -08:00
|
|
|
child.send(payload);
|
2017-01-18 02:22:37 -05:00
|
|
|
|
2017-03-09 23:15:14 -08:00
|
|
|
child.on('exit', common.mustCall((code) => assert.strictEqual(code, 0)));
|
|
|
|
}
|
|
|
|
|
|
|
|
['pipe', 'inherit', 'ignore'].forEach(test);
|