[PR #318] [MERGED] test: add unit tests for Pages Router api-handler #474

Closed
opened 2026-05-06 13:08:16 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/318
Author: @NathanDrake2406
Created: 3/7/2026
Status: Merged
Merged: 3/7/2026
Merged by: @james-elicx

Base: mainHead: test/api-handler-coverage


📝 Commits (1)

  • f4bca37 test: add unit tests for Pages Router api-handler

📊 Changes

1 file changed (+789 additions, -0 deletions)

View changed files

tests/api-handler.test.ts (+789 -0)

📄 Description

Summary

  • Adds 34 unit tests for handleApiRoute() in server/api-handler.ts
  • Tests body parsing (JSON, form-urlencoded, malformed JSON fallback, empty, unknown content-type)
  • Tests MAX_BODY_SIZE enforcement (rejects >1MB with 413)
  • Tests cookie parsing edge cases (multiple cookies, = in values, missing header)
  • Tests res.status() chaining, res.json(), res.send() type inference, res.redirect() default 307 vs custom
  • Tests error handling: missing/non-function default export, thrown errors, ssrFixStacktrace called
  • Tests query string + dynamic param merging including duplicate key promotion to arrays

Uses a minimal ViteDevServer mock (only ssrLoadModule + ssrFixStacktrace) and lightweight IncomingMessage/ServerResponse mocks via PassThrough streams.

Test plan

  • npx vitest run tests/api-handler.test.ts — 34/34 passing
  • CI: Lint, Typecheck, Vitest, Playwright E2E

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/318 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/7/2026 **Status:** ✅ Merged **Merged:** 3/7/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `test/api-handler-coverage` --- ### 📝 Commits (1) - [`f4bca37`](https://github.com/cloudflare/vinext/commit/f4bca37b3d0787b7b2750228a597801243636cec) test: add unit tests for Pages Router api-handler ### 📊 Changes **1 file changed** (+789 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `tests/api-handler.test.ts` (+789 -0) </details> ### 📄 Description ## Summary - Adds 34 unit tests for `handleApiRoute()` in `server/api-handler.ts` - Tests body parsing (JSON, form-urlencoded, malformed JSON fallback, empty, unknown content-type) - Tests `MAX_BODY_SIZE` enforcement (rejects >1MB with 413) - Tests cookie parsing edge cases (multiple cookies, `=` in values, missing header) - Tests `res.status()` chaining, `res.json()`, `res.send()` type inference, `res.redirect()` default 307 vs custom - Tests error handling: missing/non-function default export, thrown errors, `ssrFixStacktrace` called - Tests query string + dynamic param merging including duplicate key promotion to arrays Uses a minimal `ViteDevServer` mock (only `ssrLoadModule` + `ssrFixStacktrace`) and lightweight `IncomingMessage`/`ServerResponse` mocks via `PassThrough` streams. ## Test plan - [x] `npx vitest run tests/api-handler.test.ts` — 34/34 passing - [x] CI: Lint, Typecheck, Vitest, Playwright E2E --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:16 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#474
No description provided.