Skip to content

Commit

Permalink
[test] Use new Redbox matchers in app/ ReactRefreshLogBox-builtins (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored Feb 23, 2025
1 parent 4b23c7b commit 4095ecb
Showing 1 changed file with 91 additions and 93 deletions.
184 changes: 91 additions & 93 deletions test/development/acceptance-app/ReactRefreshLogBox-builtins.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { describeVariants as describe } from 'next-test-utils'
import { outdent } from 'outdent'

// TODO-APP: Investigate snapshot mismatch
describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
const { next } = nextTestSetup({
describe('ReactRefreshLogBox-builtins app', () => {
const { isTurbopack, next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
})
Expand Down Expand Up @@ -35,7 +33,7 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
])
)

const { session } = sandbox
const { browser, session } = sandbox

await session.patch(
'index.js',
Expand All @@ -47,37 +45,40 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %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
./app/page.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 @@ -93,42 +94,40 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %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 | export default function Oops() {
3 | return (
4 | <div>
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 | export default function Oops() {
3 | return (
4 | <div>
https://nextjs.org/docs/messages/module-not-found
Import trace for requested module:
./app/page.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(
'app/page.js',
Expand All @@ -145,34 +144,33 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
`
)

await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(`
"./app/page.js (2:1)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Module not found: Can't resolve 'b'",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js (2:1)
Module not found: Can't resolve 'b'
1 | 'use client'
> 2 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^
3 | export default function Oops() {
4 | return (
5 | <div>
https://nextjs.org/docs/messages/module-not-found"
| ^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./app/page.js (2:1)
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Module not found: Can't resolve 'b'",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js (2:1)
Module not found: Can't resolve 'b'
1 | 'use client'
> 2 | import Comp from 'b'
| ^
3 | export default function Oops() {
4 | return (
5 | <div>
https://nextjs.org/docs/messages/module-not-found"
| ^",
"stack": [],
}
`)
}
})
Expand All @@ -193,37 +191,37 @@ describe.each(['default', 'turbo'])('ReactRefreshLogBox app %s', () => {
],
])
)
const { session } = sandbox
await session.assertHasRedbox()

const source = await session.getRedboxSource()
if (process.env.TURBOPACK) {
expect(source).toMatchInlineSnapshot(`
"./app/page.js (2: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": "./app/page.js (2:1)
Module not found: Can't resolve './non-existent.css'
1 | 'use client'
> 2 | import './non-existent.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | export default function Page(props) {
4 | return <p>index page</p>
5 | }
https://nextjs.org/docs/messages/module-not-found"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else {
expect(source).toMatchInlineSnapshot(`
"./app/page.js (2:1)
await expect(browser).toDisplayRedbox(`
{
"count": 1,
"description": "Module not found: Can't resolve './non-existent.css'",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js (2:1)
Module not found: Can't resolve './non-existent.css'
1 | 'use client'
> 2 | import './non-existent.css'
| ^
3 | export default function Page(props) {
4 | return <p>index page</p>
5 | }
https://nextjs.org/docs/messages/module-not-found"
| ^",
"stack": [],
}
`)
}

await session.patch(
'app/page.js',
outdent`
Expand Down

0 comments on commit 4095ecb

Please sign in to comment.