Skip to content

Commit add6df6

Browse files
committed
fix: restore env vars in finally block to prevent test pollution
Move environment variable restoration from the try block to a finally block so env vars passed via the test harness are always cleaned up, even when the command fails and Deno's exit sanitizer intercepts the Deno.exit() call. Without this, a test that sets env vars (e.g. QUARTO_PDF_STANDARD) via TestContext.env could leak those values to subsequent tests when running in the same deno test process.
1 parent c68905f commit add6df6

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

src/quarto.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,6 @@ export async function quarto(
196196

197197
try {
198198
await promise;
199-
for (const [key, value] of Object.entries(oldEnv)) {
200-
if (value === undefined) {
201-
Deno.env.delete(key);
202-
} else {
203-
Deno.env.set(key, value);
204-
}
205-
}
206199
if (commandFailed()) {
207200
exitWithCleanup(1);
208201
}
@@ -213,6 +206,14 @@ export async function quarto(
213206
} else {
214207
throw e;
215208
}
209+
} finally {
210+
for (const [key, value] of Object.entries(oldEnv)) {
211+
if (value === undefined) {
212+
Deno.env.delete(key);
213+
} else {
214+
Deno.env.set(key, value);
215+
}
216+
}
216217
}
217218
}
218219

0 commit comments

Comments
 (0)