Skip to content

Commit

Permalink
test: make some requires lazy in common/index
Browse files Browse the repository at this point in the history
  • Loading branch information
jasnell committed Jan 23, 2025
1 parent 309924f commit dfea11d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@
const process = global.process; // Some tests tamper with the process global.

const assert = require('assert');
const { exec, execSync, spawn, spawnSync } = require('child_process');
const fs = require('fs');
const net = require('net');
// Do not require 'os' until needed so that test-os-checked-function can
// monkey patch it. If 'os' is required here, that test will fail.
const path = require('path');
const { inspect, getCallSites } = require('util');
const { isMainThread } = require('worker_threads');
const { isModuleNamespaceObject } = require('util/types');

const tmpdir = require('./tmpdir');
const bits = ['arm64', 'loong64', 'mips', 'mipsel', 'ppc64', 'riscv64', 's390x', 'x64']
Expand Down Expand Up @@ -124,6 +122,7 @@ if (process.argv.length === 2 &&
inspect(flags),
'Use NODE_SKIP_FLAG_CHECK to run the test with the original flags.',
);
const { spawnSync } = require('child_process');
const args = [...flags, ...process.execArgv, ...process.argv.slice(1)];
const options = { encoding: 'utf8', stdio: 'inherit' };
const result = spawnSync(process.execPath, args, options);
Expand Down Expand Up @@ -255,6 +254,7 @@ function childShouldThrowAndAbort() {
// continuous testing and developers' machines
escapedArgs[0] = 'ulimit -c 0 && ' + escapedArgs[0];
}
const { exec } = require('child_process');
const child = exec(...escapedArgs);
child.on('exit', function onExit(exitCode, signal) {
const errMsg = 'Test should have aborted ' +
Expand Down Expand Up @@ -539,6 +539,7 @@ function canCreateSymLink() {
'System32', 'whoami.exe');

try {
const { execSync } = require('child_process');
const output = execSync(`${whoamiPath} /priv`, { timeout: 1000 });
return output.includes('SeCreateSymbolicLinkPrivilege');
} catch {
Expand Down Expand Up @@ -857,6 +858,7 @@ function requireNoPackageJSONAbove(dir = __dirname) {
}

function spawnPromisified(...args) {
const { spawn } = require('child_process');
let stderr = '';
let stdout = '';

Expand Down Expand Up @@ -959,6 +961,7 @@ function getPrintedStackTrace(stderr) {
* @param {object} expectation shape of expected namespace.
*/
function expectRequiredModule(mod, expectation, checkESModule = true) {
const { isModuleNamespaceObject } = require('util/types');
const clone = { ...mod };
if (Object.hasOwn(mod, 'default') && checkESModule) {
assert.strictEqual(mod.__esModule, true);
Expand Down Expand Up @@ -1052,6 +1055,7 @@ const common = {
},

get inFreeBSDJail() {
const { execSync } = require('child_process');
if (inFreeBSDJail !== null) return inFreeBSDJail;

if (exports.isFreeBSD &&
Expand Down Expand Up @@ -1114,6 +1118,7 @@ const common = {

if (exports.isWindows) opensslCli += '.exe';

const { spawnSync } = require('child_process');
const opensslCmd = spawnSync(opensslCli, ['version']);
if (opensslCmd.status !== 0 || opensslCmd.error !== undefined) {
// OpenSSL command cannot be executed
Expand Down

0 comments on commit dfea11d

Please sign in to comment.