@@ -7,6 +7,7 @@ import os from "node:os";
|
7 | 7 | import path from "node:path"; |
8 | 8 | import { pathToFileURL } from "node:url"; |
9 | 9 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 10 | +import { withEnvAsync } from "../../src/test-utils/env.js"; |
10 | 11 | |
11 | 12 | const tempDirs: string[] = []; |
12 | 13 | const probePath = path.resolve("scripts/e2e/lib/bundled-plugin-install-uninstall/probe.mjs"); |
@@ -97,28 +98,11 @@ function runRuntimeSmoke(root: string, args: string[]) {
|
97 | 98 | } |
98 | 99 | |
99 | 100 | async function importRuntimeSmokeWithEnv(env: Record<string, string | undefined>) { |
100 | | -const previous = new Map<string, string | undefined>(); |
101 | | -for (const [key, value] of Object.entries(env)) { |
102 | | -previous.set(key, process.env[key]); |
103 | | -if (value === undefined) { |
104 | | -delete process.env[key]; |
105 | | -} else { |
106 | | -process.env[key] = value; |
107 | | -} |
108 | | -} |
109 | | -try { |
| 101 | +return await withEnvAsync(env, async () => { |
110 | 102 | return await import( |
111 | 103 | `${pathToFileURL(runtimeSmokePath).href}?case=${Date.now()}-${Math.random()}` |
112 | 104 | ); |
113 | | -} finally { |
114 | | -for (const [key, value] of previous.entries()) { |
115 | | -if (value === undefined) { |
116 | | -delete process.env[key]; |
117 | | -} else { |
118 | | -process.env[key] = value; |
119 | | -} |
120 | | -} |
121 | | -} |
| 105 | +}); |
122 | 106 | } |
123 | 107 | |
124 | 108 | async function listenOnLoopback(server: HttpServer | NetServer): Promise<number> { |
|