forked from vercel/next.js
/
index.test.js
64 lines (56 loc) · 1.73 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
/* eslint-env jest */
/* global jasmine */
import path from 'path'
import fs from 'fs-extra'
import { nextBuild, nextExport } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1
const appDir = path.join(__dirname, '..')
const outdir = path.join(__dirname, 'out')
const nextConfig = path.join(appDir, 'next.config.js')
let stderr
let exitCode
const runTests = () => {
it('should show warning for query provided for auto exported page correctly', async () => {
expect(exitCode).toBe(1)
expect(stderr).toContain(
'Error: you provided query values for / which is an auto-exported page. These can not be applied since the page can no longer be re-rendered on the server. To disable auto-export for this page add `getInitialProps`'
)
expect(stderr).not.toContain('/amp')
expect(stderr).not.toContain('/ssr')
expect(stderr).not.toContain('/ssg')
expect(stderr).not.toContain('/hello')
})
}
let origNextConfig
describe('Auto Export', () => {
describe('server mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
const { stderr: curStderr, code: curCode } = await nextExport(
appDir,
{ outdir },
{ stderr: true }
)
stderr = curStderr
exitCode = curCode
})
runTests()
})
describe('serverless mode', () => {
beforeAll(async () => {
origNextConfig = await fs.readFile(nextConfig, 'utf8')
await nextBuild(appDir)
const { stderr: curStderr, code: curCode } = await nextExport(
appDir,
{ outdir },
{ stderr: true }
)
stderr = curStderr
exitCode = curCode
})
afterAll(async () => {
await fs.writeFile(nextConfig, origNextConfig)
})
runTests()
})
})