11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ci// Ensures that child_process.fork can accept string 51cb0ef41Sopenharmony_ci// variant of stdio parameter in options object and 61cb0ef41Sopenharmony_ci// throws a TypeError when given an unexpected string 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst assert = require('assert'); 91cb0ef41Sopenharmony_ciconst fork = require('child_process').fork; 101cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst childScript = fixtures.path('child-process-spawn-node'); 131cb0ef41Sopenharmony_ciconst malFormedOpts = { stdio: '33' }; 141cb0ef41Sopenharmony_ciconst payload = { hello: 'world' }; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciassert.throws( 171cb0ef41Sopenharmony_ci () => fork(childScript, malFormedOpts), 181cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError' }); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifunction test(stringVariant) { 211cb0ef41Sopenharmony_ci const child = fork(childScript, { stdio: stringVariant }); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci child.on('message', common.mustCall((message) => { 241cb0ef41Sopenharmony_ci assert.deepStrictEqual(message, { foo: 'bar' }); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci child.send(payload); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci child.on('exit', common.mustCall((code) => assert.strictEqual(code, 0))); 301cb0ef41Sopenharmony_ci} 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci['pipe', 'inherit', 'ignore'].forEach(test); 33