forked from motdotla/dotenv
/
test-config-cli.js
80 lines (71 loc) · 1.3 KB
/
test-config-cli.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
/* @flow */
const cp = require('child_process')
const path = require('path')
const t = require('tap')
const configPath = path.resolve(__dirname, '../config.js')
function spawn (cmd, options = {}) {
const { stdout } = cp.spawnSync(
process.argv[0], // node binary
cmd,
Object.assign(
{},
{
cwd: path.resolve(__dirname, '..'),
timeout: 5000,
encoding: 'utf8'
},
options
)
)
return stdout
}
t.plan(3)
// dotenv/config enables preloading
t.equal(
spawn(
[
'-r',
configPath,
'-e',
'console.log(process.env.BASIC)',
'dotenv_config_encoding=utf8',
'dotenv_config_path=./tests/.env'
]
),
'basic\n'
)
// dotenv/config supports configuration via environment variables
t.equal(
spawn(
[
'-r',
configPath,
'-e',
'console.log(process.env.BASIC)'
],
{
env: {
DOTENV_CONFIG_PATH: './tests/.env'
}
}
),
'basic\n'
)
// dotenv/config takes CLI configuration over environment variables
t.equal(
spawn(
[
'-r',
configPath,
'-e',
'console.log(process.env.BASIC)',
'dotenv_config_path=./tests/.env'
],
{
env: {
DOTENV_CONFIG_PATH: '/tmp/dne/path/.env.should.break'
}
}
),
'basic\n'
)