test: strengthen regression coverage and trim low-value checks

This commit is contained in:
Peter Steinberger
2026-03-22 07:37:17 +00:00
parent f537ea90ed
commit b4656f193a
28 changed files with 656 additions and 212 deletions

View File

@@ -4,22 +4,53 @@ import { canonicalSparkleBuildFromVersion } from "../scripts/sparkle-build.ts";
const APPCAST_URL = new URL("../appcast.xml", import.meta.url);
type AppcastItem = {
raw: string;
shortVersion: string | null;
sparkleVersion: number | null;
};
function parseItems(appcast: string): AppcastItem[] {
return [...appcast.matchAll(/<item>([\s\S]*?)<\/item>/g)].map((match) => {
const raw = match[1] ?? "";
const shortVersion =
raw.match(/<sparkle:shortVersionString>([^<]+)<\/sparkle:shortVersionString>/)?.[1] ?? null;
const sparkleVersionText = raw.match(/<sparkle:version>([^<]+)<\/sparkle:version>/)?.[1] ?? "";
const sparkleVersion = Number.parseInt(sparkleVersionText, 10);
return {
raw,
shortVersion,
sparkleVersion: Number.isFinite(sparkleVersion) ? sparkleVersion : null,
};
});
}
describe("appcast.xml", () => {
it("uses canonical sparkle build for the latest stable appcast entry", () => {
it("keeps every appcast entry on the canonical sparkle build for its version", () => {
const appcast = readFileSync(APPCAST_URL, "utf8");
const items = [...appcast.matchAll(/<item>([\s\S]*?)<\/item>/g)].map((match) => match[1] ?? "");
const items = parseItems(appcast);
expect(items.length).toBeGreaterThan(0);
const stableItem = items.find((item) => /<sparkle:version>\d+90<\/sparkle:version>/.test(item));
expect(stableItem).toBeDefined();
for (const item of items) {
expect(item.shortVersion, item.raw).not.toBeNull();
expect(item.sparkleVersion, item.raw).not.toBeNull();
expect(item.sparkleVersion).toBe(canonicalSparkleBuildFromVersion(item.shortVersion!));
}
});
const shortVersion = stableItem?.match(
/<sparkle:shortVersionString>([^<]+)<\/sparkle:shortVersionString>/,
)?.[1];
const sparkleVersion = stableItem?.match(/<sparkle:version>([^<]+)<\/sparkle:version>/)?.[1];
it("keeps the first stable appcast entry aligned with the newest stable build", () => {
const appcast = readFileSync(APPCAST_URL, "utf8");
const stableItems = parseItems(appcast).filter(
(item) => item.sparkleVersion !== null && item.sparkleVersion % 100 === 90,
);
expect(shortVersion).toBeDefined();
expect(sparkleVersion).toBeDefined();
expect(sparkleVersion).toBe(String(canonicalSparkleBuildFromVersion(shortVersion!)));
expect(stableItems.length).toBeGreaterThan(0);
const firstStable = stableItems[0];
const newestStable = [...stableItems].toSorted(
(left, right) => (right.sparkleVersion ?? 0) - (left.sparkleVersion ?? 0),
)[0];
expect(firstStable.sparkleVersion).toBe(newestStable.sparkleVersion);
expect(firstStable.shortVersion).toBe(newestStable.shortVersion);
});
});