-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
environment.ts
58 lines (48 loc) · 1.52 KB
/
environment.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
49
50
51
52
53
54
55
56
57
58
import { isEnv, isDevelopment, isTest } from '../environment';
describe('environment', () => {
let keepEnv: string | undefined;
beforeEach(() => {
// save the NODE_ENV
keepEnv = process.env.NODE_ENV;
});
afterEach(() => {
// restore the NODE_ENV
process.env.NODE_ENV = keepEnv;
});
describe('isEnv', () => {
it(`should match when there's a value`, () => {
['production', 'development', 'test'].forEach(env => {
process.env.NODE_ENV = env;
expect(isEnv(env)).toBe(true);
});
});
it(`should treat no proces.env.NODE_ENV as it'd be in development`, () => {
delete process.env.NODE_ENV;
expect(isEnv('development')).toBe(true);
});
});
describe('isTest', () => {
it('should return true if in test', () => {
process.env.NODE_ENV = 'test';
expect(isTest()).toBe(true);
});
it('should return true if not in test', () => {
process.env.NODE_ENV = 'development';
expect(!isTest()).toBe(true);
});
});
describe('isDevelopment', () => {
it('should return true if in development', () => {
process.env.NODE_ENV = 'development';
expect(isDevelopment()).toBe(true);
});
it('should return true if not in development and environment is defined', () => {
process.env.NODE_ENV = 'test';
expect(!isDevelopment()).toBe(true);
});
it('should make development as the default environment', () => {
delete process.env.NODE_ENV;
expect(isDevelopment()).toBe(true);
});
});
});