mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
71dbb45ca8
* fix(pages): pin revalidate loopback origin * test(pages): cover production revalidation origin * fix(pages): preserve internal revalidation boundaries * fix(pages): preserve on-demand revalidation boundaries * fix(pages): dispatch Worker revalidation internally * fix(pages): authenticate revalidation request context * fix(pages): isolate revalidation transport headers * test(pages): account for generated route table size * fix(pages): align on-demand revalidation semantics * fix(pages): align revalidation response cache parity * fix(pages): preserve regenerated ISR representations * fix(pages): align ISR cache representations * fix(pages): preserve canonical ISR representations * fix(pages): align cached response parity * fix(pages): preserve custom App render props * fix(pages): preserve optional App page props * fix(pages): preserve optional App props on the client * fix(pages): normalize client App page props * fix(pages): preserve App data merge semantics * fix(pages): keep redirect status helper internal * fix(pages): match Next.js terminal ISR behavior * fix(pages): preserve custom app error envelopes * fix(pages): match Next.js dev revalidation semantics * test(pages): align dev revalidation parity coverage * chore(pages): remove stale cache helper exports * fix(cache): preserve explicit no-store context
54 lines
2.3 KiB
TypeScript
54 lines
2.3 KiB
TypeScript
import { describe, expect, it } from "vite-plus/test";
|
|
import { createPagesDevHydrationScript } from "../packages/vinext/src/server/pages-dev-hydration.js";
|
|
|
|
describe("createPagesDevHydrationScript", () => {
|
|
it("generates the normal Pages Router hydration entry", () => {
|
|
const script = createPagesDevHydrationScript({
|
|
appModuleSource: "/pages/_app.tsx",
|
|
pageModuleSource: "/pages/index.tsx",
|
|
reactStrictMode: true,
|
|
replaceFallbackRoute: true,
|
|
scriptNonce: "nonce-value",
|
|
});
|
|
|
|
expect(script).toContain('<script type="module" nonce="nonce-value">');
|
|
expect(script).toContain("_initializePagesRouterReadyFromNextData(nextData);");
|
|
expect(script).toContain('() => import("/pages/index.tsx")');
|
|
expect(script).toContain('() => import("/pages/_app.tsx")');
|
|
expect(script).toContain("const appRouter = Router;");
|
|
expect(script).not.toContain("pageProps: rawPageProps,");
|
|
expect(script).toContain("if (nextData.isFallback)");
|
|
expect(script).not.toContain("window.__VINEXT_PAGE_PATTERNS__ = [nextData.page]");
|
|
});
|
|
|
|
it("generates the forced-ready error hydration entry", () => {
|
|
const script = createPagesDevHydrationScript({
|
|
appModuleSource: null,
|
|
forceRouterReady: true,
|
|
normalizePageProps: false,
|
|
pageModuleSource: "next/error",
|
|
reactStrictMode: false,
|
|
setPagePatternsFromNextData: true,
|
|
});
|
|
|
|
expect(script).toContain("_initializePagesRouterReadyFromNextData(nextData, true);");
|
|
expect(script).toContain("window.__VINEXT_PAGE_PATTERNS__ = [nextData.page];");
|
|
expect(script).toContain('() => import("next/error")');
|
|
expect(script).toContain("const pageProps = rawPageProps ?? {};");
|
|
expect(script).toContain("element = React.createElement(PageComponent, pageProps);");
|
|
expect(script).not.toContain("if (nextData.isFallback)");
|
|
expect(script).not.toContain("const appRouter =");
|
|
});
|
|
|
|
it("serializes module specifiers safely", () => {
|
|
const script = createPagesDevHydrationScript({
|
|
appModuleSource: '/pages/_app"quoted.tsx',
|
|
pageModuleSource: "/pages/line\nfeed.tsx",
|
|
reactStrictMode: false,
|
|
});
|
|
|
|
expect(script).toContain('import("/pages/_app\\"quoted.tsx")');
|
|
expect(script).toContain('import("/pages/line\\nfeed.tsx")');
|
|
});
|
|
});
|