forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
60 lines (52 loc) · 1.86 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
/* eslint-env jest */
import fs from 'fs-extra'
import { join } from 'path'
import { File, nextBuild } from 'next-test-utils'
const appDir = __dirname
const nextConfig = new File(join(appDir, 'next.config.js'))
const reactDomPackagePah = join(appDir, 'node_modules/react-dom')
function writeNextConfig(config) {
const content = `module.exports = { experimental: ${JSON.stringify(config)} }`
nextConfig.write(content)
}
describe('Invalid react 18 webpack config', () => {
it('should enable `experimental.reactRoot` when `experimental.runtime` is enabled', async () => {
writeNextConfig({
runtime: 'edge',
})
const { stderr } = await nextBuild(appDir, [], { stderr: true })
nextConfig.restore()
expect(stderr).toContain(
'`experimental.runtime` requires `experimental.reactRoot` to be enabled along with React 18.'
)
})
})
describe('React 17 with React 18 config', () => {
beforeAll(async () => {
await fs.mkdirp(reactDomPackagePah)
await fs.writeFile(
join(reactDomPackagePah, 'package.json'),
JSON.stringify({ name: 'react-dom', version: '17.0.0' })
)
writeNextConfig({ reactRoot: true })
})
afterAll(async () => {
await fs.remove(reactDomPackagePah)
nextConfig.restore()
})
it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toContain(
'You have to use React 18 to use `experimental.reactRoot`.'
)
})
it('suspense is not allowed in blocking rendering mode', async () => {
const { stderr, code } = await nextBuild(appDir, [], {
stderr: true,
})
expect(stderr).toContain(
'Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense'
)
expect(code).toBe(1)
})
})