-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.test.js
79 lines (65 loc) · 2.1 KB
/
index.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
/* eslint-env jest */
import webdriver from 'next-webdriver'
import { join } from 'path'
import {
nextStart,
nextBuild,
findPort,
killApp,
runNextCommand,
} from 'next-test-utils'
const appDir = join(__dirname, '../')
let app
let appPort
describe('Production Config Usage', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
describe('with generateBuildId', () => {
it('should add the custom buildid', async () => {
const browser = await webdriver(appPort, '/')
const text = await browser.elementByCss('#mounted').text()
expect(text).toMatch(/ComponentDidMount executed on client\./)
const html = await browser.eval('document.documentElement.innerHTML')
expect(html).toMatch('custom-buildid')
await browser.close()
})
})
describe('env', () => {
it('should fail with leading __ in env key', async () => {
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_FAIL_UNDERSCORE: true },
stdout: true,
stderr: true,
})
expect(result.stderr).toMatch(/The key "__NEXT_MY_VAR" under/)
})
it('should fail with NODE_ in env key', async () => {
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_FAIL_NODE: true },
stdout: true,
stderr: true,
})
expect(result.stderr).toMatch(/The key "NODE_ENV" under/)
})
it('should fail with NEXT_RUNTIME in env key', async () => {
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_NEXT_PRESERVED: true },
stdout: true,
stderr: true,
})
expect(result.stderr).toMatch(/The key "NEXT_RUNTIME" under/)
})
it('should allow __ within env key', async () => {
const result = await runNextCommand(['build', appDir], {
env: { ENABLE_ENV_WITH_UNDERSCORES: true },
stdout: true,
stderr: true,
})
expect(result.stderr).not.toMatch(/The key "SOME__ENV__VAR" under/)
})
})
})