Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/marketing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"stage:install-scripts": "node scripts/stage-install-scripts.mjs",
"dev": "node scripts/stage-install-scripts.mjs && astro dev",
"build": "node scripts/stage-install-scripts.mjs && astro build",
"preview": "astro preview"
"preview": "astro preview",
"test": "vp test run"
},
"dependencies": {
"@fontsource-variable/inter": "^5.3.0",
Expand Down
18 changes: 18 additions & 0 deletions apps/marketing/src/lib/releases.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { afterEach, describe, expect, it, vi } from "vite-plus/test";

import { fetchLatestRelease } from "./releases";

afterEach(() => {
vi.unstubAllGlobals();
});

describe("fetchLatestRelease", () => {
it("rejects a GitHub API error response instead of returning it as a release", async () => {
vi.stubGlobal("sessionStorage", { getItem: () => null });
vi.stubGlobal("fetch", async () =>
Response.json({ message: "API rate limit exceeded" }, { status: 403 }),
);

await expect(fetchLatestRelease("stable")).rejects.toThrow("403");
});
});
10 changes: 8 additions & 2 deletions apps/marketing/src/lib/releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ function cacheKey(channel: ReleaseChannel) {
return `t3code-${channel}-release`;
}

async function fetchJson<T>(url: string): Promise<T> {
const response = await fetch(url);
if (!response.ok) throw new Error(`GitHub API responded ${response.status}`);
return response.json();
}

async function fetchStable(): Promise<Release> {
return fetch(LATEST_API_URL).then((r) => r.json());
return fetchJson(LATEST_API_URL);
}

async function fetchNightly(): Promise<Release> {
const list: Release[] = await fetch(LIST_API_URL).then((r) => r.json());
const list = await fetchJson<Release[]>(LIST_API_URL);
const nightly = Array.isArray(list)
? list.find((release) => release.tag_name?.includes("-nightly."))
: undefined;
Expand Down
Loading