mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
78cdd4baa4
test-child-process-fork-stdio-string-variant was only testing 'pipe' for its `stdio` value. Add `inherit` and `ignore`. Also added a `common.mustCall()` to verify that the `message` event is triggered. PR-URL: https://github.com/nodejs/node/pull/11783 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
31 lines
921 B
JavaScript
31 lines
921 B
JavaScript
'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: Incorrect value of stdio option:/;
|
|
const malFormedOpts = {stdio: '33'};
|
|
const payload = {hello: 'world'};
|
|
|
|
assert.throws(() => fork(childScript, malFormedOpts), errorRegexp);
|
|
|
|
function test(stringVariant) {
|
|
const child = fork(childScript, {stdio: stringVariant});
|
|
|
|
child.on('message', common.mustCall((message) => {
|
|
assert.deepStrictEqual(message, {foo: 'bar'});
|
|
}));
|
|
|
|
child.send(payload);
|
|
|
|
child.on('exit', common.mustCall((code) => assert.strictEqual(code, 0)));
|
|
}
|
|
|
|
['pipe', 'inherit', 'ignore'].forEach(test);
|