52 lines
2.2 KiB
TypeScript
52 lines
2.2 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { compareSemVer, isNewerVersion, matchAssetForPlatform, type GitHubAsset } from "./update.js";
|
|
|
|
describe("update version comparator", () => {
|
|
test("correctly identifies newer semantic versions", () => {
|
|
expect(isNewerVersion("0.2.1", "0.2.0")).toBe(true);
|
|
expect(isNewerVersion("1.0.0", "0.2.0")).toBe(true);
|
|
expect(isNewerVersion("0.3.0", "0.2.1")).toBe(true);
|
|
expect(isNewerVersion("0.2.0", "0.2.0")).toBe(false);
|
|
expect(isNewerVersion("0.1.9", "0.2.0")).toBe(false);
|
|
expect(isNewerVersion("0.2.0", "0.2.1")).toBe(false);
|
|
});
|
|
|
|
test("compareSemVer handles tags, major, minor, and patch", () => {
|
|
expect(compareSemVer("v0.2.1", "0.2.0")).toBe(1);
|
|
expect(compareSemVer("0.2.0", "v0.2.1")).toBe(-1);
|
|
expect(compareSemVer("v0.2.1", "v0.2.1")).toBe(0);
|
|
expect(compareSemVer("1.0.0", "0.9.9")).toBe(1);
|
|
expect(compareSemVer("0.1.0", "0.2.1")).toBe(-1);
|
|
});
|
|
});
|
|
|
|
describe("matchAssetForPlatform", () => {
|
|
const assets: GitHubAsset[] = [
|
|
{ name: "hose-use-darwin-arm64", downloadUrl: "https://example.com/darwin-arm64", size: 100 },
|
|
{ name: "hose-use-darwin-x64", downloadUrl: "https://example.com/darwin-x64", size: 100 },
|
|
{ name: "hose-use-linux-x64.tar.gz", downloadUrl: "https://example.com/linux-x64.tar.gz", size: 100 },
|
|
{ name: "hose-use-linux-arm64", downloadUrl: "https://example.com/linux-arm64", size: 100 },
|
|
{ name: "hose-use-windows-x64.zip", downloadUrl: "https://example.com/win-x64.zip", size: 100 },
|
|
];
|
|
|
|
test("matches darwin arm64", () => {
|
|
const matched = matchAssetForPlatform(assets, "darwin", "arm64");
|
|
expect(matched?.name).toBe("hose-use-darwin-arm64");
|
|
});
|
|
|
|
test("matches darwin x64", () => {
|
|
const matched = matchAssetForPlatform(assets, "darwin", "x64");
|
|
expect(matched?.name).toBe("hose-use-darwin-x64");
|
|
});
|
|
|
|
test("matches linux x64 archive", () => {
|
|
const matched = matchAssetForPlatform(assets, "linux", "x64");
|
|
expect(matched?.name).toBe("hose-use-linux-x64.tar.gz");
|
|
});
|
|
|
|
test("matches windows x64 archive", () => {
|
|
const matched = matchAssetForPlatform(assets, "windows", "x64");
|
|
expect(matched?.name).toBe("hose-use-windows-x64.zip");
|
|
});
|
|
});
|