mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
fbf68d588e
* fix(app-router): preserve searchParams cache variants * test(app-router): cover RSC metadata cache variants * fix(app-router): isolate metadata searchParams observation * fix(app-router): preserve static ISR cache proofs * fix(app-router): limit queryless cache probes * fix(app-router): skip redundant cache proof probes * fix(app-router): harden incomplete cache proofs * fix(app-router): observe loading page execution * fix(app-router): preserve exotic page exports * fix(app-router): preserve client page ISR * fix(app-router): avoid duplicate queryless page execution * fix(app-router): observe viewport search params * fix(app-router): clear force-static search params * fix(app-router): isolate intercept static context * fix(app-router): preserve intercept request context * fix(app-router): isolate action static context * fix(app-router): match static request API semantics * fix(app-router): preserve dynamic segment constraints * fix(app-router): apply slot-only segment config * fix(app-router): preserve draft mode reads in static errors * fix(app-router): include nested slot constraints * fix(app-router): refresh slot layout constraints * fix(app-router): render nested slot layouts * fix(app-router): preserve nested slot params * fix(app-router): preserve intercepted slot head * fix(app-router): scope parallel layout params * fix(app-router): preserve intercept layout parity * fix(app-router): preserve intercept ancestor params * fix(app-router): scope intercept source params * fix(app-router): preserve intercept source route params * test(app-router): stabilize parity validation
52 lines
2.6 KiB
TypeScript
52 lines
2.6 KiB
TypeScript
import { http, passthrough, type RequestHandler } from "msw";
|
|
|
|
/**
|
|
* Default MSW handlers shared across the test suite.
|
|
*
|
|
* `tests/_msw/setup.ts` enables `onUnhandledRequest: "error"`, so any
|
|
* request issued by tests must be matched by either a default handler
|
|
* here or a per-test override registered via `server.use(...)`.
|
|
*
|
|
* MSW is wired into the `unit` vitest project only — the integration
|
|
* project's tests spin up in-process HTTP servers and fixture dev
|
|
* servers, which don't mix well with the @mswjs/interceptors layer.
|
|
* See the comment on the `integration` project in `vite.config.ts`.
|
|
*
|
|
* Tests register their own handlers locally via `server.use(...)`.
|
|
*/
|
|
|
|
/**
|
|
* Loopback addresses are always passed through to the real network.
|
|
*
|
|
* Even unit tests routinely spin up small in-process HTTP servers
|
|
* (e.g. middleware-rewrite proxy tests in `tests/shims.test.ts`,
|
|
* static-asset 404 tests, JSX-in-JS rendering tests). Those tests bind
|
|
* a Node `http.Server` on `127.0.0.1:<random>` and fetch it. Without
|
|
* this passthrough, MSW's interceptor sees the loopback fetch, finds
|
|
* no handler, and errors via `onUnhandledRequest: "error"`.
|
|
*
|
|
* `passthrough()` is the documented escape hatch: the request is
|
|
* forwarded to the real network without buffering.
|
|
*/
|
|
// 127/8 + the unspecified `0.0.0.0` + IPv6 `::1` + the literal hostname
|
|
// "localhost". `0.0.0.0` is included defensively — Node servers that
|
|
// bind to "0.0.0.0" sometimes surface that exact host in URLs handed
|
|
// to fetch in tests. The IPv4 octets are loosely bounded to 1-3 digits
|
|
// — `URL.hostname` normalises real addresses and no test would
|
|
// construct an out-of-range octet, so the looser bound keeps the regex
|
|
// readable.
|
|
const LOOPBACK_URL_PATTERN =
|
|
/^https?:\/\/(?:localhost|127(?:\.\d{1,3}){3}|0(?:\.0){3}|\[?::1\]?)(?::\d+)?(?:\/|$)/;
|
|
const loopbackPassthrough = http.all(LOOPBACK_URL_PATTERN, () => passthrough());
|
|
|
|
// @vercel/og's Node runtime loads embedded Yoga WASM through fetch. Depending
|
|
// on the bundler transform, the inline binary is exposed either as a data URL
|
|
// or as the equivalent malformed `nullapplication/...` URL. Neither form is a
|
|
// network request, so pass it through without weakening strict handling for
|
|
// unmocked external HTTP requests. Otherwise MSW logs the full multi-megabyte
|
|
// WASM URL, which can exhaust CI output limits even though rendering succeeds.
|
|
const INLINE_BINARY_URL_PATTERN = /^(?:data:|null)application\/octet-stream;base64,/;
|
|
const inlineBinaryPassthrough = http.all(INLINE_BINARY_URL_PATTERN, () => passthrough());
|
|
|
|
export const handlers: RequestHandler[] = [loopbackPassthrough, inlineBinaryPassthrough];
|