[PR #473] [MERGED] test: headers() and cookies() in server actions and route handlers #597

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

📋 Pull Request Information

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

Base: mainHead: test/headers-cookies-in-server-actions


📝 Commits (3)

  • 127491f test: add regression tests for headers() and cookies() in server actions and route handlers
  • 2f21e99 test: address review comments on action-headers tests
  • 7d649c2 test: address second round of review comments

📊 Changes

4 files changed (+301 additions, -0 deletions)

View changed files

tests/fixtures/app-basic/app/nextjs-compat/action-headers/actions.ts (+20 -0)
tests/fixtures/app-basic/app/nextjs-compat/action-headers/page.tsx (+37 -0)
tests/fixtures/app-basic/app/nextjs-compat/api/headers-in-route/route.ts (+16 -0)
tests/nextjs-compat/action-headers.test.ts (+228 -0)

📄 Description

Summary

  • Adds integration tests verifying headers() and cookies() work correctly inside server actions (both wrapper form actions and named exports)
  • Adds a route handler fixture and tests confirming headers() + cookies() work together in the same handler
  • Documents the action ID format used in Vitest integration tests (name="$ACTION_ID_<module>#<export>") for future test authors

New files

File Purpose
tests/nextjs-compat/action-headers.test.ts 8 integration tests covering server action and route handler scenarios
tests/fixtures/app-basic/app/nextjs-compat/action-headers/actions.ts "use server" module with getHeaderFromAction and getCookieFromAction named exports
tests/fixtures/app-basic/app/nextjs-compat/action-headers/page.tsx Page fixture with form actions to generate $ACTION_ID_* hidden inputs
tests/fixtures/app-basic/app/nextjs-compat/api/headers-in-route/route.ts Route handler fixture that reads both headers() and cookies() simultaneously

Test coverage

  • Page renders correctly
  • Action IDs are exposed in form HTML
  • headers() does not throw in a server action
  • cookies() does not throw in a server action
  • getHeaderFromAction("x-test-header") returns the correct header value
  • getCookieFromAction("test-cookie") returns the correct cookie value
  • headers() and cookies() both work together in a route handler

🔄 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/473 **Author:** [@james-elicx](https://github.com/james-elicx) **Created:** 3/11/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `test/headers-cookies-in-server-actions` --- ### 📝 Commits (3) - [`127491f`](https://github.com/cloudflare/vinext/commit/127491f09746c649d9d8b9cb5336c9c61d28af1e) test: add regression tests for headers() and cookies() in server actions and route handlers - [`2f21e99`](https://github.com/cloudflare/vinext/commit/2f21e99030a561735f4dc42fbb7b6ceabeac47fa) test: address review comments on action-headers tests - [`7d649c2`](https://github.com/cloudflare/vinext/commit/7d649c201b43a053e3d26d71b0da925301d971c0) test: address second round of review comments ### 📊 Changes **4 files changed** (+301 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `tests/fixtures/app-basic/app/nextjs-compat/action-headers/actions.ts` (+20 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/action-headers/page.tsx` (+37 -0) ➕ `tests/fixtures/app-basic/app/nextjs-compat/api/headers-in-route/route.ts` (+16 -0) ➕ `tests/nextjs-compat/action-headers.test.ts` (+228 -0) </details> ### 📄 Description ## Summary - Adds integration tests verifying `headers()` and `cookies()` work correctly inside server actions (both wrapper form actions and named exports) - Adds a route handler fixture and tests confirming `headers()` + `cookies()` work together in the same handler - Documents the action ID format used in Vitest integration tests (`name="$ACTION_ID_<module>#<export>"`) for future test authors ## New files | File | Purpose | |------|---------| | `tests/nextjs-compat/action-headers.test.ts` | 8 integration tests covering server action and route handler scenarios | | `tests/fixtures/app-basic/app/nextjs-compat/action-headers/actions.ts` | `"use server"` module with `getHeaderFromAction` and `getCookieFromAction` named exports | | `tests/fixtures/app-basic/app/nextjs-compat/action-headers/page.tsx` | Page fixture with form actions to generate `$ACTION_ID_*` hidden inputs | | `tests/fixtures/app-basic/app/nextjs-compat/api/headers-in-route/route.ts` | Route handler fixture that reads both `headers()` and `cookies()` simultaneously | ## Test coverage - Page renders correctly - Action IDs are exposed in form HTML - `headers()` does not throw in a server action - `cookies()` does not throw in a server action - `getHeaderFromAction("x-test-header")` returns the correct header value - `getCookieFromAction("test-cookie")` returns the correct cookie value - `headers()` and `cookies()` both work together in a route handler --- <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:59 +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#597
No description provided.