refactor(test): reuse env snapshot helper

This commit is contained in:
Peter Steinberger
2026-02-15 21:31:23 +00:00
parent 856e1a3187
commit aabe4d9b45
2 changed files with 21 additions and 18 deletions

18
src/test-utils/env.ts Normal file
View File

@@ -0,0 +1,18 @@
export function captureEnv(keys: string[]) {
const snapshot = new Map<string, string | undefined>();
for (const key of keys) {
snapshot.set(key, process.env[key]);
}
return {
restore() {
for (const [key, value] of snapshot) {
if (value === undefined) {
delete process.env[key];
} else {
process.env[key] = value;
}
}
},
};
}