forked from vercel/next.js
/
ReactRefreshLogBox-builtins.test.ts
148 lines (127 loc) · 3.22 KB
/
ReactRefreshLogBox-builtins.test.ts
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import { sandbox } from './helpers'
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('ReactRefreshLogBox', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {},
skipStart: true,
})
})
afterAll(() => next.destroy())
// Module trace is only available with webpack 5
test('Node.js builtins', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'node_modules/my-package/index.js',
`
const dns = require('dns')
module.exports = dns
`,
],
[
'node_modules/my-package/package.json',
`
{
"name": "my-package",
"version": "0.0.1"
}
`,
],
])
)
await session.patch(
'index.js',
`
import pkg from 'my-package'
export default function Hello() {
return (pkg ? <h1>Package loaded</h1> : <h1>Package did not load</h1>)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
expect(await session.getRedboxSource()).toMatchSnapshot()
await cleanup()
})
test('Module not found', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'index.js',
`import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await cleanup()
})
test('Module not found (empty import trace)', async () => {
const { session, cleanup } = await sandbox(next)
await session.patch(
'pages/index.js',
`import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await cleanup()
})
test('Module not found (missing global CSS)', async () => {
const { session, cleanup } = await sandbox(
next,
new Map([
[
'pages/_app.js',
`
import './non-existent.css'
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
`,
],
[
'pages/index.js',
`
export default function Page(props) {
return <p>index page</p>
}
`,
],
])
)
expect(await session.hasRedbox(true)).toBe(true)
const source = await session.getRedboxSource()
expect(source).toMatchSnapshot()
await session.patch(
'pages/_app.js',
`
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
`
)
expect(await session.hasRedbox(false)).toBe(false)
expect(
await session.evaluate(() => document.documentElement.innerHTML)
).toContain('index page')
await cleanup()
})
})