forked from netlify/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.test.js
More file actions
52 lines (45 loc) · 1.38 KB
/
Copy pathenv.test.js
File metadata and controls
52 lines (45 loc) · 1.38 KB
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
const test = require('ava')
const path = require('path')
const { getEnvSettings } = require('./env')
const { withSiteBuilder } = require('../../tests/utils/siteBuilder')
test('should return empty object for a site with no .env file', async t => {
await withSiteBuilder('site-without-env-file', async builder => {
await builder.buildAsync()
const vars = await getEnvSettings(builder.directory)
t.deepEqual(vars, {})
})
})
test('should read env vars from .env.development file', async t => {
await withSiteBuilder('site-with-envs-file', async builder => {
builder
.withEnvFile({
path: '.env',
env: { TEST: 'FROM_ENV' },
})
.withEnvFile({
path: '.env.development',
env: { TEST: 'FROM_DEVELOPMENT_ENV' },
})
await builder.buildAsync()
const vars = await getEnvSettings(builder.directory)
t.deepEqual(vars, {
file: path.resolve(builder.directory, '.env.development'),
vars: {
TEST: 'FROM_DEVELOPMENT_ENV',
},
})
})
})
test('should handle empty .env file', async t => {
await withSiteBuilder('site-with-empty-env-file', async builder => {
builder.withEnvFile({
path: '.env',
})
await builder.buildAsync()
const vars = await getEnvSettings(builder.directory)
t.deepEqual(vars, {
file: path.resolve(builder.directory, '.env'),
vars: {},
})
})
})