diff --git a/test/scripts/bench-cli-startup.test.ts b/test/scripts/bench-cli-startup.test.ts index 2b99e9485db..5b02033a23c 100644 --- a/test/scripts/bench-cli-startup.test.ts +++ b/test/scripts/bench-cli-startup.test.ts @@ -4,31 +4,9 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { testing } from "../../scripts/bench-cli-startup.ts"; +import { withEnv } from "../../src/test-utils/env.js"; import { createTempDirTracker } from "../helpers/temp-dir.js"; -function withEnv(env: Record, callback: () => T): T { - const previous = new Map(); - for (const [key, value] of Object.entries(env)) { - previous.set(key, process.env[key]); - if (value === undefined) { - delete process.env[key]; - } else { - 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; - } - } - } -} - function isProcessAlive(pid: number): boolean { try { process.kill(pid, 0);