Files
vercel__next.js/test/development/acceptance/ReactRefreshLogBox-builtins.test.ts
Niklas Mischkulnig 9b8a7a1055 Turbopack: improve issue printing colors (#94858)
1. Align the code highlight marker color with the issue severity
2. Make the issue title colored
3. Prefix issues with `Warning` or `Error`


<img width="1383" height="862" alt="Bildschirmfoto 2026-06-16 um 18 59
03"
src="https://github.com/user-attachments/assets/f98c606d-4ea8-40c2-836d-e395f1df904c"
/>


<img width="1039" height="450" alt="Bildschirmfoto 2026-06-16 um 19 03
39"
src="https://github.com/user-attachments/assets/2747f914-0587-4178-a87d-344f24715c96"
/>



<details>
<summary>Old</summary>

<img width="1267" height="745" alt="Bildschirmfoto 2026-06-16 um 17 04
35"
src="https://github.com/user-attachments/assets/837739ff-82f7-4ea2-8767-ca7d866a8570"
/>

</details>
2026-06-16 21:29:37 +02:00

318 lines
9.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { outdent } from 'outdent'
import path from 'path'
describe('ReactRefreshLogBox', () => {
const { isTurbopack, next, isRspack } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
})
// Module trace is only available with webpack 5
test('Node.js builtins', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'node_modules/my-package/index.js',
outdent`
const dns = require('dns')
module.exports = dns
`,
],
[
'node_modules/my-package/package.json',
outdent`
{
"name": "my-package",
"version": "0.0.1"
}
`,
],
])
)
const { browser, session } = sandbox
await session.patch(
'index.js',
outdent`
import pkg from 'my-package'
export default function Hello() {
return (pkg ? <h1>Package loaded</h1> : <h1>Package did not load</h1>)
}
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Module not found: Can't resolve 'dns'",
"environmentLabel": null,
"label": "Build Error",
"source": "./node_modules/my-package/index.js (1:13)
Error: Module not found: Can't resolve 'dns'
> 1 | const dns = require('dns')
| ^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else if (isRspack) {
await expect({ browser, next }).toDisplayRedbox(`
{
"description": " × Module not found: Can't resolve 'dns' in '<FIXME-project-root>/node_modules/my-package'",
"environmentLabel": null,
"label": "Build Error",
"source": "./node_modules/my-package/index.js
× Module not found: Can't resolve 'dns' in '<FIXME-project-root>/node_modules/my-package'
╭─[1:12]
1 │ const dns = require('dns')
· ──────────────
2 │ module.exports = dns
╰────
Import trace for requested module:
./node_modules/my-package/index.js
./index.js",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"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')
| ^",
"stack": [],
}
`)
}
})
test('Module not found', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
await session.patch(
'index.js',
outdent`
import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Module not found: Can't resolve 'b'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (1:1)
Error: Module not found: Can't resolve 'b'
> 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else if (isRspack) {
await expect({ browser, next }).toDisplayRedbox(`
{
"description": " × Module not found: Can't resolve 'b' in '<FIXME-project-root>'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
× Module not found: Can't resolve 'b' in '<FIXME-project-root>'
╭─[2:0]
1 │ import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
2 │ import Comp from 'b';
· ─────────────────────
3 │ export default function Oops() {
4 │ return /*#__PURE__*/ _jsxDEV("div", {
╰────
Import trace for requested module:
./index.js
./pages/index.js",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"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'
| ^",
"stack": [],
}
`)
}
})
test('Module not found (empty import trace)', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
await session.patch(
'pages/index.js',
outdent`
import Comp from 'b'
export default function Oops() {
return (
<div>
<Comp>lol</Comp>
</div>
)
}
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Module not found: Can't resolve 'b'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/index.js (1:1)
Error: Module not found: Can't resolve 'b'
> 1 | import Comp from 'b'
| ^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else if (isRspack) {
await expect({ browser, next }).toDisplayRedbox(`
{
"description": " × Module not found: Can't resolve 'b' in '<FIXME-project-root>/pages'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/index.js
× Module not found: Can't resolve 'b' in '<FIXME-project-root>/pages'
╭─[2:0]
1 │ import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
2 │ import Comp from 'b';
· ─────────────────────
3 │ export default function Oops() {
4 │ return /*#__PURE__*/ _jsxDEV("div", {
╰────
Import trace for requested module:
./pages/index.js",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"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'
| ^",
"stack": [],
}
`)
}
})
test('Module not found (missing global CSS)', async () => {
await using sandbox = await createSandbox(
next,
new Map([
[
'pages/_app.js',
outdent`
import './non-existent.css'
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
`,
],
[
'pages/index.js',
outdent`
export default function Page(props) {
return <p>index page</p>
}
`,
],
])
)
const { browser, session } = sandbox
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Module not found: Can't resolve './non-existent.css'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_app.js (1:1)
Error: Module not found: Can't resolve './non-existent.css'
> 1 | import './non-existent.css'
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^",
"stack": [],
}
`)
} else if (isRspack) {
await expect({ browser, next }).toDisplayRedbox(`
{
"description": " × Module not found: Can't resolve './non-existent.css' in '<FIXME-project-root>/pages'",
"environmentLabel": null,
"label": "Build Error",
"source": "./pages/_app.js
× Module not found: Can't resolve './non-existent.css' in '<FIXME-project-root>/pages'
╭─[2:0]
1 │ import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
2 │ import './non-existent.css';
· ────────────────────────────
3 │ export default function App({ Component, pageProps }) {
4 │ return /*#__PURE__*/ _jsxDEV(Component, {
╰────",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"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'
| ^",
"stack": [],
}
`)
}
await session.patch(
'pages/_app.js',
outdent`
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
`
)
await session.waitForNoRedbox()
expect(
await session.evaluate(() => document.documentElement.innerHTML)
).toContain('index page')
})
})