2323const process = globalThis . process ; // Some tests tamper with the process globalThis.
2424
2525const assert = require ( 'assert' ) ;
26- const { exec, execSync, spawn, spawnSync } = require ( 'child_process' ) ;
2726const fs = require ( 'fs' ) ;
2827const net = require ( 'net' ) ;
2928// Do not require 'os' until needed so that test-os-checked-function can
3029// monkey patch it. If 'os' is required here, that test will fail.
3130const path = require ( 'path' ) ;
3231const { inspect, getCallSites } = require ( 'util' ) ;
3332const { isMainThread } = require ( 'worker_threads' ) ;
34- const { isModuleNamespaceObject } = require ( 'util/types' ) ;
3533
3634const tmpdir = require ( './tmpdir' ) ;
3735const bits = [ 'arm64' , 'loong64' , 'mips' , 'mipsel' , 'ppc64' , 'riscv64' , 's390x' , 'x64' ]
@@ -104,6 +102,7 @@ if (process.argv.length === 2 &&
104102 inspect ( flags ) ,
105103 'Use NODE_SKIP_FLAG_CHECK to run the test with the original flags.' ,
106104 ) ;
105+ const { spawnSync } = require ( 'child_process' ) ;
107106 const args = [ ...flags , ...process . execArgv , ...process . argv . slice ( 1 ) ] ;
108107 const options = { encoding : 'utf8' , stdio : 'inherit' } ;
109108 const result = spawnSync ( process . execPath , args , options ) ;
@@ -232,6 +231,7 @@ function childShouldThrowAndAbort() {
232231 // continuous testing and developers' machines
233232 escapedArgs [ 0 ] = 'ulimit -c 0 && ' + escapedArgs [ 0 ] ;
234233 }
234+ const { exec } = require ( 'child_process' ) ;
235235 const child = exec ( ...escapedArgs ) ;
236236 child . on ( 'exit' , function onExit ( exitCode , signal ) {
237237 const errMsg = 'Test should have aborted ' +
@@ -474,6 +474,7 @@ function canCreateSymLink() {
474474 'System32' , 'whoami.exe' ) ;
475475
476476 try {
477+ const { execSync } = require ( 'child_process' ) ;
477478 const output = execSync ( `${ whoamiPath } /priv` , { timeout : 1000 } ) ;
478479 return output . includes ( 'SeCreateSymbolicLinkPrivilege' ) ;
479480 } catch {
@@ -780,6 +781,7 @@ function requireNoPackageJSONAbove(dir = __dirname) {
780781}
781782
782783function spawnPromisified ( ...args ) {
784+ const { spawn } = require ( 'child_process' ) ;
783785 let stderr = '' ;
784786 let stdout = '' ;
785787
@@ -843,6 +845,7 @@ function escapePOSIXShell(cmdParts, ...args) {
843845 * @param {object } expectation shape of expected namespace.
844846 */
845847function expectRequiredModule ( mod , expectation , checkESModule = true ) {
848+ const { isModuleNamespaceObject } = require ( 'util/types' ) ;
846849 const clone = { ...mod } ;
847850 if ( Object . hasOwn ( mod , 'default' ) && checkESModule ) {
848851 assert . strictEqual ( mod . __esModule , true ) ;
@@ -920,6 +923,7 @@ const common = {
920923 } ,
921924
922925 get inFreeBSDJail ( ) {
926+ const { execSync } = require ( 'child_process' ) ;
923927 if ( inFreeBSDJail !== null ) return inFreeBSDJail ;
924928
925929 if ( exports . isFreeBSD &&
0 commit comments