Skip to content

Commit

Permalink
test(@nestjs/config) reset env correctly
Browse files Browse the repository at this point in the history
process.env does not reset correctly.
assgin copy value of origin process.env in beforeAll
and reset process.env with value of envBackup
  • Loading branch information
bejewel-kyoungmin committed Mar 22, 2024
1 parent 7a7dc4d commit 6498d2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions tests/e2e/cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -56,7 +58,9 @@ describe('Cache', () => {
});

afterEach(async () => {
process.env = envBackup;
process.env = {
...envBackup,
};
await app.close();
});
});
8 changes: 6 additions & 2 deletions tests/e2e/load-priority.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -65,7 +67,9 @@ describe('Environment variables and .env files', () => {
});

afterEach(async () => {
process.env = envBackup;
process.env = {
...envBackup,
};
await app.close();
});
});

0 comments on commit 6498d2b

Please sign in to comment.