Files
caperren-com/test/endpoints.spec.ts
Corwin Perren dac9e80efd
All checks were successful
Build and Test - Staging / test (pull_request) Successful in 5m26s
Build and Test - Staging / build_and_push (pull_request) Successful in 4m16s
Build and Test - Staging / deploy_staging (pull_request) Successful in 3s
Fix unit tests for placeholder site-layout entries
2025-12-12 23:05:47 -08:00

48 lines
1.3 KiB
TypeScript

import { getPaths, siteLayout } from "@data/site-layout.ts";
import { expect, test } from "vitest";
export const setDifference = <T>(a: Set<T>, b: Set<T>) =>
new Set([...a].filter((x) => !b.has(x)));
// Paths that should be known to Astro statically
const astroStaticPaths = new Set(
Object.keys(import.meta.glob("/src/pages/**/*.astro")).map(
(path) =>
path
.replace("/src/pages", "")
.replace(/index\.astro$/, "")
.replace(/\.astro$|\.md$/, "")
.replace(/\/$/, "") || "/",
),
);
// Paths that exist in the site layout
const siteLayoutPaths = new Set([
...getPaths(siteLayout),
...getPaths(siteLayout, [], true),
]);
test("Astro Paths Not Empty", () => {
expect(astroStaticPaths).not.toHaveLength(0);
});
test("Site Layout Paths Not Empty", () => {
expect(siteLayoutPaths).not.toHaveLength(0);
});
test("Pages Missing from Site Layout", () => {
const astroNotLayoutPaths = setDifference(astroStaticPaths, siteLayoutPaths);
expect(astroNotLayoutPaths).toHaveLength(0);
});
test("Pages Missing from Astro Paths", () => {
const siteLayoutNotAstroPaths = setDifference(
siteLayoutPaths,
astroStaticPaths,
);
expect(
siteLayoutNotAstroPaths,
`FOUND: ${[...siteLayoutNotAstroPaths]}`,
).toHaveLength(0);
});