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

cliRelease.test.ts

95 lines4.0 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 // Built but not published (macOS x64 segfaults under Rosetta when
27 // cross-injected; the arm64 Linux and Windows runners do not exist yet).
28 expect(cliArchivePlatformKey("darwin", "x64")).toBeUndefined();
29 expect(cliArchivePlatformKey("linux", "arm64")).toBeUndefined();
30 expect(cliArchivePlatformKey("win32", "arm64")).toBeUndefined();
31 expect(cliArchivePlatformKey("freebsd", "x64")).toBeUndefined();
32 expect(cliArchivePlatformKey("linux", "ia32")).toBeUndefined();
33 });
34​
35 it("resolves download URLs under the tagged release, honoring a mirror", () => {
36 expect(cliReleaseDownloadBaseUrl("1.2.3")).toBe(
37 "https://github.com/pingdotgg/t3code/releases/download/v1.2.3",
38 );
39 expect(cliReleaseDownloadBaseUrl("1.2.3", "https://mirror.example/t3/")).toBe(
40 "https://mirror.example/t3/v1.2.3",
41 );
42 });
43​
44 it("parses sha256sum output including binary-mode markers", () => {
45 const checksums = parseChecksums(
46 [
47 `${"a".repeat(64)} t3-1.2.3-linux-x64.tar.gz`,
48 `${"B".repeat(64)} *t3-1.2.3-win32-x64.zip`,
49 "not a checksum line",
50 "",
51 ].join("\n"),
52 );
53 expect(checksums.get("t3-1.2.3-linux-x64.tar.gz")).toBe("a".repeat(64));
54 expect(checksums.get("t3-1.2.3-win32-x64.zip")).toBe("b".repeat(64));
55 expect(checksums.size).toBe(2);
56 });
57​
58 it("extracts with the System32 bsdtar on Windows and plain tar elsewhere", () => {
59 expect(cliArchiveTarCommand("linux", {})).toBe("tar");
60 expect(cliArchiveTarCommand("win32", { SystemRoot: "D:\\Win" })).toBe(
61 "D:\\Win\\System32\\tar.exe",
62 );
63 expect(cliArchiveTarCommand("win32", {})).toBe("C:\\Windows\\System32\\tar.exe");
64 });
65​
66 it("derives the release channel from the version alone", () => {
67 expect(cliReleaseChannelOf("1.2.3")).toBe("stable");
68 expect(cliReleaseChannelOf("1.2.3-nightly.20260911.4")).toBe("nightly");
69 expect(cliReleaseChannelOf("1.2.3-preview.20260911.4")).toBe("preview");
70 // A prerelease that is not one of our trains is not silently a nightly.
71 expect(cliReleaseChannelOf("1.2.3-rc.1")).toBe("stable");
72 });
73​
74 it("picks the newest non-draft release on the requested channel", () => {
75 const releases = [
76 { tag_name: "v1.2.4-preview.20260912.9", draft: true },
77 { tag_name: "v1.2.4-preview.20260912.8" },
78 { tag_name: "v1.2.4-nightly.20260912.7" },
79 { tag_name: "desktop-preview" },
80 { tag_name: "v1.2.3" },
81 { tag_name: "v1.2.3-nightly.20260911.2" },
82 ];
83 expect(newestCliReleaseVersion(releases, "preview")).toBe("1.2.4-preview.20260912.8");
84 expect(newestCliReleaseVersion(releases, "nightly")).toBe("1.2.4-nightly.20260912.7");
85 expect(newestCliReleaseVersion(releases, "stable")).toBe("1.2.3");
86 expect(newestCliReleaseVersion([{ tag_name: "v1.2.3" }], "preview")).toBeUndefined();
87 });
88​
89 it("pages through the release index at the largest page GitHub allows", () => {
90 expect(cliReleaseIndexPageUrl(1)).toBe(
91 "https://api.github.com/repos/pingdotgg/t3code/releases?per_page=100&page=1",
92 );
93 expect(cliReleaseIndexPageUrl(3)).toContain("page=3");
94 });
95});