Skip to content

Commit

Permalink
[test] Use new Redbox matchers in pages/ ReactRefreshLogBox-builtins (v…
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Feb 23, 2025
1 parent 05f4b87 commit 0b49048
Showing 1 changed file with 92 additions and 88 deletions.
180 changes: 92 additions & 88 deletions test/development/acceptance/ReactRefreshLogBox-builtins.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { describeVariants as describe } from 'next-test-utils'
import { outdent } from 'outdent'
import path from 'path'

describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
const { next } = nextTestSetup({
describe('ReactRefreshLogBox', () => {
const { isTurbopack, next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
})
Expand Down Expand Up @@ -33,7 +32,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
],
])
)
const { session } = sandbox
const { browser, session } = sandbox
await session.patch(
'index.js',
outdent`
Expand All @@ -44,37 +43,41 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
}
`
)
await session.assertHasRedbox()
if (process.env.TURBOPACK) {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js (1:13)

if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | const dns = require('dns')
| ^^^^^^^^^^^^^^
2 | module.exports = dns
https://nextjs.org/docs/messages/module-not-found"
| ^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
expect(await session.getRedboxSource()).toMatchInlineSnapshot(`
"./node_modules/my-package/index.js (1:1)
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | const dns = require('dns')
| ^
2 | module.exports = dns
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./index.js
./pages/index.js"
| ^",
"stack": [],
}
`)
}
})

test('Module not found', async () => {
await using sandbox = await createSandbox(next)
const { session } = sandbox
const { browser, session } = sandbox

await session.patch(
'index.js',
Expand All @@ -91,42 +94,40 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
`
)

await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(`
"./index.js (1:1)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^
2 |
3 | export default function Oops() {
4 | return (
https://nextjs.org/docs/messages/module-not-found"
| ^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./index.js (1:1)
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | import Comp from 'b'
| ^
2 |
3 | export default function Oops() {
4 | return (
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./pages/index.js"
| ^",
"stack": [],
}
`)
}
})

test('Module not found (empty import trace)', async () => {
await using sandbox = await createSandbox(next)
const { session } = sandbox
const { browser, session } = sandbox

await session.patch(
'pages/index.js',
Expand All @@ -143,32 +144,33 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
`
)

await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(`
"./pages/index.js (1:1)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^
2 |
3 | export default function Oops() {
4 | return (
https://nextjs.org/docs/messages/module-not-found"
| ^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./pages/index.js (1:1)
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | import Comp from 'b'
| ^
2 |
3 | export default function Oops() {
4 | return (
https://nextjs.org/docs/messages/module-not-found"
| ^",
"stack": [],
}
`)
}
})
Expand Down Expand Up @@ -197,33 +199,35 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox %s', () => {
],
])
)
const { session } = sandbox
await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(`
"./pages/_app.js (1:1)
const { browser, session } = sandbox

if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | import './non-existent.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 |
3 | export default function App({ Component, pageProps }) {
4 | return <Component {...pageProps} />
https://nextjs.org/docs/messages/module-not-found"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./pages/_app.js (1:1)
await expect(browser).toDisplayRedbox(`
{
"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'
> 1 | import './non-existent.css'
| ^
2 |
3 | export default function App({ Component, pageProps }) {
4 | return <Component {...pageProps} />
https://nextjs.org/docs/messages/module-not-found"
| ^",
"stack": [],
}
`)
}

Expand Down

0 comments on commit 0b49048

Please sign in to comment.