11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Flags: --expose-internals 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst common = require('../common'); 51cb0ef41Sopenharmony_ciconst assert = require('assert'); 61cb0ef41Sopenharmony_ciconst getValidStdio = require('internal/child_process').getValidStdio; 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst expectedError = { code: 'ERR_INVALID_ARG_VALUE', name: 'TypeError' }; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci// Should throw if string and not ignore, pipe, or inherit 111cb0ef41Sopenharmony_ciassert.throws(() => getValidStdio('foo'), expectedError); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci// Should throw if not a string or array 141cb0ef41Sopenharmony_ciassert.throws(() => getValidStdio(600), expectedError); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci// Should populate stdio with undefined if len < 3 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci const stdio1 = []; 191cb0ef41Sopenharmony_ci const result = getValidStdio(stdio1, false); 201cb0ef41Sopenharmony_ci assert.strictEqual(stdio1.length, 3); 211cb0ef41Sopenharmony_ci assert.strictEqual(Object.hasOwn(result, 'stdio'), true); 221cb0ef41Sopenharmony_ci assert.strictEqual(Object.hasOwn(result, 'ipc'), true); 231cb0ef41Sopenharmony_ci assert.strictEqual(Object.hasOwn(result, 'ipcFd'), true); 241cb0ef41Sopenharmony_ci} 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci// Should throw if stdio has ipc and sync is true 271cb0ef41Sopenharmony_ciconst stdio2 = ['ipc', 'ipc', 'ipc']; 281cb0ef41Sopenharmony_ciassert.throws(() => getValidStdio(stdio2, true), 291cb0ef41Sopenharmony_ci { code: 'ERR_IPC_SYNC_FORK', name: 'Error' } 301cb0ef41Sopenharmony_ci); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci// Should throw if stdio is not a valid input 331cb0ef41Sopenharmony_ci{ 341cb0ef41Sopenharmony_ci const stdio = ['foo']; 351cb0ef41Sopenharmony_ci assert.throws(() => getValidStdio(stdio, false), 361cb0ef41Sopenharmony_ci { code: 'ERR_INVALID_SYNC_FORK_INPUT', name: 'TypeError' } 371cb0ef41Sopenharmony_ci ); 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci// Should throw if stdio is not a valid option 411cb0ef41Sopenharmony_ci{ 421cb0ef41Sopenharmony_ci const stdio = [{ foo: 'bar' }]; 431cb0ef41Sopenharmony_ci assert.throws(() => getValidStdio(stdio), expectedError); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ciif (common.isMainThread) { 471cb0ef41Sopenharmony_ci const stdio3 = [process.stdin, process.stdout, process.stderr]; 481cb0ef41Sopenharmony_ci const result = getValidStdio(stdio3, false); 491cb0ef41Sopenharmony_ci assert.deepStrictEqual(result, { 501cb0ef41Sopenharmony_ci stdio: [ 511cb0ef41Sopenharmony_ci { type: 'fd', fd: 0 }, 521cb0ef41Sopenharmony_ci { type: 'fd', fd: 1 }, 531cb0ef41Sopenharmony_ci { type: 'fd', fd: 2 }, 541cb0ef41Sopenharmony_ci ], 551cb0ef41Sopenharmony_ci ipc: undefined, 561cb0ef41Sopenharmony_ci ipcFd: undefined 571cb0ef41Sopenharmony_ci }); 581cb0ef41Sopenharmony_ci} else { 591cb0ef41Sopenharmony_ci common.printSkipMessage( 601cb0ef41Sopenharmony_ci 'stdio is not associated with file descriptors in Workers'); 611cb0ef41Sopenharmony_ci} 62