Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

cliRelease.test.ts

92 lines3.8 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 cliArchiveFileName,
5 cliArchivePlatformKey,
6 cliArchiveTarCommand,
7 cliReleaseDownloadBaseUrl,
8 cliReleaseChannelOf,
9 cliReleaseIndexPageUrl,
10 newestCliReleaseVersion,
11 parseChecksums,
12} from "./cliRelease.ts";
13​
14describe("cliRelease", () => {
15 it("names archives by version and platform, zip only on Windows", () => {
16 expect(cliArchiveFileName("1.2.3-preview.20260911.4", "linux-x64")).toBe(
17 "t3-1.2.3-preview.20260911.4-linux-x64.tar.gz",
18 );
19 expect(cliArchiveFileName("1.2.3", "win32-x64")).toBe("t3-1.2.3-win32-x64.zip");
20 });
21​
22 it("only maps platforms and architectures that have a release archive", () => {
23 expect(cliArchivePlatformKey("darwin", "arm64")).toBe("darwin-arm64");
24 expect(cliArchivePlatformKey("linux", "x64")).toBe("linux-x64");
25 expect(cliArchivePlatformKey("win32", "x64")).toBe("win32-x64");
26 expect(cliArchivePlatformKey("darwin", "x64")).toBeUndefined();
27 expect(cliArchivePlatformKey("linux", "arm64")).toBe("linux-arm64");
28 expect(cliArchivePlatformKey("win32", "arm64")).toBe("win32-arm64");
29 expect(cliArchivePlatformKey("freebsd", "x64")).toBeUndefined();
30 expect(cliArchivePlatformKey("linux", "ia32")).toBeUndefined();
31 });
32​
33 it("resolves download URLs under the tagged release, honoring a mirror", () => {
34 expect(cliReleaseDownloadBaseUrl("1.2.3")).toBe(
35 "https://github.com/pingdotgg/t3code/releases/download/v1.2.3",
36 );
37 expect(cliReleaseDownloadBaseUrl("1.2.3", "https://mirror.example/t3/")).toBe(
38 "https://mirror.example/t3/v1.2.3",
39 );
40 });
41​
42 it("parses sha256sum output including binary-mode markers", () => {
43 const checksums = parseChecksums(
44 [
45 `${"a".repeat(64)} t3-1.2.3-linux-x64.tar.gz`,
46 `${"B".repeat(64)} *t3-1.2.3-win32-x64.zip`,
47 "not a checksum line",
48 "",
49 ].join("\n"),
50 );
51 expect(checksums.get("t3-1.2.3-linux-x64.tar.gz")).toBe("a".repeat(64));
52 expect(checksums.get("t3-1.2.3-win32-x64.zip")).toBe("b".repeat(64));
53 expect(checksums.size).toBe(2);
54 });
55​
56 it("extracts with the System32 bsdtar on Windows and plain tar elsewhere", () => {
57 expect(cliArchiveTarCommand("linux", {})).toBe("tar");
58 expect(cliArchiveTarCommand("win32", { SystemRoot: "D:\\Win" })).toBe(
59 "D:\\Win\\System32\\tar.exe",
60 );
61 expect(cliArchiveTarCommand("win32", {})).toBe("C:\\Windows\\System32\\tar.exe");
62 });
63​
64 it("derives the release channel from the version alone", () => {
65 expect(cliReleaseChannelOf("1.2.3")).toBe("stable");
66 expect(cliReleaseChannelOf("1.2.3-nightly.20260911.4")).toBe("nightly");
67 expect(cliReleaseChannelOf("1.2.3-preview.20260911.4")).toBe("preview");
68 expect(cliReleaseChannelOf("1.2.3-rc.1")).toBe("stable");
69 });
70​
71 it("picks the newest non-draft release on the requested channel", () => {
72 const releases = [
73 { tag_name: "v1.2.4-preview.20260912.9", draft: true },
74 { tag_name: "v1.2.4-preview.20260912.8" },
75 { tag_name: "v1.2.4-nightly.20260912.7" },
76 { tag_name: "desktop-preview" },
77 { tag_name: "v1.2.3" },
78 { tag_name: "v1.2.3-nightly.20260911.2" },
79 ];
80 expect(newestCliReleaseVersion(releases, "preview")).toBe("1.2.4-preview.20260912.8");
81 expect(newestCliReleaseVersion(releases, "nightly")).toBe("1.2.4-nightly.20260912.7");
82 expect(newestCliReleaseVersion(releases, "stable")).toBe("1.2.3");
83 expect(newestCliReleaseVersion([{ tag_name: "v1.2.3" }], "preview")).toBeUndefined();
84 });
85​
86 it("pages through the release index at the largest page GitHub allows", () => {
87 expect(cliReleaseIndexPageUrl(1)).toBe(
88 "https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=1",
89 );
90 expect(cliReleaseIndexPageUrl(3)).toContain("page=3");
91 });
92});