mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 19:50:22 +00:00
test: expand npm install and update check coverage
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { compareSemverStrings, resolveNpmChannelTag } from "./update-check.js";
|
||||
import {
|
||||
compareSemverStrings,
|
||||
fetchNpmLatestVersion,
|
||||
fetchNpmTagVersion,
|
||||
formatGitInstallLabel,
|
||||
resolveNpmChannelTag,
|
||||
} from "./update-check.js";
|
||||
|
||||
describe("compareSemverStrings", () => {
|
||||
it("handles stable and prerelease precedence for both legacy and beta formats", () => {
|
||||
@@ -72,4 +78,81 @@ describe("resolveNpmChannelTag", () => {
|
||||
|
||||
expect(resolved).toEqual({ tag: "latest", version: "1.0.1" });
|
||||
});
|
||||
|
||||
it("keeps non-beta channels unchanged", async () => {
|
||||
versionByTag.latest = "1.0.3";
|
||||
|
||||
await expect(resolveNpmChannelTag({ channel: "stable", timeoutMs: 1000 })).resolves.toEqual({
|
||||
tag: "latest",
|
||||
version: "1.0.3",
|
||||
});
|
||||
});
|
||||
|
||||
it("exposes tag fetch helpers for success and http failures", async () => {
|
||||
versionByTag.latest = "1.0.4";
|
||||
|
||||
await expect(fetchNpmTagVersion({ tag: "latest", timeoutMs: 1000 })).resolves.toEqual({
|
||||
tag: "latest",
|
||||
version: "1.0.4",
|
||||
});
|
||||
await expect(fetchNpmLatestVersion({ timeoutMs: 1000 })).resolves.toEqual({
|
||||
latestVersion: "1.0.4",
|
||||
error: undefined,
|
||||
});
|
||||
await expect(fetchNpmTagVersion({ tag: "beta", timeoutMs: 1000 })).resolves.toEqual({
|
||||
tag: "beta",
|
||||
version: null,
|
||||
error: "HTTP 404",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatGitInstallLabel", () => {
|
||||
it("formats branch, detached tag, and non-git installs", () => {
|
||||
expect(
|
||||
formatGitInstallLabel({
|
||||
root: "/repo",
|
||||
installKind: "git",
|
||||
packageManager: "pnpm",
|
||||
git: {
|
||||
root: "/repo",
|
||||
sha: "1234567890abcdef",
|
||||
tag: null,
|
||||
branch: "main",
|
||||
upstream: "origin/main",
|
||||
dirty: false,
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
fetchOk: true,
|
||||
},
|
||||
}),
|
||||
).toBe("main · @ 12345678");
|
||||
|
||||
expect(
|
||||
formatGitInstallLabel({
|
||||
root: "/repo",
|
||||
installKind: "git",
|
||||
packageManager: "pnpm",
|
||||
git: {
|
||||
root: "/repo",
|
||||
sha: "abcdef1234567890",
|
||||
tag: "v1.2.3",
|
||||
branch: "HEAD",
|
||||
upstream: null,
|
||||
dirty: false,
|
||||
ahead: 0,
|
||||
behind: 0,
|
||||
fetchOk: null,
|
||||
},
|
||||
}),
|
||||
).toBe("detached · tag v1.2.3 · @ abcdef12");
|
||||
|
||||
expect(
|
||||
formatGitInstallLabel({
|
||||
root: null,
|
||||
installKind: "package",
|
||||
packageManager: "pnpm",
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user