Files
cloudflare__vinext/tests/compatibility-support.test.ts
James Anderson c2362842c9 fix(build): support deployed web worker graphs (#2314)
* fix(build): support deployed web worker graphs

* fix(build): address worker parity review findings

* fix(build): preserve web worker URL origins

* test(e2e): cover deployed web workers

* test(e2e): port upstream Cloudflare worker suite

* fix(build): preserve worker asset semantics

* fix(build): tolerate minimal resolved config mocks

* test(worker): classify Vite-equivalent coverage
2026-08-16 01:06:42 +01:00

112 lines
3.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
CLASSIFIED_SUITES,
getSuiteSupport,
NON_SUPPORTED_SUITES,
SUITE_SUPPORT_POLICY,
} from "../apps/web/app/compatibility/suite-support";
import {
bucketByRouter,
bucketPassRate,
bucketSupportedPassRate,
} from "../apps/web/app/compatibility/router-buckets";
describe("compatibility suite support policy", () => {
it("defaults newly-added suites to supported", () => {
expect(getSuiteSupport("test/e2e/new-suite/new-suite.test.ts")).toEqual({
status: "supported",
feature: null,
reason: null,
});
});
it("keeps deferred, Vite-equivalent, and unsupported states distinct", () => {
const counts = Object.values(SUITE_SUPPORT_POLICY).reduce(
(result, policy) => {
result[policy.status]++;
return result;
},
{ deferred: 0, "needs-vite-equivalent": 0, unsupported: 0 },
);
expect(counts).toEqual({
deferred: 25,
"needs-vite-equivalent": 3,
unsupported: 6,
});
expect(NON_SUPPORTED_SUITES).toHaveLength(34);
expect(CLASSIFIED_SUITES).toHaveLength(69);
expect(new Set(CLASSIFIED_SUITES).size).toBe(69);
});
it("classifies the mixed legacy Edge Runtime suite at file scope", () => {
const suite = "test/e2e/app-dir/next-after-app-deploy/index.test.ts";
expect(getSuiteSupport(suite)).toEqual({
status: "unsupported",
feature: "Next.js dual Node.js and legacy Edge Runtime builds",
reason:
"Vinext uses one Workers/Node-compat server graph and does not implement Next.js's per-route legacy Edge Runtime bundle or route-specific process.env.NEXT_RUNTIME constant. This mixed file couples portable nodejs assertions with legacy edge-runtime variants; cover after() on Workers separately.",
});
expect(NON_SUPPORTED_SUITES).toContain(suite);
});
it("points the upstream worker suite at its Vite and Cloudflare equivalent", () => {
const support = getSuiteSupport("test/e2e/app-dir/worker/worker.test.ts");
expect(support.status).toBe("needs-vite-equivalent");
expect(support.reason).toContain("tests/e2e/nextjs-worker/worker.spec.ts");
expect(support.reason).toContain("Cloudflare plugin");
});
it("uses canonical Next.js suite paths", () => {
for (const suite of NON_SUPPORTED_SUITES) {
expect(suite).toMatch(/^test\/e2e\/.+\.test\.[jt]sx?$/);
expect(getSuiteSupport(suite).reason).toBeTruthy();
}
});
});
describe("compatibility rate buckets", () => {
it("retains raw results while excluding non-supported suites from the supported rate", () => {
const buckets = bucketByRouter([
{
router: "app" as const,
supportStatus: "supported" as const,
passed: 8,
failed: 2,
skipped: 1,
},
{
router: "app" as const,
supportStatus: "deferred" as const,
passed: 1,
failed: 9,
skipped: 0,
},
{
router: "both" as const,
supportStatus: "supported" as const,
passed: 5,
failed: 0,
skipped: 0,
},
]);
expect(buckets.all).toEqual({
files: 3,
passed: 14,
failed: 11,
skipped: 1,
supportedPassed: 13,
supportedFailed: 2,
});
expect(bucketPassRate(buckets.all)).toBeCloseTo(56, 2);
expect(bucketSupportedPassRate(buckets.all)).toBeCloseTo(86.67, 2);
// Mixed suites continue to count toward both router buckets.
expect(buckets.app.supportedPassed).toBe(13);
expect(buckets.pages.supportedPassed).toBe(5);
});
});