forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic.js
More file actions
132 lines (110 loc) · 4.11 KB
/
Copy pathdynamic.js
File metadata and controls
132 lines (110 loc) · 4.11 KB
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
131
132
/* global describe, it, expect */
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import { waitFor } from 'next-test-utils'
export default (context, render) => {
describe('Dynamic import', () => {
describe('with SSR', () => {
async function get$ (path, query) {
const html = await render(path, query)
return cheerio.load(html)
}
it('should render dynmaic import components', async () => {
const $ = await get$('/dynamic/ssr')
expect($('p').text()).toBe('Hello World 1')
})
it('should stop render dynmaic import components', async () => {
const $ = await get$('/dynamic/no-ssr')
expect($('p').text()).toBe('loading...')
})
it('should stop render dynmaic import components with custom loading', async () => {
const $ = await get$('/dynamic/no-ssr-custom-loading')
expect($('p').text()).toBe('LOADING')
})
it('should render dynamic imports bundle', async () => {
const $ = await get$('/dynamic/bundle')
const bodyText = $('body').text()
expect(/Dynamic Bundle/.test(bodyText)).toBe(true)
expect(/Hello World 1/.test(bodyText)).toBe(true)
expect(/Hello World 2/.test(bodyText)).toBe(false)
})
it('should render dynamic imports bundle with additional components', async () => {
const $ = await get$('/dynamic/bundle?showMore=1')
const bodyText = $('body').text()
expect(/Dynamic Bundle/.test(bodyText)).toBe(true)
expect(/Hello World 1/.test(bodyText)).toBe(true)
expect(/Hello World 2/.test(bodyText)).toBe(true)
})
})
describe('with browser', () => {
it('should render the page client side', async () => {
const browser = await webdriver(context.appPort, '/dynamic/no-ssr-custom-loading')
while (true) {
const bodyText = await browser
.elementByCss('body').text()
if (/Hello World 1/.test(bodyText)) break
await waitFor(1000)
}
browser.close()
})
it('should render even there are no physical chunk exists', async () => {
const browser = await webdriver(context.appPort, '/dynamic/no-chunk')
while (true) {
const bodyText = await browser
.elementByCss('body').text()
if (
/Welcome, normal/.test(bodyText) &&
/Welcome, dynamic/.test(bodyText)
) break
await waitFor(1000)
}
browser.close()
})
describe('with bundle', () => {
it('should render components', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
while (true) {
const bodyText = await browser
.elementByCss('body').text()
if (
/Dynamic Bundle/.test(bodyText) &&
/Hello World 1/.test(bodyText) &&
!(/Hello World 2/.test(bodyText))
) break
await waitFor(1000)
}
browser.close()
})
it('should render support React context', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
while (true) {
const bodyText = await browser
.elementByCss('body').text()
if (
/ZEIT Rocks/.test(bodyText)
) break
await waitFor(1000)
}
browser.close()
})
it('should load new components and render for prop changes', async () => {
const browser = await webdriver(context.appPort, '/dynamic/bundle')
await browser
.waitForElementByCss('#toggle-show-more')
.elementByCss('#toggle-show-more').click()
while (true) {
const bodyText = await browser
.elementByCss('body').text()
if (
/Dynamic Bundle/.test(bodyText) &&
/Hello World 1/.test(bodyText) &&
/Hello World 2/.test(bodyText)
) break
await waitFor(1000)
}
browser.close()
})
})
})
})
}