Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: make some requires lazy in common/index #56715

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
const process = globalThis.process; // Some tests tamper with the process globalThis.

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 @@ -104,6 +102,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 @@ -232,6 +231,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 @@ -474,6 +474,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 @@ -780,6 +781,7 @@ function requireNoPackageJSONAbove(dir = __dirname) {
}

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

Expand Down Expand Up @@ -843,6 +845,7 @@ function escapePOSIXShell(cmdParts, ...args) {
* @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 @@ -920,6 +923,7 @@ const common = {
},

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

if (exports.isFreeBSD &&
Expand Down
Loading