Unverified Commit a0cd5d9a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Use new Redbox matchers in app/ ReactRefreshLogBoxMisc (#76563)

parent 7135484d
...@@ -3,210 +3,15 @@ import { FileRef, nextTestSetup } from 'e2e-utils' ...@@ -3,210 +3,15 @@ import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path' import path from 'path'
import { outdent } from 'outdent' import { outdent } from 'outdent'
// TODO: re-enable these tests after figuring out what is causing describe('ReactRefreshLogBox app', () => {
// them to be so unreliable in CI const { isTurbopack, next } = nextTestSetup({
describe.skip('ReactRefreshLogBox app', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true, skipStart: true,
}) })
test('<Link> with multiple children', async () => {
await using sandbox = await createSandbox(next)
const { session } = sandbox
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Index() {
return (
<Link href="/">
<p>One</p>
<p>Two</p>
</Link>
)
}
`
)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: Multiple children were passed to <Link> with \`href\` of \`/\` but only one child is supported https://nextjs.org/docs/messages/link-multiple-children"`
)
expect(
await session.evaluate(
() =>
(
document
.querySelector('body > nextjs-portal')
.shadowRoot.querySelector(
'#nextjs__container_errors_desc a:nth-of-type(1)'
) as any
).href
)
).toMatch('https://nextjs.org/docs/messages/link-multiple-children')
})
test('<Link> component props errors', async () => {
await using sandbox = await createSandbox(next)
const { session } = sandbox
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return <Link />
}
`
)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: Failed prop type: The prop \`href\` expects a \`string\` or \`object\` in \`<Link>\`, but got \`undefined\` instead."`
)
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return <Link href="/">Abc</Link>
}
`
)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return (
<Link
href="/"
as="/"
replace={false}
scroll={false}
shallow={false}
passHref={false}
prefetch={false}
>
Abc
</Link>
)
}
`
)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return (
<Link
href="/"
as="/"
replace={true}
scroll={true}
shallow={true}
passHref={true}
prefetch={true}
>
Abc
</Link>
)
}
`
)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return (
<Link
href="/"
as="/"
replace={undefined}
scroll={undefined}
shallow={undefined}
passHref={undefined}
prefetch={undefined}
>
Abc
</Link>
)
}
`
)
await session.assertNoRedbox()
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return (
<Link
href="/"
as="/"
replace={undefined}
scroll={'oops'}
shallow={undefined}
passHref={undefined}
prefetch={undefined}
>
Abc
</Link>
)
}
`
)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchSnapshot()
await session.patch(
'index.js',
outdent`
import Link from 'next/link'
export default function Hello() {
return (
<Link
href={false}
as="/"
replace={undefined}
scroll={'oops'}
shallow={undefined}
passHref={undefined}
prefetch={undefined}
>
Abc
</Link>
)
}
`
)
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchSnapshot()
})
test('server-side only compilation errors', async () => { test('server-side only compilation errors', async () => {
await using sandbox = await createSandbox(next) await using sandbox = await createSandbox(next)
const { session } = sandbox const { browser, session } = sandbox
await session.patch( await session.patch(
'app/page.js', 'app/page.js',
...@@ -226,6 +31,45 @@ describe.skip('ReactRefreshLogBox app', () => { ...@@ -226,6 +31,45 @@ describe.skip('ReactRefreshLogBox app', () => {
` `
) )
await session.assertHasRedbox() if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Ecmascript file had an error",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js (3:23)
Ecmascript file had an error
> 3 | export async function getStaticProps() {
| ^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: x "getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js
Error: x "getStaticProps" is not supported in app/. Read more: https://nextjs.org/docs/app/building-your-application/data-fetching
|
|
,-[3:1]
1 | 'use client'
2 | import myLibrary from 'my-non-existent-library'
3 | export async function getStaticProps() {
: ^^^^^^^^^^^^^^
4 | return {
5 | props: {
6 | result: myLibrary()
\`----
Import trace for requested module:
./app/page.js",
"stack": [],
}
`)
}
}) })
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment