-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.test.js
68 lines (59 loc) · 1.79 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
/* eslint-env jest */
import path from 'path'
import webdriver from 'next-webdriver'
import {
nextBuild,
nextStart,
findPort,
launchApp,
killApp,
renderViaHTTP,
waitFor,
} from 'next-test-utils'
const appDir = path.join(__dirname, '..')
let appPort
let app
const runTests = () => {
it('should provide router context in AppTree on SSR', async () => {
let html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/page:.*?\//)
html = await renderViaHTTP(appPort, '/another')
expect(html).toMatch(/page:.*?\/another/)
})
it('should provide router context in AppTree on CSR', async () => {
const browser = await webdriver(appPort, '/')
let html = await browser.eval(`document.documentElement.innerHTML`)
expect(html).toMatch(/page:.*?\//)
browser.elementByCss('#another').click()
await waitFor(500)
html = await browser.eval(`document.documentElement.innerHTML`)
expect(html).toMatch(/page:.*?\//)
browser.elementByCss('#home').click()
await waitFor(500)
html = await browser.eval(`document.documentElement.innerHTML`)
expect(html).toMatch(/page:.*?\/another/)
})
it('should pass AppTree to NextPageContext', async () => {
const html = await renderViaHTTP(appPort, '/hello')
expect(html).toMatch(/saved:.*?Hello world/)
})
}
describe('AppTree', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
runTests()
})
})