2021-09-13 14:36:25 +02:00
|
|
|
import { sandbox } from './helpers'
|
|
|
|
import { createNext } from 'e2e-utils'
|
|
|
|
import { NextInstance } from 'test/lib/next-modes/base'
|
2023-01-13 21:02:44 +01:00
|
|
|
import { getSnapshotTestDescribe } from 'next-test-utils'
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
for (const variant of ['default', 'turbo']) {
|
|
|
|
getSnapshotTestDescribe(variant)(`ReactRefreshLogBox ${variant}`, () => {
|
|
|
|
let next: NextInstance
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
beforeAll(async () => {
|
|
|
|
next = await createNext({
|
|
|
|
files: {},
|
|
|
|
skipStart: true,
|
|
|
|
})
|
2021-09-13 14:36:25 +02:00
|
|
|
})
|
2023-01-13 21:02:44 +01:00
|
|
|
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',
|
|
|
|
`
|
2021-09-13 14:36:25 +02:00
|
|
|
const dns = require('dns')
|
|
|
|
module.exports = dns
|
|
|
|
`,
|
2023-01-13 21:02:44 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'node_modules/my-package/package.json',
|
|
|
|
`
|
2021-09-13 14:36:25 +02:00
|
|
|
{
|
|
|
|
"name": "my-package",
|
|
|
|
"version": "0.0.1"
|
|
|
|
}
|
|
|
|
`,
|
2023-01-13 21:02:44 +01:00
|
|
|
],
|
|
|
|
])
|
|
|
|
)
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await session.patch(
|
|
|
|
'index.js',
|
|
|
|
`
|
2021-09-13 14:36:25 +02:00
|
|
|
import pkg from 'my-package'
|
|
|
|
|
|
|
|
export default function Hello() {
|
|
|
|
return (pkg ? <h1>Package loaded</h1> : <h1>Package did not load</h1>)
|
|
|
|
}
|
|
|
|
`
|
2023-01-13 21:02:44 +01:00
|
|
|
)
|
|
|
|
expect(await session.hasRedbox(true)).toBe(true)
|
|
|
|
expect(await session.getRedboxSource()).toMatchSnapshot()
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await cleanup()
|
|
|
|
})
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
test('Module not found', async () => {
|
|
|
|
const { session, cleanup } = await sandbox(next)
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await session.patch(
|
|
|
|
'index.js',
|
|
|
|
`import Comp from 'b'
|
2021-09-13 14:36:25 +02:00
|
|
|
export default function Oops() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Comp>lol</Comp>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
`
|
2023-01-13 21:02:44 +01:00
|
|
|
)
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
expect(await session.hasRedbox(true)).toBe(true)
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
const source = await session.getRedboxSource()
|
|
|
|
expect(source).toMatchSnapshot()
|
2021-09-13 14:36:25 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await cleanup()
|
|
|
|
})
|
2021-10-21 12:07:02 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
test('Module not found (empty import trace)', async () => {
|
|
|
|
const { session, cleanup } = await sandbox(next)
|
2021-10-21 12:07:02 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await session.patch(
|
|
|
|
'pages/index.js',
|
|
|
|
`import Comp from 'b'
|
2021-10-21 12:07:02 +02:00
|
|
|
export default function Oops() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Comp>lol</Comp>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
`
|
2023-01-13 21:02:44 +01:00
|
|
|
)
|
2021-10-21 12:07:02 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
expect(await session.hasRedbox(true)).toBe(true)
|
2021-10-21 12:07:02 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
const source = await session.getRedboxSource()
|
|
|
|
expect(source).toMatchSnapshot()
|
2021-10-21 12:07:02 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await cleanup()
|
|
|
|
})
|
2022-04-20 14:03:48 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
test('Module not found (missing global CSS)', async () => {
|
|
|
|
const { session, cleanup } = await sandbox(
|
|
|
|
next,
|
|
|
|
new Map([
|
|
|
|
[
|
|
|
|
'pages/_app.js',
|
|
|
|
`
|
2022-04-20 14:03:48 +02:00
|
|
|
import './non-existent.css'
|
2023-01-13 21:02:44 +01:00
|
|
|
|
2022-04-20 14:03:48 +02:00
|
|
|
export default function App({ Component, pageProps }) {
|
|
|
|
return <Component {...pageProps} />
|
|
|
|
}
|
|
|
|
`,
|
2023-01-13 21:02:44 +01:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'pages/index.js',
|
|
|
|
`
|
2022-04-20 14:03:48 +02:00
|
|
|
export default function Page(props) {
|
|
|
|
return <p>index page</p>
|
|
|
|
}
|
|
|
|
`,
|
2023-01-13 21:02:44 +01:00
|
|
|
],
|
|
|
|
])
|
|
|
|
)
|
|
|
|
expect(await session.hasRedbox(true)).toBe(true)
|
2022-04-20 14:03:48 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
const source = await session.getRedboxSource()
|
|
|
|
expect(source).toMatchSnapshot()
|
2022-04-20 14:03:48 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await session.patch(
|
|
|
|
'pages/_app.js',
|
|
|
|
`
|
2022-04-20 14:03:48 +02:00
|
|
|
export default function App({ Component, pageProps }) {
|
|
|
|
return <Component {...pageProps} />
|
|
|
|
}
|
|
|
|
`
|
2023-01-13 21:02:44 +01:00
|
|
|
)
|
|
|
|
expect(await session.hasRedbox(false)).toBe(false)
|
|
|
|
expect(
|
|
|
|
await session.evaluate(() => document.documentElement.innerHTML)
|
|
|
|
).toContain('index page')
|
2022-04-20 14:03:48 +02:00
|
|
|
|
2023-01-13 21:02:44 +01:00
|
|
|
await cleanup()
|
|
|
|
})
|
2022-04-20 14:03:48 +02:00
|
|
|
})
|
2023-01-13 21:02:44 +01:00
|
|
|
}
|