File size: 2,781 Bytes
1e92f2d |
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 |
import path from 'path'
import { outdent } from 'outdent'
import { FileRef, nextTestSetup } from 'e2e-utils'
describe('Error overlay - RSC runtime errors', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'rsc-runtime-errors')),
})
it('should show runtime errors if invalid client API from node_modules is executed', async () => {
await next.patchFile(
'app/server/page.js',
outdent`
import { callClientApi } from 'client-package'
export default function Page() {
callClientApi()
return 'page'
}
`
)
const browser = await next.browser('/server')
await expect(browser).toDisplayRedbox(`
{
"description": "useState only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component",
"environmentLabel": "Server",
"label": "Runtime TypeError",
"source": "app/server/page.js (3:16) @ Page
> 3 | callClientApi()
| ^",
"stack": [
"Page app/server/page.js (3:16)",
],
}
`)
})
it('should show runtime errors if invalid server API from node_modules is executed', async () => {
await next.patchFile(
'app/client/page.js',
outdent`
'use client'
import { callServerApi } from 'server-package'
export default function Page() {
callServerApi()
return 'page'
}
`
)
const browser = await next.browser('/client')
await expect(browser).toDisplayRedbox(`
{
"description": "\`cookies\` was called outside a request scope. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/client/page.js (4:16) @ Page
> 4 | callServerApi()
| ^",
"stack": [
"Page app/client/page.js (4:16)",
],
}
`)
})
it('should show source code for jsx errors from server component', async () => {
await next.patchFile(
'app/server/page.js',
outdent`
export default function Page() {
return <div>{alert('warn')}</div>
}
`
)
const browser = await next.browser('/server')
await expect(browser).toDisplayRedbox(`
{
"description": "alert is not defined",
"environmentLabel": "Server",
"label": "Runtime ReferenceError",
"source": "app/server/page.js (2:16) @ Page
> 2 | return <div>{alert('warn')}</div>
| ^",
"stack": [
"Page app/server/page.js (2:16)",
],
}
`)
})
})
|