2023-01-24 11:12:29 +01:00
|
|
|
/* eslint-env jest */
|
2023-06-21 21:47:21 +02:00
|
|
|
import { sandbox } from 'development-sandbox'
|
|
|
|
import { FileRef, nextTestSetup } from 'e2e-utils'
|
2023-01-24 11:12:29 +01:00
|
|
|
import path from 'path'
|
2023-06-21 21:47:21 +02:00
|
|
|
import { outdent } from 'outdent'
|
2023-01-24 11:12:29 +01:00
|
|
|
|
2023-06-21 21:47:21 +02:00
|
|
|
describe('Component Stack in error overlay', () => {
|
|
|
|
const { next } = nextTestSetup({
|
2023-01-24 11:12:29 +01:00
|
|
|
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
|
|
|
|
dependencies: {
|
|
|
|
react: 'latest',
|
|
|
|
'react-dom': 'latest',
|
|
|
|
},
|
|
|
|
skipStart: true,
|
2023-06-21 21:47:21 +02:00
|
|
|
})
|
2023-01-24 11:12:29 +01:00
|
|
|
|
2023-06-21 21:47:21 +02:00
|
|
|
it('should show a component stack on hydration error', async () => {
|
|
|
|
const { cleanup, session } = await sandbox(
|
|
|
|
next,
|
|
|
|
new Map([
|
|
|
|
[
|
|
|
|
'app/component.js',
|
|
|
|
outdent`
|
|
|
|
'use client'
|
|
|
|
const isClient = typeof window !== 'undefined'
|
|
|
|
export default function Component() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p>{isClient ? "client" : "server"}</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'app/page.js',
|
|
|
|
outdent`
|
|
|
|
import Component from './component'
|
|
|
|
export default function Mismatch() {
|
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<Component />
|
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
`,
|
|
|
|
],
|
|
|
|
])
|
|
|
|
)
|
2023-01-24 11:12:29 +01:00
|
|
|
|
2023-06-21 21:47:21 +02:00
|
|
|
await session.waitForAndOpenRuntimeError()
|
|
|
|
|
|
|
|
expect(await session.getRedboxComponentStack()).toMatchInlineSnapshot(`
|
2023-01-24 11:12:29 +01:00
|
|
|
"p
|
|
|
|
div
|
|
|
|
Component
|
|
|
|
main"
|
|
|
|
`)
|
|
|
|
|
2023-06-21 21:47:21 +02:00
|
|
|
await cleanup()
|
|
|
|
})
|
|
|
|
})
|