-
-
Notifications
You must be signed in to change notification settings - Fork 27k
/
Copy pathenv.test.js
86 lines (74 loc) · 2.43 KB
/
env.test.js
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import initDOM from './initDOM';
describe('Integration', () => {
describe('Environment variables', () => {
let doc;
afterEach(() => {
doc && doc.defaultView.close();
doc = undefined;
});
it('file env variables', async () => {
doc = await initDOM('file-env-variables');
expect(
doc.getElementById('feature-file-env-original-1').textContent
).toBe('from-original-env-1');
expect(
doc.getElementById('feature-file-env-original-2').textContent
).toBe('override-from-original-local-env-2');
if (process.env.NODE_ENV === 'production') {
expect(doc.getElementById('feature-file-env').textContent).toBe(
'production'
);
expect(doc.getElementById('feature-file-env-x').textContent).toBe(
'x-from-production-env'
);
} else {
expect(doc.getElementById('feature-file-env').textContent).toBe(
'development'
);
expect(doc.getElementById('feature-file-env-x').textContent).toBe(
'x-from-development-env'
);
}
});
it('PUBLIC_URL', async () => {
doc = await initDOM('public-url');
const prefix =
process.env.NODE_ENV === 'development'
? ''
: 'http://www.example.org/spa';
expect(doc.getElementById('feature-public-url').textContent).toBe(
`${prefix}.`
);
expect(
doc.querySelector('head link[rel="shortcut icon"]').getAttribute('href')
).toBe(`${prefix}/favicon.ico`);
});
it('shell env variables', async () => {
doc = await initDOM('shell-env-variables');
expect(
doc.getElementById('feature-shell-env-variables').textContent
).toBe('fromtheshell.');
});
it('expand .env variables', async () => {
doc = await initDOM('expand-env-variables');
expect(doc.getElementById('feature-expand-env-1').textContent).toBe(
'basic'
);
expect(doc.getElementById('feature-expand-env-2').textContent).toBe(
'basic'
);
expect(doc.getElementById('feature-expand-env-3').textContent).toBe(
'basic'
);
expect(
doc.getElementById('feature-expand-env-existing').textContent
).toBe('fromtheshell');
});
});
});