From 6498d2b2724c0552053836960f44b996665ff1ed Mon Sep 17 00:00:00 2001 From: kyoungminkim Date: Fri, 22 Mar 2024 15:06:20 +0900 Subject: [PATCH] test(@nestjs/config) reset env correctly process.env does not reset correctly. assgin copy value of origin process.env in beforeAll and reset process.env with value of envBackup --- tests/e2e/cache.spec.ts | 8 ++++++-- tests/e2e/load-priority.spec.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/e2e/cache.spec.ts b/tests/e2e/cache.spec.ts index b5e49942..919047b5 100644 --- a/tests/e2e/cache.spec.ts +++ b/tests/e2e/cache.spec.ts @@ -7,7 +7,9 @@ describe('Cache', () => { let app: INestApplication; let envBackup: NodeJS.ProcessEnv; beforeAll(() => { - envBackup = process.env; + envBackup = { + ...process.env, + }; }); describe('without cache', () => { beforeAll(async () => { @@ -56,7 +58,9 @@ describe('Cache', () => { }); afterEach(async () => { - process.env = envBackup; + process.env = { + ...envBackup, + }; await app.close(); }); }); diff --git a/tests/e2e/load-priority.spec.ts b/tests/e2e/load-priority.spec.ts index 456aa8ac..1a56a0c4 100644 --- a/tests/e2e/load-priority.spec.ts +++ b/tests/e2e/load-priority.spec.ts @@ -8,7 +8,9 @@ describe('Environment variables and .env files', () => { let app: INestApplication; let envBackup: NodeJS.ProcessEnv; beforeAll(() => { - envBackup = process.env; + envBackup = { + ...process.env, + }; }); describe('without conflicts', () => { beforeAll(async () => { @@ -65,7 +67,9 @@ describe('Environment variables and .env files', () => { }); afterEach(async () => { - process.env = envBackup; + process.env = { + ...envBackup, + }; await app.close(); }); });