Skip to content

Commit 8f89ee5

Browse files
committed
Copy properties back onto process.env rather than overwriting it
Copy the properties rather than directly overwriting `process.env` to preserve behaviour like aliasing `process.env.PATH` with `process.env.Path` on Windows.
1 parent c4e8011 commit 8f89ee5

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

lib/testing-utils.js

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/testing-utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/testing-utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,17 @@ export function setupTests(test: TestFn<any>) {
8383
sinon.restore();
8484

8585
// Undo any modifications to the env
86-
process.env = t.context.env;
86+
// Copy the properties rather than directly overwriting `process.env` to
87+
// preserve behaviour like aliasing `process.env.PATH` with
88+
// `process.env.Path` on Windows.
89+
console.log("Process env before", process.env);
90+
console.log("Stored env", t.context.env);
91+
for (const key of Object.keys(process.env)) {
92+
delete process.env[key];
93+
}
94+
console.log("Process env after deleting", process.env);
95+
Object.assign(process.env, t.context.env);
96+
console.log("Process env after resetting", process.env);
8797
});
8898
}
8999

0 commit comments

Comments
 (0)