/
index.test.js
140 lines (110 loc) · 4.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* eslint-env jest */
/* global jasmine */
import 'flat-map-polyfill'
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { join } from 'path'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2
const fixturesDir = join(__dirname, '..', 'fixtures')
describe('Build Output', () => {
describe('Basic Application Output', () => {
const appDir = join(fixturesDir, 'basic-app')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should not include internal pages', async () => {
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain('/_document')
expect(stdout).not.toContain('/_app')
expect(stdout).not.toContain('/_error')
expect(stdout).toContain('○ /')
})
})
describe('Custom App Output', () => {
const appDir = join(fixturesDir, 'with-app')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should not include custom error', async () => {
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/\/_app [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain('/_document')
expect(stdout).not.toContain('/_error')
expect(stdout).toContain('/_app')
expect(stdout).toContain('○ /')
})
})
describe('With AMP Output', () => {
const appDir = join(fixturesDir, 'with-amp')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should not include custom error', async () => {
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout).toMatch(/\/ [ 0-9.]* kB/)
expect(stdout).toMatch(/\/amp .* AMP/)
expect(stdout).toMatch(/\/hybrid [ 0-9.]* B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain('/_document')
expect(stdout).not.toContain('/_error')
expect(stdout).toContain('○ /')
})
})
describe('Custom Error Output', () => {
const appDir = join(fixturesDir, 'with-error')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should not include custom app', async () => {
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout).toMatch(/\/ [ ]* \d{1,} B/)
expect(stdout).toMatch(/λ \/_error [ ]* \d{1,} B/)
expect(stdout).toMatch(/\+ shared by all [ 0-9.]* kB/)
expect(stdout).toMatch(/ runtime\/main\.js [ 0-9.]* kB/)
expect(stdout).toMatch(/ chunks\/framework\.js [ 0-9. ]* kB/)
expect(stdout).not.toContain('/_document')
expect(stdout).not.toContain('/_app')
expect(stdout).toContain('/_error')
expect(stdout).toContain('○ /')
})
})
describe('Custom Static Error Output', () => {
const appDir = join(fixturesDir, 'with-error-static')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
// FIXME: this should be static
xit('should specify /_error as static', async () => {
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout).toContain('○ /_error')
})
// This test is not really correct.
// Remove this when fixed and enable the above one.
it('should specify /_error as lambda even when static', async () => {
const { stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(stdout).toContain('λ /_error')
})
})
})