test: reuse parallels env helper

This commit is contained in:
Shakker
2026-06-05 01:08:02 +01:00
parent 74680e3484
commit 55c414ca81

View File

@@ -37,6 +37,7 @@ import { parseArgs as parseMacosSmokeArgs } from "../../scripts/e2e/parallels/ma
import { parseArgs as parseNpmUpdateSmokeArgs } from "../../scripts/e2e/parallels/npm-update-smoke.ts";
import { PhaseRunner } from "../../scripts/e2e/parallels/phase-runner.ts";
import { parseArgs as parseWindowsSmokeArgs } from "../../scripts/e2e/parallels/windows-smoke.ts";
import { withEnv } from "../../src/test-utils/env.js";
import { spawnNodeEvalSync } from "../../src/test-utils/node-process.js";
const WRAPPERS = {
@@ -113,27 +114,6 @@ class FakeHostServerChild extends EventEmitter {
}
}
function withEnv<T>(env: Record<string, string>, callback: () => T): T {
const previous = new Map<string, string | undefined>();
for (const [key, _value] of Object.entries(env)) {
previous.set(key, process.env[key]);
}
for (const [key, value] of Object.entries(env)) {
process.env[key] = value;
}
try {
return callback();
} finally {
for (const [key, value] of previous) {
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
}
}
async function unusedLoopbackPort(): Promise<number> {
const server = createServer();
await new Promise<void>((resolve) => {