import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { resolveNpmChannelTag } from "./update-check.js"; describe("resolveNpmChannelTag", () => { let versionByTag: Record; beforeEach(() => { versionByTag = {}; vi.stubGlobal( "fetch", vi.fn(async (input: RequestInfo | URL) => { const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url; const tag = decodeURIComponent(url.split("/").pop() ?? ""); const version = versionByTag[tag] ?? null; return { ok: version != null, status: version != null ? 200 : 404, json: async () => ({ version }), } as Response; }), ); }); afterEach(() => { vi.unstubAllGlobals(); }); it("falls back to latest when beta is older", async () => { versionByTag.beta = "2026.1.19-beta.1"; versionByTag.latest = "2026.1.20-1"; const resolved = await resolveNpmChannelTag({ channel: "beta", timeoutMs: 1000 }); expect(resolved).toEqual({ tag: "latest", version: "2026.1.20-1" }); }); it("keeps beta when beta is not older", async () => { versionByTag.beta = "2026.1.20-beta.1"; versionByTag.latest = "2026.1.20-1"; const resolved = await resolveNpmChannelTag({ channel: "beta", timeoutMs: 1000 }); expect(resolved).toEqual({ tag: "beta", version: "2026.1.20-beta.1" }); }); });