/
concurrent.js
56 lines (50 loc) · 1.74 KB
/
concurrent.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
import { join } from 'path'
import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import { File, check } from 'next-test-utils'
export default (context, render) => {
const dynamicHello = new File(
join(context.appDir, 'components/dynamic-hello.js')
)
const nextConfig = new File(join(context.appDir, 'next.config.js'))
async function get$(path, query) {
const html = await render(path, query)
return cheerio.load(html)
}
describe('concurrentFeatures is enabled', () => {
beforeAll(() => {
dynamicHello.replace('const suspense = false', `const suspense = true`)
nextConfig.replace(
'concurrentFeatures: false',
'concurrentFeatures: true'
)
})
afterAll(() => {
dynamicHello.restore()
nextConfig.restore()
})
it('should render the fallback on server side if not suspended on server', async () => {
const $ = await get$('/suspense/no-thrown')
const html = $('body').html()
expect(html).toContain('loading')
expect(JSON.parse($('#__NEXT_DATA__').text()).dynamicIds).toBeUndefined()
})
it('should render the fallback on server side if suspended on server', async () => {
const $ = await get$('/suspense/thrown')
const html = $('body').html()
expect(html).toContain('loading')
expect(JSON.parse($('#__NEXT_DATA__').text()).dynamicIds).toBeUndefined()
})
it('should hydrate suspenses on client side if suspended on server', async () => {
let browser
try {
browser = await webdriver(context.appPort, '/suspense/thrown')
await check(() => browser.elementByCss('body').text(), /hello/)
} finally {
if (browser) {
await browser.close()
}
}
})
})
}