test(pages-router): regression coverage for edge runtime & OG image API routes (#1338)#1648
Conversation
…PI routes (#1338) Adds Pages Router fixtures and dev + production integration tests for the two scenarios reported as failing in the Next.js Deploy Suite: - `export const config = { runtime: 'edge' }` API route returns a Web Response (issue #1338 case 1 — edge API routes were observed as 500). - `next/og` `ImageResponse` with `runtime: 'edge'` inside a Pages Router API route returns `image/png` (issue #1338 case 2 — OG routes were observed as 404). Ports route handlers from `next.js/test/e2e/edge-pages-support/app/pages/api/hello.js` and `next.js/test/e2e/og-api/app/pages/api/og.js`. The existing implementation already wires both code paths correctly via `handlePagesApiRoute` and the `vinext:og-inline-fetch-assets` plugin; this PR locks in coverage so a Pages Router-only build cannot silently regress either path. Refs #1338
|
/bigbonk review |
commit: |
|
There was a problem hiding this comment.
Review: LGTM
Clean, well-scoped regression coverage PR. Fixtures are faithful to the upstream Next.js test sources and the test assertions cover the right things.
What's good
- Fixture provenance comments link back to the exact Next.js source files — easy to cross-reference.
- Both dev (standalone
it()blocks in "Pages Router integration") and prod (inside the monolithic "serves pages from production build end-to-end") paths are covered. - The
edge-hello.tshandler exercisesreq.nextUrl.searchParamswith a query param, not just a bare request — this catches a broader class of edge-route dispatch bugs. - The OG route test checks both
content-type: image/pngand non-zero blob size, which is sufficient to prove theImageResponserendered end-to-end. - The
NextRequestLiketype inedge-hello.tsis pragmatic — it avoids pulling in the fullNextRequesttype fromnext/serverwhile still exercising thenextUrl.searchParamsAPI surface thathandlePagesApiRoutewires up for edge routes.
Nits (non-blocking)
-
Prod coverage lives in the monolithic test: The edge API and OG assertions are appended inside
it("serves pages from production build end-to-end")which already has ~25 sub-assertions. If that test fails on an unrelated assertion (e.g., thessr-cache-controlcheck above), the edge/OG assertions never run. Consider splitting these into thedescribe("Production server middleware (Pages Router)")block as standaloneit()blocks in a follow-up — that describe already hasstartProdServerlifecycle hooks, so the edge/OG tests would get independent pass/fail reporting for free. -
No
startProdServer-based standalone tests: Thedescribe("Production server middleware (Pages Router)")block (which usesstartProdServerand has independentit()blocks) doesn't get edge/OG coverage from this PR. The middleware matcher/((?!api|_next|favicon\.ico|mw-object-gated).*)excludes/api/*from middleware, so the prod-server routing path for API routes is actually different — worth covering independently when time permits.
Both nits are follow-up material. The coverage as-is is a net improvement and locks in the regression.
|
Approved PR #1648. The PR adds solid regression coverage for the two Pages Router edge-runtime scenarios reported in #1338 (edge API routes returning 500 and OG image routes returning 404). The fixtures are faithfully ported from the upstream Next.js test suite, and both dev-mode and production-mode code paths are covered. I left two non-blocking nits about the prod-mode tests being embedded in the monolithic "serves pages from production build end-to-end" test rather than as standalone |
Summary
Adds Pages Router-only fixtures and dev + production integration tests for the two scenarios reported as failing in the Next.js Deploy Suite (#1338):
export const config = { runtime: 'edge' }API route returns a WebResponse(case 1 —/api/hellowas observed as 500).next/ogImageResponsewithruntime: 'edge'inside a Pages Router API route returnsimage/png(case 2 —/api/ogwas observed as 404).The existing implementation already routes both code paths through
handlePagesApiRouteand applies thevinext:og-inline-fetch-assetsVite transform; this PR locks in regression coverage so a Pages Router-only build cannot silently regress either path. Both new tests pass locally against the currentmain-equivalent code.Route handlers are ported from Next.js' own e2e fixtures:
next.js/test/e2e/edge-pages-support/app/pages/api/hello.jsnext.js/test/e2e/og-api/app/pages/api/og.jsScoped intentionally — the App Router OG + custom-font (
/font/opengraph-image500) and other edge-runtime test-suite gaps remain out of scope for this PR and continue to be tracked under #1338.Refs #1338
Test plan
pnpm test tests/pages-router.test.ts— dev + prod regression cases pass (271 tests)pnpm test tests/pages-api-route.test.ts— direct handler unit tests still passpnpm run check— fmt, lint, types clean