Files
buzz-sheet/tests/public-performance.test.ts
gunshiz d6153be50d
CI / Verify (push) Successful in 3m8s
CI / Build immutable images and deploy (push) Successful in 3m11s
feat : update
2026-10-05 22:40:59 +07:00

98 lines
3.5 KiB
TypeScript

import { readFile } from "node:fs/promises";
import { afterAll, describe, expect, it } from "vitest";
const originalBaseUrl = process.env.BASE_URL;
process.env.BASE_URL = "https://guide.example.test";
const { default: robots } = await import("@/app/robots");
afterAll(() => {
if (originalBaseUrl === undefined) delete process.env.BASE_URL;
else process.env.BASE_URL = originalBaseUrl;
});
async function repositoryFile(path: string): Promise<string> {
return readFile(new URL(`../${path}`, import.meta.url), "utf8");
}
describe("public rendering performance", () => {
it("keeps the directory eligible for a populated static shell", async () => {
const [layout, page] = await Promise.all([
repositoryFile("app/layout.tsx"),
repositoryFile("app/page.tsx"),
]);
expect(layout).not.toContain("export const instant = false");
expect(page).not.toContain("export const instant = false");
expect(page).toContain("async function DirectoryContent()");
expect(page).toContain("await connection()");
expect(page).toContain("fallback={<DirectorySkeleton />}");
});
it("isolates request-time header authentication", async () => {
const header = await repositoryFile("components/public/site-header.tsx");
expect(header).toContain("<Suspense fallback={null}>");
expect(header).toContain("<AdminEditLink");
});
it("gives only the first directory cover high fetch priority", async () => {
const directory = await repositoryFile(
"components/public/structured-directory.tsx",
);
expect(directory).toContain(
'fetchPriority={index === 0 ? "high" : undefined}',
);
expect(directory).not.toContain("preload={index === 0}");
expect(directory).toContain("prefetch={false}");
});
it("publishes a public-only crawler policy", () => {
expect(robots()).toEqual({
rules: {
userAgent: "*",
allow: "/",
disallow: ["/admin", "/api", "/auth", "/login", "/register"],
},
sitemap: "https://guide.example.test/sitemap.xml",
});
});
it("loads AdSense for every visitor, including signed-in admins", async () => {
const [adsense, home, guide, guideSection, adsTxt] = await Promise.all([
repositoryFile("components/public/google-adsense.tsx"),
repositoryFile("app/page.tsx"),
repositoryFile("app/[character]/page.tsx"),
repositoryFile("app/[character]/[page]/page.tsx"),
repositoryFile("public/ads.txt"),
]);
expect(adsense).not.toContain("authClient.useSession()");
expect(adsense).not.toContain('from "@/lib/auth/client"');
expect(adsense).toContain('process.env.NODE_ENV !== "production"');
expect(adsense).toContain("pagead2.googlesyndication.com");
expect(adsense).toContain("<script");
expect(adsense).not.toContain('from "next/script"');
expect(home).toContain("<GoogleAdsense />");
expect(guide).toContain("<GoogleAdsense />");
expect(guideSection).toContain("<GoogleAdsense />");
expect(adsTxt.trim()).toBe(
"google.com, pub-9687404323559597, DIRECT, f08c47fec0942fa0",
);
});
it("allows the production analytics and advertising endpoints", async () => {
const headers = await repositoryFile("lib/security/headers.ts");
expect(headers).toContain("https://static.cloudflareinsights.com");
expect(headers).toContain("https://*.adtrafficquality.google");
});
it("accepts Next.js deployment metadata on the document root", async () => {
const layout = await repositoryFile("app/layout.tsx");
expect(layout).toContain("suppressHydrationWarning");
});
});