-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.test.ts
101 lines (95 loc) · 2.39 KB
/
main.test.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { join } from "../research/utils"
import { main } from "./main"
describe(main.name, () => {
it("demo", () => {
const files: Record<string, string> = {
"npm0": "OVERWRITE=true",
"npm1": "NPM1=Loaded",
"arg0": "ARG0=Loaded",
"arg1": "ARG1=Loaded",
"env": "ENV=Loaded",
"env0": "ENV0=Loaded",
"env1": "ENV1=Loaded"
}
, env = {
"npm_package_config_env_file_0": "npm0",
"npm_package_config_env_file_1": "npm1",
"ENV_FILE": "env",
"ENV_FILE_0": "env0",
"ENV_FILE_1": "env1",
"OVERWRITE": "false"
}
, argv = ["node", "script", "--env-file=arg0", "--env-file=arg1"]
main(
env,
argv,
k => files[k],
true
)
expect(env).toStrictEqual({
"NPM1": "Loaded",
"ARG0": "Loaded",
"ARG1": "Loaded",
"ENV": "Loaded",
"ENV0": "Loaded",
"ENV1": "Loaded",
"OVERWRITE": "false",
"npm_package_config_env_file_0": "npm0",
"npm_package_config_env_file_1": "npm1",
"ENV_FILE": "env",
"ENV_FILE_0": "env0",
"ENV_FILE_1": "env1"
})
expect(argv).toStrictEqual([
"node", "script"
])
})
it("Isolation and propagation", () => {
const env = {
"global": "global",
"OVERWRITE": "global"
}
, files: Record<string, string> = {
"file1": join(
"file1=file1",
"OVERWRITE=file1",
"file1_catch_global=${global}",
"file1_catch_file2=${file2}",
"file1_vs_file2=file1",
),
"file2": join(
"file2=file2",
"OVERWRITE=file2",
"file2_catch_global=${global}",
"file2_catch_file1=${file1}",
"file1_vs_file2=file2"
)
}
, argv = ["node", "script", "--env-file=file1", "--env-file=file2"]
expect(main(
env,
argv,
k => files[k],
false
)).toStrictEqual({
"file1": "file1",
"file1_catch_file2": "",
"file1_catch_global": "global",
"file2": "file2",
"file2_catch_file1": "",
"file2_catch_global": "global",
"file1_vs_file2": "file2"
})
expect(env).toStrictEqual({
"global": "global",
"OVERWRITE": "global",
"file1": "file1",
"file2": "file2",
"file1_catch_file2": "",
"file2_catch_file1": "",
"file1_catch_global": "global",
"file2_catch_global": "global",
"file1_vs_file2": "file2"
})
})
})