Files
Rune-Spec/tests/scripts/release.test.ts

56 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from "bun:test";
import { parseSemver, bumpVersion } from "../../scripts/release";
describe("parseSemver", () => {
it("解析标准版本号 1.2.3", () => {
expect(parseSemver("1.2.3")).toEqual({ major: 1, minor: 2, patch: 3 });
});
it("解析 0.0.0", () => {
expect(parseSemver("0.0.0")).toEqual({ major: 0, minor: 0, patch: 0 });
});
it("解析大版本号 99.999.1", () => {
expect(parseSemver("99.999.1")).toEqual({ major: 99, minor: 999, patch: 1 });
});
it("非三位格式抛出异常", () => {
expect(() => parseSemver("1.2")).toThrow("无效的版本号格式");
expect(() => parseSemver("1.2.3.4")).toThrow("无效的版本号格式");
});
it("非数字格式抛出异常", () => {
expect(() => parseSemver("a.b.c")).toThrow("无效的版本号格式");
expect(() => parseSemver("1.2.3-beta")).toThrow("无效的版本号格式");
});
it("负数抛出异常", () => {
expect(() => parseSemver("-1.2.3")).toThrow("无效的版本号格式");
});
it("四段格式抛出异常", () => {
expect(() => parseSemver("1.5.3.2")).toThrow("无效的版本号格式");
});
});
describe("bumpVersion", () => {
it("major 递增0.1.0 → 1.0.0", () => {
expect(bumpVersion("0.1.0", "major")).toBe("1.0.0");
});
it("minor 递增0.1.0 → 0.2.0", () => {
expect(bumpVersion("0.1.0", "minor")).toBe("0.2.0");
});
it("patch 递增0.1.0 → 0.1.1", () => {
expect(bumpVersion("0.1.0", "patch")).toBe("0.1.1");
});
it("major 递增低位归零1.5.3 → 2.0.0", () => {
expect(bumpVersion("1.5.3", "major")).toBe("2.0.0");
});
it("minor 递增 patch 归零1.5.3 → 1.6.0", () => {
expect(bumpVersion("1.5.3", "minor")).toBe("1.6.0");
});
it("patch 递增不影响高位1.5.3 → 1.5.4", () => {
expect(bumpVersion("1.5.3", "patch")).toBe("1.5.4");
});
it("大数字递增正确", () => {
expect(bumpVersion("99.999.1", "minor")).toBe("99.1000.0");
});
it("无效版本号抛出异常", () => {
expect(() => bumpVersion("invalid", "minor")).toThrow("无效的版本号格式");
});
});