-
Notifications
You must be signed in to change notification settings - Fork 2
/
process.e2e-spec.ts
48 lines (42 loc) 路 1.43 KB
/
process.e2e-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint-disable max-classes-per-file */
import { Module } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { ConfigModule } from '../src';
import { FirstConfig } from './fixtures/first.config';
import { SecondConfig } from './fixtures/second.config';
import { TestModule } from './fixtures/test.module';
describe('Process', () => {
it('override', async () => {
Object.assign(process.env, {
FIRST__STRING_VAR: 'stringVar',
FIRST__STRING_VAR_WITH_DEFAULT: 'stringVarWithDefault',
FIRST__INT_VAR: '1',
FIRST__INT_VAR_WITH_DEFAULT: '7',
FIRST__NUMBER_VAR: '1.1',
FIRST__NUMBER_VAR_WITH_DEFAULT: '7.7',
FIRST__BOOL_VAR: 'true',
FIRST__BOOL_VAR_WITH_DEFAULT: 'true',
});
@Module({
imports: [ConfigModule.forRoot({ configs: [FirstConfig] }), TestModule],
})
class AppModule {}
const app = await NestFactory.createApplicationContext(AppModule);
const firstConfig = app.get<FirstConfig>(FirstConfig);
const secondConfig = app.get<SecondConfig>(SecondConfig);
expect(firstConfig).toMatchObject({
stringVar: 'stringVar',
stringVarWithDefault: 'stringVarWithDefault',
intVar: 1,
intVarWithDefault: 7,
numberVar: 1.1,
numberVarWithDefault: 7.7,
boolVar: true,
boolVarWithDefault: true,
});
expect(secondConfig).toMatchObject({
variable: 'value',
});
await app.close();
});
});