Files
cloudflare__vinext/tests/app-page-params.test.ts
T
James Anderson fbf68d588e fix(app-router): restore cache and parallel route parity (#2261)
* 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
2026-06-22 23:17:41 +01:00

76 lines
3.1 KiB
TypeScript

import { describe, expect, it } from "vite-plus/test";
import {
resolveAppPageBranchParams,
resolveAppPageSegmentParamScopeKeys,
resolveAppPageSegmentParams,
} from "../packages/vinext/src/server/app-page-params.js";
describe("app page params helpers", () => {
it("passes only params that apply to each layout", () => {
// Ported from Next.js: test/e2e/app-dir/layout-params/layout-params.test.ts
// https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/layout-params/layout-params.test.ts
const routeSegments = ["base", "[param1]", "[param2]"];
const matchedParams = { param1: "something", param2: "another" };
expect(resolveAppPageSegmentParams(routeSegments, 0, matchedParams)).toEqual({});
expect(resolveAppPageSegmentParams(routeSegments, 1, matchedParams)).toEqual({});
expect(resolveAppPageSegmentParams(routeSegments, 2, matchedParams)).toEqual({
param1: "something",
});
expect(resolveAppPageSegmentParams(routeSegments, 3, matchedParams)).toEqual({
param1: "something",
param2: "another",
});
});
it("scopes catch-all params to the catch-all layout", () => {
// Ported from Next.js: test/e2e/app-dir/layout-params/layout-params.test.ts
// https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/layout-params/layout-params.test.ts
const routeSegments = ["catchall", "[...params]"];
const matchedParams = { params: ["something", "another"] };
expect(resolveAppPageSegmentParams(routeSegments, 1, matchedParams)).toEqual({});
expect(resolveAppPageSegmentParams(routeSegments, 2, matchedParams)).toEqual({
params: ["something", "another"],
});
});
it("omits empty optional catch-all params from layouts", () => {
// Ported from Next.js: test/e2e/app-dir/layout-params/layout-params.test.ts
// https://github.com/vercel/next.js/blob/canary/test/e2e/app-dir/layout-params/layout-params.test.ts
const routeSegments = ["optional-catchall", "[[...params]]"];
expect(resolveAppPageSegmentParams(routeSegments, 1, { params: [] })).toEqual({});
expect(resolveAppPageSegmentParams(routeSegments, 2, { params: [] })).toEqual({});
expect(
resolveAppPageSegmentParams(routeSegments, 2, { params: ["something", "another"] }),
).toEqual({
params: ["something", "another"],
});
});
it("keeps optional catch-all names in structural layout param scope", () => {
const routeSegments = ["docs", "[[...slug]]"];
expect(resolveAppPageSegmentParams(routeSegments, 2, { slug: [] })).toEqual({});
expect(resolveAppPageSegmentParamScopeKeys(routeSegments, 2)).toEqual(["slug"]);
});
it("preserves ancestor params while scoping parallel branch params", () => {
expect(
resolveAppPageBranchParams(
["photos", "[photo]", "[comment]"],
2,
{ locale: "en", photo: "42", comment: "7" },
["photos", "[photo]"],
),
).toEqual({ locale: "en", photo: "42" });
});
it("uses canonical segment parsing for branch-local param names", () => {
expect(resolveAppPageBranchParams(["[invalid.name]"], 0, { "invalid.name": "outer" })).toEqual({
"invalid.name": "outer",
});
});
});