test(web): catch experimental-edge in the edge-runtime scan

The scan matched only `export const runtime = "edge"` in .ts/.tsx files.
It now also matches `experimental-edge` and `runtime: "edge"` object
forms, and scans .js/.jsx/.mjs files under app/.

Test: product-telemetry-route.test.ts 3/3 (1 new; failed with the old
pattern on experimental-edge).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_014ZwqatxgVFxHvovngywnks
This commit is contained in:
Hunter BandClaude Opus 5.5 committed 2026-09-29 04:41:57 -07:00
1 parent 992e2dc319
commit accf2cf863
1 file changed
+18 -2
+18 -2
View File
@@ -10,16 +10,32 @@ function sourceFiles(dir: string): string[] {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
const path = join(dir, entry.name);
if (entry.isDirectory()) return sourceFiles(path);
return /\.(ts|tsx)$/.test(entry.name) ? [path] : [];
return /\.(m?[jt]sx?)$/.test(entry.name) ? [path] : [];
});
}
// `export const runtime = "edge"`, `runtime: 'experimental-edge'`, and so on.
// Route segment config only takes effect in app/ files, so that is the scan.
const EDGE_RUNTIME =
/(?:\bexport\s+const\s+runtime\s*=|\bruntime\s*:)\s*["'](?:experimental-)?edge["']/;
describe("/api/product-telemetry", () => {
it("recognizes edge and experimental-edge declarations", () => {
for (const source of [
'export const runtime = "edge";',
"export const runtime = 'experimental-edge';",
'export const config = { runtime: "edge" };',
]) {
expect(EDGE_RUNTIME.test(source), source).toBe(true);
}
expect(EDGE_RUNTIME.test('export const runtime = "nodejs";')).toBe(false);
});
// @opennextjs/cloudflare does not support the edge runtime; the deployed
// telemetry route answered every request with a 500 while it declared it.
it("no app route or page opts into the edge runtime", () => {
const edge = sourceFiles(APP_DIR).filter((file) =>
/export\s+const\s+runtime\s*=\s*["']edge["']/.test(readFileSync(file, "utf8")),
EDGE_RUNTIME.test(readFileSync(file, "utf8")),
);
expect(edge).toEqual([]);
});