mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
test: reuse parallels env helper
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user