Skip to content

Commit 36b02bf

Browse files
jasnelladuh95
authored andcommitted
test: make some requires lazy in common/index
PR-URL: #56715 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 55a0135 commit 36b02bf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/common/index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
const process = globalThis.process; // Some tests tamper with the process globalThis.
2424

2525
const assert = require('assert');
26-
const { exec, execSync, spawn, spawnSync } = require('child_process');
2726
const fs = require('fs');
2827
const 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.
3130
const path = require('path');
3231
const { inspect, getCallSites } = require('util');
3332
const { isMainThread } = require('worker_threads');
34-
const { isModuleNamespaceObject } = require('util/types');
3533

3634
const tmpdir = require('./tmpdir');
3735
const 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

782783
function 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
*/
845847
function 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

Comments
 (0)