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

[test] Use new Redbox matchers in pages/ ReactRefreshLogBox-builtins (#76392)

parent 05f4b877
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'])('ReactRefreshLogBox %s', () => { describe('ReactRefreshLogBox', () => {
const { next } = nextTestSetup({ const { isTurbopack, next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')), files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true, skipStart: true,
}) })
...@@ -33,7 +32,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => { ...@@ -33,7 +32,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
], ],
]) ])
) )
const { session } = sandbox const { browser, session } = sandbox
await session.patch( await session.patch(
'index.js', 'index.js',
outdent` outdent`
...@@ -44,37 +43,41 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => { ...@@ -44,37 +43,41 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
} }
` `
) )
await session.assertHasRedbox()
if (process.env.TURBOPACK) { if (isTurbopack) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./node_modules/my-package/index.js (1:13) {
"count": 1,
"description": "Module not found: Can't resolve 'dns'",
"environmentLabel": null,
"label": "Build Error",
"source": "./node_modules/my-package/index.js (1:13)
Module not found: Can't resolve 'dns' Module not found: Can't resolve 'dns'
> 1 | const dns = require('dns') > 1 | const dns = require('dns')
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^",
2 | module.exports = dns "stack": [],
}
https://nextjs.org/docs/messages/module-not-found"
`) `)
} else { } else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./node_modules/my-package/index.js (1:1) {
"count": 1,
"description": "Module not found: Can't resolve 'dns'",
"environmentLabel": null,
"label": "Build Error",
"source": "./node_modules/my-package/index.js (1:1)
Module not found: Can't resolve 'dns' Module not found: Can't resolve 'dns'
> 1 | const dns = require('dns') > 1 | const dns = require('dns')
| ^ | ^",
2 | module.exports = dns "stack": [],
}
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./index.js
./pages/index.js"
`) `)
} }
}) })
test('Module not found', async () => { test('Module not found', 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(
'index.js', 'index.js',
...@@ -91,42 +94,40 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => { ...@@ -91,42 +94,40 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
` `
) )
await session.assertHasRedbox() if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
const source = await session.getRedboxSource() {
if (process.env.TURBOPACK) { "count": 1,
expect(source).toMatchInlineSnapshot(` "description": "Module not found: Can't resolve 'b'",
"./index.js (1:1) "environmentLabel": null,
"label": "Build Error",
"source": "./index.js (1:1)
Module not found: Can't resolve 'b' Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^",
2 | "stack": [],
3 | export default function Oops() { }
4 | return (
https://nextjs.org/docs/messages/module-not-found"
`) `)
} else { } else {
expect(source).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./index.js (1:1) {
"count": 1,
"description": "Module not found: Can't resolve 'b'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (1:1)
Module not found: Can't resolve 'b' Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^ | ^",
2 | "stack": [],
3 | export default function Oops() { }
4 | return (
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./pages/index.js"
`) `)
} }
}) })
test('Module not found (empty import trace)', async () => { test('Module not found (empty import trace)', 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(
'pages/index.js', 'pages/index.js',
...@@ -143,32 +144,33 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => { ...@@ -143,32 +144,33 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
` `
) )
await session.assertHasRedbox() if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
const source = await session.getRedboxSource() {
if (process.env.TURBOPACK) { "count": 1,
expect(source).toMatchInlineSnapshot(` "description": "Module not found: Can't resolve 'b'",
"./pages/index.js (1:1) "environmentLabel": null,
"label": "Build Error",
"source": "./pages/index.js (1:1)
Module not found: Can't resolve 'b' Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^",
2 | "stack": [],
3 | export default function Oops() { }
4 | return (
https://nextjs.org/docs/messages/module-not-found"
`) `)
} else { } else {
expect(source).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./pages/index.js (1:1) {
"count": 1,
"description": "Module not found: Can't resolve 'b'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/index.js (1:1)
Module not found: Can't resolve 'b' Module not found: Can't resolve 'b'
> 1 | import Comp from 'b' > 1 | import Comp from 'b'
| ^ | ^",
2 | "stack": [],
3 | export default function Oops() { }
4 | return (
https://nextjs.org/docs/messages/module-not-found"
`) `)
} }
}) })
...@@ -197,33 +199,35 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => { ...@@ -197,33 +199,35 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
], ],
]) ])
) )
const { session } = sandbox const { browser, session } = sandbox
await session.assertHasRedbox()
const source = await session.getRedboxSource() if (isTurbopack) {
if (process.env.TURBOPACK) { await expect(browser).toDisplayRedbox(`
expect(source).toMatchInlineSnapshot(` {
"./pages/_app.js (1:1) "count": 1,
"description": "Module not found: Can't resolve './non-existent.css'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_app.js (1:1)
Module not found: Can't resolve './non-existent.css' Module not found: Can't resolve './non-existent.css'
> 1 | import './non-existent.css' > 1 | import './non-existent.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
2 | "stack": [],
3 | export default function App({ Component, pageProps }) { }
4 | return <Component {...pageProps} />
https://nextjs.org/docs/messages/module-not-found"
`) `)
} else { } else {
expect(source).toMatchInlineSnapshot(` await expect(browser).toDisplayRedbox(`
"./pages/_app.js (1:1) {
"count": 1,
"description": "Module not found: Can't resolve './non-existent.css'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_app.js (1:1)
Module not found: Can't resolve './non-existent.css' Module not found: Can't resolve './non-existent.css'
> 1 | import './non-existent.css' > 1 | import './non-existent.css'
| ^ | ^",
2 | "stack": [],
3 | export default function App({ Component, pageProps }) { }
4 | return <Component {...pageProps} />
https://nextjs.org/docs/messages/module-not-found"
`) `)
} }
......
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