-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.test.js
57 lines (48 loc) · 1.38 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
/* eslint-env jest */
import { join } from 'path'
import {
renderViaHTTP,
findPort,
launchApp,
killApp,
nextBuild,
nextStart,
getBuildManifest,
} from 'next-test-utils'
import fs from 'fs-extra'
// test suite
import clientNavigation from './client-navigation'
const context = {}
const appDir = join(__dirname, '../')
const runTests = (isProd = false) => {
clientNavigation(context, isProd)
}
describe('Client 404', () => {
describe('dev mode', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort)
// pre-build page at the start
await renderViaHTTP(context.appPort, '/')
})
afterAll(() => killApp(context.server))
runTests()
})
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
context.appPort = await findPort()
context.server = await nextStart(appDir, context.appPort)
const manifest = await getBuildManifest(appDir)
const files = manifest.pages['/missing'].filter((d) =>
/static[\\/]chunks[\\/]pages/.test(d)
)
if (files.length < 1) {
throw new Error('oops!')
}
await Promise.all(files.map((f) => fs.remove(join(appDir, '.next', f))))
})
afterAll(() => killApp(context.server))
runTests(true)
})
})