Files
next.js/test/e2e/app-dir/error-on-next-codemod-comment/error-on-next-codemod-comment.test.ts
Niklas MischkulnigandGitHub 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

141 lines
4.9 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 { nextTestSetup } from 'e2e-utils'
import {
waitForRedbox,
waitForNoRedbox,
getRedboxSource,
retry,
} from 'next-test-utils'
describe('app-dir - error-on-next-codemod-comment', () => {
const { next, isNextDev, skipped } = nextTestSetup({
files: __dirname,
skipStart: true,
skipDeployment: true,
})
if (skipped) return
if (isNextDev) {
beforeAll(async () => {
await next.start()
})
it('should error with swc if you have codemod comments left', async () => {
const browser = await next.browser('/')
await waitForRedbox(browser)
if (process.env.IS_TURBOPACK_TEST) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./app/page.tsx (2:2)
Error: You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.
After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken.
1 | export default function Page() {
> 2 | // @next-codemod-error remove jsx of next line
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | return <p>hello world</p>
4 | }
5 |
Ecmascript file had an error"
`)
} else if (process.env.NEXT_RSPACK) {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./app/page.tsx
╰─▶ × Error: x You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.
│ | After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken.
│
│ ,-[2:1]
│ 1 | export default function Page() {
│ 2 | // @next-codemod-error remove jsx of next line
│ : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
│ 3 | return <p>hello world</p>
│ 4 | }
│ \`----
│"
`)
} else {
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"./app/page.tsx
Error: x You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.
| After review, either remove the comment if you made the necessary changes or replace "@next-codemod-error" with "@next-codemod-ignore" to bypass the build error if no action at this line can be taken.
,-[2:1]
1 | export default function Page() {
2 | // @next-codemod-error remove jsx of next line
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | return <p>hello world</p>
4 | }
\`----"
`)
}
})
it('should error with inline comment as well', async () => {
let originFileContent
await next.patchFile('app/page.tsx', (code) => {
originFileContent = code
return code.replace(
'// @next-codemod-error remove jsx of next line',
'/* @next-codemod-error remove jsx of next line */'
)
})
const browser = await next.browser('/')
await waitForRedbox(browser)
// Recover the original file content
await next.patchFile('app/page.tsx', originFileContent)
})
it('should disappear the error when you rre the codemod comment', async () => {
const browser = await next.browser('/')
await waitForRedbox(browser)
let originFileContent
await next.patchFile('app/page.tsx', (code) => {
originFileContent = code
return code.replace(
'// @next-codemod-error remove jsx of next line',
''
)
})
await retry(async () => {
await waitForNoRedbox(browser)
})
// Recover the original file content
await next.patchFile('app/page.tsx', originFileContent)
})
it('should disappear the error when you replace with bypass comment', async () => {
const browser = await next.browser('/')
await waitForRedbox(browser)
let originFileContent
await next.patchFile('app/page.tsx', (code) => {
originFileContent = code
return code.replace('@next-codemod-error', '@next-codemod-bypass')
})
await retry(async () => {
await waitForNoRedbox(browser)
})
// Recover the original file content
await next.patchFile('app/page.tsx', originFileContent)
})
} else {
it('should fail the build with next build', async () => {
const res = await next.build()
expect(res.exitCode).toBe(1)
expect(res.cliOutput).toContain(
'You have an unresolved @next/codemod comment "remove jsx of next line" that needs review.'
)
})
}
})