0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-child-process-fork-stdio-string-variant.js
Rich Trott 78cdd4baa4 test: include all stdio strings for fork()
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>
2017-03-13 11:42:30 -07:00

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);