Unverified Commit ef0d79f5 authored by Jamiboy Mohammad's avatar Jamiboy Mohammad Committed by GitHub

test: consolidate duplicate mode branches in build error tests (#99135)

## Summary

Follow-up to #98847 and #98848, addressing [this review
comment](https://github.com/vercel/next.js/pull/98847#discussion_r_placeholder)
about the duplicate `isNextDev` check in
`cache-components-edge-deduplication`.

Several suites that gained deploy coverage branch on the test mode twice
in a row: once to decide whether `next.start()` should resolve or
reject, and again to pick the assertions. Each pair is folded into a
single branch so the start call sits with the assertions that depend on
it. Two suites that wrote `if (isNextDev) { ... }` followed by `if
(!isNextDev) { ... }` now use a plain `else`, and
`interception-routes-output-export` drops an `else if (isNextDev)` that
could only ever be an `else`.

No assertion changes.

- `cache-components-edge-deduplication`
- `cache-components-route-handler-errors`
- `app-edge-invalid-reexport` — the start branch also folded the
`isTurbopack` distinction in, so the "Turbopack fails, webpack warns"
split is stated once
- `generate-static-params-error` — the dev-only `beforeAll` moved into
the dev branch
- `interception-routes-output-export`
- `catches-missing-getStaticProps`
- `conflicting-public-file-page`

## Verification

- `pnpm test-start-turbo` — 7/7 suites pass
- `pnpm test-dev-turbo` — 7/7 suites pass
- `pnpm test-start-webpack` — 6 pass, 1 skipped
(`cache-components-edge-deduplication` is `@force-gate turbopack`)
- `pnpm test-dev-webpack` — 6/6 applicable suites pass

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 4b9d9de2
......@@ -13,13 +13,9 @@ describe('app-dir edge SSR invalid reexport', () => {
})
it('should warn or error about the re-export of a pages runtime/preferredRegion config', async () => {
if (isNextDev || !isTurbopack) {
if (isNextDev) {
await next.start()
} else {
await expect(next.start()).rejects.toThrow()
}
if (isNextDev) {
const browser = await next.browser('/export/inherit')
// Turbopack is stricter and disallows reexports completely
// webpack merely warns in the CLI and still serves the page wuthout a redbox
......@@ -37,6 +33,11 @@ describe('app-dir edge SSR invalid reexport', () => {
}
`)
}
} else if (isTurbopack) {
// Turbopack fails the build, webpack only warns.
await expect(next.start()).rejects.toThrow()
} else {
await next.start()
}
expect(next.cliOutput).toInclude(
......
......@@ -7,11 +7,9 @@ describe('app-root-param-getters - generateStaticParams error', () => {
skipStart: true,
})
beforeAll(async () => {
if (isNextDev) await next.start()
})
if (isNextDev) {
beforeAll(() => next.start())
it('should error when reading a root param inside the generateStaticParams that defines it - dev', async () => {
const browser = await next.browser('/en/us')
......
......@@ -14,11 +14,7 @@ describe('cache-components-route-handler-errors', () => {
it("should error when route handlers use segment configs that aren't supported by cacheComponents", async () => {
if (isNextDev) {
await next.start()
} else {
await expect(next.start()).rejects.toThrow()
}
if (isNextDev) {
// Test the first route handler with "dynamic" config
const browser = await next.browser('/route-with-dynamic')
await waitForRedbox(browser)
......@@ -40,6 +36,8 @@ describe('cache-components-route-handler-errors', () => {
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.'
)
} else {
await expect(next.start()).rejects.toThrow()
// In build mode, check for all three errors in the output
expect(next.cliOutput).toContain('./app/route-with-dynamic/route.ts')
expect(next.cliOutput).toContain(
......
......@@ -33,11 +33,7 @@ describe('cache-components-edge-deduplication', () => {
it('should not duplicate errors when layout is compiled for both edge and non-edge contexts', async () => {
if (isNextDev) {
await next.start()
} else {
await expect(next.start()).rejects.toThrow()
}
if (isNextDev) {
const browser = await next.browser('/edge-with-layout/edge')
waitForRedbox(browser)
await expect(browser).toDisplayRedbox(`
......@@ -62,6 +58,8 @@ describe('cache-components-edge-deduplication', () => {
// We don't show an error stack, just the individual error messages at each location
expect(layoutErrorMatches.length).toBe(1)
} else {
await expect(next.start()).rejects.toThrow()
// Check that both the layout and edge page errors appear
expect(next.cliOutput).toContain('./app/edge-with-layout/layout.tsx')
expect(next.cliOutput).toContain('./app/edge-with-layout/edge/page.tsx')
......
......@@ -9,13 +9,7 @@ describe('interception-routes-output-export', () => {
})
it('should error when using interception routes with static export', async () => {
if (!isNextDev) {
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
expect(cliOutput).toContain(
'Intercepting routes are not supported with static export.'
)
} else if (isNextDev) {
if (isNextDev) {
let stderr = ''
let child: ChildProcess | undefined
const port = await findPort()
......@@ -42,6 +36,11 @@ describe('interception-routes-output-export', () => {
}
await exit.catch(() => {})
}
} else {
await expect(next.start()).rejects.toThrow()
expect(next.cliOutput).toContain(
'Intercepting routes are not supported with static export.'
)
}
}, 240_000)
})
......@@ -15,9 +15,7 @@ import { nextTestSetup, isNextDev, isNextStart } from 'e2e-utils'
const html = await next.render('/hello')
expect(html).toMatch(errorRegex)
})
}
if (!isNextDev) {
} else {
it('should catch it in server build mode', async () => {
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
......
......@@ -20,9 +20,7 @@ describe('Errors on conflict between public file and page file', () => {
expect(next.cliOutput).toMatch(regex)
})
}
if (!isNextDev) {
} else {
it('should show conflict error during build', async () => {
await expect(next.start()).rejects.toThrow()
const cliOutput = next.cliOutput
......
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