diff --git a/test/scripts/plugin-index-sqlite.test.ts b/test/scripts/plugin-index-sqlite.test.ts index 4d29c9404b63..60bedf3596fe 100644 --- a/test/scripts/plugin-index-sqlite.test.ts +++ b/test/scripts/plugin-index-sqlite.test.ts @@ -5,24 +5,15 @@ import path from "node:path"; import { DatabaseSync } from "node:sqlite"; import { pathToFileURL } from "node:url"; import { describe, expect, it } from "vitest"; +import { withEnvAsync } from "../../src/test-utils/env.js"; const MODULE_URL = pathToFileURL(path.resolve("scripts/e2e/lib/plugin-index-sqlite.mjs")).href; let importCounter = 0; async function loadPluginIndex(env: Record = {}) { - const previous = new Map(Object.keys(env).map((key) => [key, process.env[key]])); - Object.assign(process.env, env); - try { + return await withEnvAsync(env, async () => { return await import(`${MODULE_URL}?case=${importCounter++}`); - } finally { - for (const [key, value] of previous) { - if (value === undefined) { - delete process.env[key]; - } else { - process.env[key] = value; - } - } - } + }); } function writeLegacyIndex(root: string, text: string) {