Файли
openidea/scripts/nightly-prepare.test.ts
T
2026-12-02 00:00:57 +08:00

66 рядки
2.6 KiB
TypeScript

// @vitest-environment node
import { describe, expect, it } from "vitest";
import { NIGHTLY_ENDPOINT, NIGHTLY_TARGETS, msiVersion, nightlyVersion, setNightlyConfig } from "./nightly-prepare.ts";
describe("nightlyVersion", () => {
it("is the next patch's nightly once the current version is released", () => {
expect(nightlyVersion("0.1.55", true, "20261130", new Set(["v0.1.55"]))).toBe("0.1.56-nightly.20261130");
});
it("is the current version's nightly while that is not released", () => {
expect(nightlyVersion("0.1.56", false, "20261130", new Set())).toBe("0.1.56-nightly.20261130");
});
it("numbers further nightlies of the same day, which sort after the first", () => {
const tags = new Set(["v0.1.56-nightly.20261130", "v0.1.56-nightly.20261130.2"]);
expect(nightlyVersion("0.1.55", true, "20261130", tags)).toBe("0.1.56-nightly.20261130.3");
});
it("refuses a malformed date or version", () => {
expect(() => nightlyVersion("0.1.55", true, "2026-11-30", new Set())).toThrow();
expect(() => nightlyVersion("0.1", true, "20261130", new Set())).toThrow();
});
});
describe("msiVersion", () => {
it("is the last release with the build number", () => {
expect(msiVersion("0.1.55", true, 42)).toBe("0.1.55.42");
expect(msiVersion("0.1.56", false, 42)).toBe("0.1.55.42");
expect(msiVersion("0.2.0", false, 42)).toBe("0.2.0.42");
});
it("refuses a build number MSI cannot hold", () => {
expect(() => msiVersion("0.1.55", true, 65536)).toThrow();
expect(() => msiVersion("0.1.55", true, Number.NaN)).toThrow();
});
});
describe("setNightlyConfig", () => {
it("sets the version, the nightly manifest, the MSI version and drops RPM, keeping the rest", () => {
const json = JSON.stringify(
{
version: "0.1.55",
bundle: { targets: "all", macOS: { minimumSystemVersion: "11.0" } },
plugins: { updater: { pubkey: "key", endpoints: ["https://example.com/latest.json"] } },
},
null,
2,
);
const config = JSON.parse(setNightlyConfig(json, "0.1.56-nightly.20261130", "0.1.55.42"));
expect(config.version).toBe("0.1.56-nightly.20261130");
expect(config.plugins.updater).toEqual({ pubkey: "key", endpoints: [NIGHTLY_ENDPOINT] });
expect(config.bundle).toEqual({
targets: NIGHTLY_TARGETS,
macOS: { minimumSystemVersion: "11.0" },
windows: { wix: { version: "0.1.55.42" } },
});
expect(config.bundle.targets).not.toContain("rpm");
});
it("refuses a config without the updater", () => {
expect(() =>
setNightlyConfig(JSON.stringify({ version: "0.1.55" }), "0.1.56-nightly.20261130", "0.1.55.1"),
).toThrow();
});
});