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

[test] Use new Redbox matchers in pages/ ReactRefreshLogBox-app-doc (#76551)

parent 1c60a25c
import { createSandbox } from 'development-sandbox' import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils' import { FileRef, nextTestSetup } from 'e2e-utils'
import { describeVariants as describe } from 'next-test-utils'
import { outdent } from 'outdent' import { outdent } from 'outdent'
import path from 'path' import path from 'path'
describe.each(['default', 'turbo'])( describe('ReactRefreshLogBox _app _document', () => {
'ReactRefreshLogBox _app _document %s', const { isTurbopack, next } = nextTestSetup({
() => {
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,
}) })
...@@ -17,8 +14,17 @@ describe.each(['default', 'turbo'])( ...@@ -17,8 +14,17 @@ describe.each(['default', 'turbo'])(
next, next,
new Map([['pages/_app.js', ``]]) new Map([['pages/_app.js', ``]])
) )
const { session } = sandbox const { browser, session } = sandbox
await session.assertHasRedbox() await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Error: The default export is not a React Component in page: "/_app"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
expect(await session.getRedboxDescription()).toMatchInlineSnapshot( expect(await session.getRedboxDescription()).toMatchInlineSnapshot(
`"Error: The default export is not a React Component in page: "/_app""` `"Error: The default export is not a React Component in page: "/_app""`
) )
...@@ -40,11 +46,18 @@ describe.each(['default', 'turbo'])( ...@@ -40,11 +46,18 @@ describe.each(['default', 'turbo'])(
next, next,
new Map([['pages/_document.js', ``]]) new Map([['pages/_document.js', ``]])
) )
const { session } = sandbox const { browser, session } = sandbox
await session.assertHasRedbox()
expect(await session.getRedboxDescription()).toMatchInlineSnapshot( await expect(browser).toDisplayRedbox(`
`"Error: The default export is not a React Component in page: "/_document""` {
) "count": 1,
"description": "Error: The default export is not a React Component in page: "/_document"",
"environmentLabel": null,
"label": "Runtime Error",
"source": null,
"stack": [],
}
`)
await session.patch( await session.patch(
'pages/_document.js', 'pages/_document.js',
...@@ -91,25 +104,30 @@ describe.each(['default', 'turbo'])( ...@@ -91,25 +104,30 @@ describe.each(['default', 'turbo'])(
], ],
]) ])
) )
const { session } = sandbox const { browser, session } = sandbox
await session.assertHasRedbox()
const content = await session.getRedboxSource() if (isTurbopack) {
const source = next.normalizeTestDirContent(content) await expect(browser).toDisplayRedbox(`
if (process.env.TURBOPACK) { {
expect(source).toMatchInlineSnapshot(` "count": 1,
"./pages/_app.js (2:11) "description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_app.js (2:11)
Parsing ecmascript source code failed Parsing ecmascript source code failed
1 | function MyApp({ Component, pageProps }) {
> 2 | return <<Component {...pageProps} />; > 2 | return <<Component {...pageProps} />;
| ^ | ^",
3 | } "stack": [],
4 | export default MyApp }
Expression expected"
`) `)
} else { } else {
expect(source).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./pages/_app.js {
"count": 1,
"description": "Error: x Expression expected",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_app.js
Error: x Expression expected Error: x Expression expected
,-[2:1] ,-[2:1]
1 | function MyApp({ Component, pageProps }) { 1 | function MyApp({ Component, pageProps }) {
...@@ -126,9 +144,10 @@ describe.each(['default', 'turbo'])( ...@@ -126,9 +144,10 @@ describe.each(['default', 'turbo'])(
3 | } 3 | }
4 | export default MyApp 4 | export default MyApp
\`---- \`----
Caused by: Caused by:
Syntax Error" Syntax Error",
"stack": [],
}
`) `)
} }
...@@ -177,28 +196,29 @@ describe.each(['default', 'turbo'])( ...@@ -177,28 +196,29 @@ describe.each(['default', 'turbo'])(
], ],
]) ])
) )
const { session } = sandbox const { browser, session } = sandbox
await session.assertHasRedbox() if (isTurbopack) {
const source = next.normalizeTestDirContent( await expect(browser).toDisplayRedbox(`
await session.getRedboxSource() {
) "count": 1,
if (process.env.TURBOPACK) { "description": "Parsing ecmascript source code failed",
expect(source).toMatchInlineSnapshot(` "environmentLabel": null,
"./pages/_document.js (3:36) "label": "Build Error",
"source": "./pages/_document.js (3:36)
Parsing ecmascript source code failed Parsing ecmascript source code failed
1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
2 |
> 3 | class MyDocument extends Document {{ > 3 | class MyDocument extends Document {{
| ^ | ^",
4 | static async getInitialProps(ctx) { "stack": [],
5 | const initialProps = await Document.getInitialProps(ctx) }
6 | return { ...initialProps }
Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key"
`) `)
} else { } else {
expect(source).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./pages/_document.js {
"count": 1,
"description": "Error: x Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_document.js
Error: x Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key Error: x Unexpected token \`{\`. Expected identifier, string literal, numeric literal or [ for the computed key
,-[3:1] ,-[3:1]
1 | import Document, { Html, Head, Main, NextScript } from 'next/document' 1 | import Document, { Html, Head, Main, NextScript } from 'next/document'
...@@ -209,9 +229,10 @@ describe.each(['default', 'turbo'])( ...@@ -209,9 +229,10 @@ describe.each(['default', 'turbo'])(
5 | const initialProps = await Document.getInitialProps(ctx) 5 | const initialProps = await Document.getInitialProps(ctx)
6 | return { ...initialProps } 6 | return { ...initialProps }
\`---- \`----
Caused by: Caused by:
Syntax Error" Syntax Error",
"stack": [],
}
`) `)
} }
...@@ -244,5 +265,4 @@ describe.each(['default', 'turbo'])( ...@@ -244,5 +265,4 @@ describe.each(['default', 'turbo'])(
) )
await session.assertNoRedbox() await session.assertNoRedbox()
}) })
} })
)
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