reset environment variables between tests

This commit is contained in:
Robert 2020-07-21 11:24:37 +01:00
parent ee63f4ee4b
commit 29cf06569d
6 changed files with 28 additions and 3 deletions

7
lib/testing-utils.js generated
View file

@ -51,6 +51,11 @@ function setupTests(test) {
const processStderrWrite = process.stderr.write.bind(process.stderr);
t.context.stderrWrite = processStderrWrite;
process.stderr.write = wrapOutput(t.context);
// Many tests modify environment variables. Take a copy now so that
// We reset them after the test to keep tests independent of each other.
// process.env only has strings fields, so a shallow copy is fine.
t.context.env = {};
Object.assign(process.env, t.context.env);
});
typedTest.afterEach.always(t => {
// Restore stdout and stderr
@ -62,6 +67,8 @@ function setupTests(test) {
}
// Undo any modifications made by sinon
sinon_1.default.restore();
// Undo any modifications to the env
process.env = t.context.env;
});
}
exports.setupTests = setupTests;