-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/121' of https://github.com/Sikora00/config into…
… Sikora00-feature/121
- Loading branch information
Showing
7 changed files
with
174 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { INestApplication } from '@nestjs/common'; | ||
import { Test } from '@nestjs/testing'; | ||
import { ConfigService } from '../../lib'; | ||
import { AppModule } from '../src/app.module'; | ||
|
||
describe('Cache', () => { | ||
let app: INestApplication; | ||
let envBackup: NodeJS.ProcessEnv; | ||
beforeAll(() => { | ||
envBackup = process.env; | ||
}); | ||
describe('without cache', () => { | ||
beforeAll(async () => { | ||
process.env['NAME'] = 'TEST'; | ||
const moduleRef = await Test.createTestingModule({ | ||
imports: [AppModule.withEnvVars()], | ||
}).compile(); | ||
|
||
app = moduleRef.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
it(`should return loaded env variables from vars`, () => { | ||
const configService = app.get(ConfigService); | ||
expect(configService.get('NAME')).toEqual('TEST'); | ||
}); | ||
|
||
it(`should return new vars`, () => { | ||
process.env['NAME'] = 'CHANGED'; | ||
const configService = app.get(ConfigService); | ||
expect(configService.get('NAME')).toEqual('CHANGED'); | ||
}); | ||
}); | ||
|
||
describe('with cache', () => { | ||
beforeAll(async () => { | ||
process.env['NAME'] = 'TEST'; | ||
const moduleRef = await Test.createTestingModule({ | ||
imports: [AppModule.withCache()], | ||
}).compile(); | ||
|
||
app = moduleRef.createNestApplication(); | ||
await app.init(); | ||
}); | ||
|
||
it(`should return loaded env variables from vars`, () => { | ||
const configService = app.get(ConfigService); | ||
expect(configService.get('NAME')).toEqual('TEST'); | ||
}); | ||
|
||
it(`should return cached vars`, () => { | ||
process.env['NAME'] = 'CHANGED'; | ||
const configService = app.get(ConfigService); | ||
expect(configService.get('NAME')).toEqual('TEST'); | ||
}); | ||
}); | ||
|
||
afterEach(async () => { | ||
process.env = envBackup; | ||
await app.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters