Unverified Commit 4b9d9de2 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: snapshot the proxy-runtime build error output (#99136)

## Summary

Follow-up to #98848, addressing [this review
comment](https://github.com/vercel/next.js/pull/98848#discussion_r4074331118)
asking for a snapshot test.

The Turbopack production assertion in `proxy-runtime` compared a
hand-maintained `expected` literal against the CLI output with
`toContain`, with the deploy differences patched up by a local
`normalize` helper. It now extracts the build error section and asserts
it with an inline snapshot, so the whole diagnostic is pinned —
including the error count line and the trailing frame, which the
substring match never covered — and can be regenerated instead of edited
by hand.

The normalization deploy needed (timestamp prefixes, code-frame
indentation, dropped blank lines) runs in every mode now, so a single
snapshot covers local and deploy builds rather than branching on
`isNextDeploy`.

### Tests that were checked and left alone

`use-cache-close-over-function` and `use-cache-hanging` have the same
`expected` + `normalize` + `toContain` shape from #98847, but their
build errors happen during page generation, so the surrounding output
interleaves `Generating static pages using N workers (n/m)` lines — `N`
follows the host's CPU count and the progress lines vary run to run. In
`use-cache-close-over-function` the failing route also varies, which is
why the existing assertion matches `"/(client|server)"`. A snapshot over
that region would be flaky, so both keep their targeted substring
assertions. `proxy-runtime` is snapshot-safe because its error is a
compile error raised before page generation starts.

## Verification

- `pnpm test-start-turbo` — passes, and a second run passes against the
committed snapshot
- `pnpm test-start-webpack`, `pnpm test-dev-turbo`, `pnpm
test-dev-webpack` — pass (these take the unchanged non-Turbopack/dev
branch)

Local checks used the published native binding. Deploy validation is
pending repository CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: 's avatarClaude Opus 5 <noreply@anthropic.com>
parent aea417ab
......@@ -2,7 +2,7 @@ import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi'
describe('proxy-runtime', () => {
const { next, isNextDev, isNextDeploy } = nextTestSetup({
const { next, isNextDev, isTurbopack } = nextTestSetup({
files: __dirname,
skipStart: true,
})
......@@ -21,24 +21,20 @@ describe('proxy-runtime', () => {
}
// TODO: Investigate why in dev-turbo, the error is shown in the browser console, not CLI output.
if (process.env.IS_TURBOPACK_TEST && !isNextDev) {
const expected = `proxy.ts:3:14
Error: Next.js can't recognize the exported \`config\` field in route. Proxy does not support Edge runtime.
1 | export default function () {}
2 |
> 3 | export const config = { runtime: 'edge' }
| ^^^^^^
4 |
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.`
// Deployment logs add timestamps and remove code-frame indentation.
const normalize = (output: string) =>
isNextDeploy
? output
.replace(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z {2}/gm, '')
.replace(/^[ \t]+/gm, '')
: output
expect(normalize(stripAnsi(cliOutput))).toContain(normalize(expected))
if (isTurbopack && !isNextDev) {
expect(getBuildError(cliOutput)).toMatchInlineSnapshot(`
"Error: Turbopack build failed with 1 error:
./proxy.ts:3:14
Error: Next.js can't recognize the exported \`config\` field in route. Proxy does not support Edge runtime.
1 | export default function () {}
2 |
> 3 | export const config = { runtime: 'edge' }
| ^^^^^^
4 |
The exported configuration object in a source file needs to have a very specific format from which some properties can be statically parsed at compiled-time.
https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
at <unknown> (https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config)"
`)
} else {
expect(cliOutput).toContain(
`Route segment config is not allowed in Proxy file at "./proxy.ts". Proxy always runs on Node.js runtime. Learn more: https://nextjs.org/docs/messages/middleware-to-proxy`
......@@ -48,3 +44,30 @@ The exported configuration object in a source file needs to have a very specific
if (isNextDev) await next.stop()
}, 240_000)
})
// Deployment logs prefix every line with a timestamp, drop code-frame
// indentation, and can omit blank lines, so the same normalization is applied
// in all modes to keep a single snapshot.
function getBuildError(cliOutput: string): string {
const lines: string[] = []
let capturing = false
for (const rawLine of stripAnsi(cliOutput).split('\n')) {
const line = rawLine
.replace(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z {2}/, '')
.trim()
// The command exit status is not compiler output.
if (/^Error: Command .* exited with \d+$/.test(line)) break
if (capturing) {
if (line) {
lines.push(line)
}
} else if (line.includes('Build error occurred')) {
capturing = true
}
}
return lines.join('\n')
}
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