1import { describe, expect, it } from "vite-plus/test";
2
3import { cliArchiveTarCommand, newestCliReleaseVersion, parseChecksums } from "./cliRelease.ts";
4
5describe("cliRelease", () => {
6 it("parses sha256sum output including binary-mode markers", () => {
7 const checksums = parseChecksums(
8 [
9 `${"a".repeat(64)} t3-1.2.3-linux-x64.tar.gz`,
10 `${"B".repeat(64)} *t3-1.2.3-win32-x64.zip`,
11 "not a checksum line",
12 "",
13 ].join("\n"),
14 );
15 expect(checksums.get("t3-1.2.3-linux-x64.tar.gz")).toBe("a".repeat(64));
16 expect(checksums.get("t3-1.2.3-win32-x64.zip")).toBe("b".repeat(64));
17 expect(checksums.size).toBe(2);
18 });
19
20 it("extracts with the System32 bsdtar on Windows and plain tar elsewhere", () => {
21 expect(cliArchiveTarCommand("linux", {})).toBe("tar");
22 expect(cliArchiveTarCommand("win32", { SystemRoot: "D:\\Win" })).toBe(
23 "D:\\Win\\System32\\tar.exe",
24 );
25 expect(cliArchiveTarCommand("win32", {})).toBe("C:\\Windows\\System32\\tar.exe");
26 });
27
28 it("picks the newest non-draft release on the requested channel", () => {
29 const releases = [
30 { tag_name: "v1.2.4-preview.20260912.9", draft: true },
31 { tag_name: "v1.2.4-preview.20260912.8" },
32 { tag_name: "v1.2.4-nightly.20260912.7" },
33 { tag_name: "desktop-preview" },
34 { tag_name: "v1.2.3" },
35 { tag_name: "v1.2.3-nightly.20260911.2" },
36 ];
37 expect(newestCliReleaseVersion(releases, "preview")).toBe("1.2.4-preview.20260912.8");
38 expect(newestCliReleaseVersion(releases, "nightly")).toBe("1.2.4-nightly.20260912.7");
39 expect(newestCliReleaseVersion(releases, "stable")).toBe("1.2.3");
40 expect(newestCliReleaseVersion([{ tag_name: "v1.2.3" }], "preview")).toBeUndefined();
41 });
42});