feat: add extension update check
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import {
|
||||
compareExtensionVersions,
|
||||
parseUpdateManifest
|
||||
} from "../src/shared/update-check";
|
||||
|
||||
describe("update-check", () => {
|
||||
test("compares dotted extension versions numerically", () => {
|
||||
expect(compareExtensionVersions("0.2.0421.3", "0.2.0421.2")).toBeGreaterThan(0);
|
||||
expect(compareExtensionVersions("0.2.10.0", "0.2.9.9")).toBeGreaterThan(0);
|
||||
expect(compareExtensionVersions("0.2.0421.2", "0.2.0421.2")).toBe(0);
|
||||
expect(compareExtensionVersions("0.2.0421.1", "0.2.0421.2")).toBeLessThan(0);
|
||||
});
|
||||
|
||||
test("parses a valid update manifest", () => {
|
||||
expect(
|
||||
parseUpdateManifest({
|
||||
guideUrl: "https://cos.example.com/guide.pdf",
|
||||
latestVersion: "0.2.0421.3",
|
||||
minSupportedVersion: "0.2.0421.2",
|
||||
publishedAt: "2026-05-19",
|
||||
releaseNotes: ["支持检查更新"],
|
||||
zipUrl: "https://cos.example.com/plugin.zip"
|
||||
})
|
||||
).toEqual({
|
||||
guideUrl: "https://cos.example.com/guide.pdf",
|
||||
latestVersion: "0.2.0421.3",
|
||||
minSupportedVersion: "0.2.0421.2",
|
||||
publishedAt: "2026-05-19",
|
||||
releaseNotes: ["支持检查更新"],
|
||||
zipUrl: "https://cos.example.com/plugin.zip"
|
||||
});
|
||||
});
|
||||
|
||||
test("rejects invalid update manifests", () => {
|
||||
expect(parseUpdateManifest({ latestVersion: "0.2.0421.3" })).toBeNull();
|
||||
expect(
|
||||
parseUpdateManifest({
|
||||
guideUrl: "javascript:alert(1)",
|
||||
latestVersion: "0.2.0421.3",
|
||||
minSupportedVersion: "0.2.0421.2",
|
||||
publishedAt: "2026-05-19",
|
||||
releaseNotes: [],
|
||||
zipUrl: "https://cos.example.com/plugin.zip"
|
||||
})
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user