askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
toolbar: Back and Forward are greyed out when there's nowhere to go
cc08c7a
1 week, 2 days ago
History
version.test.ts · 2.3 KB · 44 lines
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { compareVersions, displayVersion, nextVersion, parseVersion, semverVersion, shownVersion } from "../src/version.ts"; |
| 3 | |
| 4 | describe("version: year.month and a release count", () => { |
| 5 | it("shows package.json's semver with the month padded and a v before the count", () => { |
| 6 | expect(displayVersion("2026.11.1")).toBe("2026.11v1"); |
| 7 | expect(displayVersion("2026.1.3")).toBe("2026.01v3"); |
| 8 | expect(displayVersion("2026.12.1-beta.2")).toBe("2026.12v1-beta.2"); |
| 9 | }); |
| 10 | |
| 11 | it("writes semver without a leading zero, which semver forbids", () => { |
| 12 | const v = parseVersion("2027.01v1"); |
| 13 | expect(v && semverVersion(v)).toBe("2027.1.1"); |
| 14 | }); |
| 15 | |
| 16 | it("reads either spelling, and nothing else", () => { |
| 17 | expect(parseVersion("2026.11v1")).toEqual({ year: 2026, month: 11, n: 1, pre: "" }); |
| 18 | expect(parseVersion("2026.11.1")).toEqual({ year: 2026, month: 11, n: 1, pre: "" }); |
| 19 | for (const bad of ["0.1.0", "2026.13.1", "2026.11.0", "2026.011.1", "2026.11v01", "2026.1v1", "2026.11", "v2026.11.1"]) { |
| 20 | expect(parseVersion(bad), bad).toBeNull(); |
| 21 | } |
| 22 | expect(displayVersion("0.1.0")).toBe("0.1.0"); |
| 23 | }); |
| 24 | |
| 25 | it("counts up within a month and starts again at 1 in a new one (by the UTC month)", () => { |
| 26 | const nov = new Date("2026-11-23T12:00:00Z"); |
| 27 | expect(shownVersion(nextVersion("0.1.0", nov))).toBe("2026.11v1"); |
| 28 | expect(shownVersion(nextVersion("2026.11.1", nov))).toBe("2026.11v2"); |
| 29 | expect(shownVersion(nextVersion("2026.11.2", new Date("2026-12-01T00:00:00Z")))).toBe("2026.12v1"); |
| 30 | expect(shownVersion(nextVersion("2026.12.1", new Date("2027-01-01T00:30:00Z")))).toBe("2027.01v1"); |
| 31 | expect(shownVersion(nextVersion("2026.11.1", new Date("2026-11-30T23:59:59-05:00")))).toBe("2026.12v1"); // already December in UTC |
| 32 | }); |
| 33 | |
| 34 | it("after a pre-release, the next is that release, final", () => { |
| 35 | expect(shownVersion(nextVersion("2026.12.1-beta.2", new Date("2026-12-05T00:00:00Z")))).toBe("2026.12v1"); |
| 36 | }); |
| 37 | |
| 38 | it("sorts in release order, a pre-release before its final", () => { |
| 39 | const order = ["2026.11v1", "2026.11v2", "2026.12v1-beta.1", "2026.12v1-beta.2", "2026.12v1", "2027.01v1"]; |
| 40 | const parsed = order.map((s) => parseVersion(s)!); |
| 41 | const shuffled = [...parsed].reverse().sort(compareVersions); |
| 42 | expect(shuffled.map(shownVersion)).toEqual(order); |
| 43 | }); |
| 44 | }); |