55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import robots from "@/app/robots";
|
|
|
|
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={<div className="min-h-svh"');
|
|
});
|
|
|
|
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", "/register"],
|
|
},
|
|
sitemap: "https://guide.example.test/sitemap.xml",
|
|
});
|
|
});
|
|
});
|