forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basic.js
57 lines (48 loc) · 1.96 KB
/
basic.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
import webdriver from 'next-webdriver'
import { renderViaHTTP } from 'next-test-utils'
export default async function basic(context, { env }) {
it('should render 404 error correctly', async () => {
const path404HTML = await renderViaHTTP(context.appPort, '/404')
const pathNotFoundHTML = await renderViaHTTP(context.appPort, '/not-found')
expect(path404HTML).toContain('custom-404-page')
expect(pathNotFoundHTML).toContain('custom-404-page')
})
it('should render dynamic routes correctly', async () => {
const dynamicRoute1HTML = await renderViaHTTP(
context.appPort,
'/routes/dynamic1'
)
const dynamicRoute2HTML = await renderViaHTTP(
context.appPort,
'/routes/dynamic2'
)
expect(dynamicRoute1HTML).toContain('query: dynamic1')
expect(dynamicRoute2HTML).toContain('query: dynamic2')
})
it('should support api routes', async () => {
const res = await renderViaHTTP(context.appPort, '/api/ping')
expect(res).toContain('pong')
})
it('should handle suspense error page correctly (node stream)', async () => {
const browser = await webdriver(context.appPort, '/404')
const hydrationContent = await browser.waitForElementByCss('#__next').text()
expect(hydrationContent).toBe('custom-404-pagenext_streaming_data')
})
it('should render 500 error correctly', async () => {
const errPaths = ['/err', '/err/render']
const promises = errPaths.map(async (pagePath) => {
const html = await renderViaHTTP(context.appPort, pagePath)
if (env === 'dev') {
// In dev mode it should show the error popup.
expect(html).toContain('Error: oops')
} else {
expect(html).toContain('custom-500-page')
}
})
await Promise.all(promises)
})
it('should render fallback if error raised from suspense during streaming', async () => {
const html = await renderViaHTTP(context.appPort, '/err/suspense')
expect(html).toContain('error-fallback')
})
}