-
Notifications
You must be signed in to change notification settings - Fork 26k
/
index.test.js
130 lines (117 loc) · 3.23 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
/* eslint-env jest */
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import {
fetchViaHTTP,
renderViaHTTP,
findPort,
killApp,
launchApp,
nextBuild,
nextStart,
check,
} from 'next-test-utils'
import { join } from 'path'
let app
let appPort
const appDir = join(__dirname, '../')
function runTests(dev = false) {
it('ssr async page modules', async () => {
const html = await renderViaHTTP(appPort, '/')
const $ = cheerio.load(html)
expect($('#app-value').text()).toBe('hello')
expect($('#page-value').text()).toBe('42')
})
it('csr async page modules', async () => {
let browser
try {
browser = await webdriver(appPort, '/')
expect(await browser.elementByCss('#app-value').text()).toBe('hello')
expect(await browser.elementByCss('#page-value').text()).toBe('42')
expect(await browser.elementByCss('#doc-value').text()).toBe('doc value')
} finally {
if (browser) await browser.close()
}
})
it('works on async api routes', async () => {
const res = await fetchViaHTTP(appPort, '/api/hello')
expect(res.status).toBe(200)
const result = await res.json()
expect(result).toHaveProperty('value', 42)
})
it('works with getServerSideProps', async () => {
let browser
try {
browser = await webdriver(appPort, '/gssp')
expect(await browser.elementByCss('#gssp-value').text()).toBe('42')
} finally {
if (browser) await browser.close()
}
})
it('works with getStaticProps', async () => {
let browser
try {
browser = await webdriver(appPort, '/gsp')
expect(await browser.elementByCss('#gsp-value').text()).toBe('42')
} finally {
if (browser) await browser.close()
}
})
it('can render async 404 pages', async () => {
let browser
try {
browser = await webdriver(appPort, '/dhiuhefoiahjeoij')
expect(await browser.elementByCss('#content-404').text()).toBe("hi y'all")
} finally {
if (browser) await browser.close()
}
})
// TODO: investigate this test flaking
it.skip('can render async AMP pages', async () => {
let browser
try {
browser = await webdriver(appPort, '/config')
await check(
() => browser.elementByCss('#amp-timeago').text(),
'just now',
true
)
} finally {
if (browser) await browser.close()
}
})
;(dev ? it.skip : it)('can render async error page', async () => {
let browser
try {
browser = await webdriver(appPort, '/make-error')
expect(await browser.elementByCss('#content-error').text()).toBe(
'hello error'
)
} finally {
if (browser) await browser.close()
}
})
}
describe('Async modules', () => {
describe('dev mode', () => {
beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests(true)
})
;(process.env.TURBOPACK ? describe.skip : describe)('production mode', () => {
beforeAll(async () => {
await nextBuild(appDir)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await killApp(app)
})
runTests()
})
})