|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { formatRuntimeWithVersion, parseRuntime } from "~/utils/runtime"; |
| 3 | + |
| 4 | +describe("parseRuntime", () => { |
| 5 | + it("normalizes bun runtimes", () => { |
| 6 | + expect(parseRuntime("bun")).toEqual({ |
| 7 | + runtime: "bun", |
| 8 | + originalRuntime: "bun", |
| 9 | + displayName: "Bun", |
| 10 | + }); |
| 11 | + expect(parseRuntime("bun-1.2")).toEqual({ |
| 12 | + runtime: "bun", |
| 13 | + originalRuntime: "bun-1.2", |
| 14 | + displayName: "Bun", |
| 15 | + }); |
| 16 | + }); |
| 17 | + |
| 18 | + it("normalizes node runtimes", () => { |
| 19 | + expect(parseRuntime("node")).toEqual({ |
| 20 | + runtime: "node", |
| 21 | + originalRuntime: "node", |
| 22 | + displayName: "Node.js", |
| 23 | + }); |
| 24 | + expect(parseRuntime("node-24")).toEqual({ |
| 25 | + runtime: "node", |
| 26 | + originalRuntime: "node-24", |
| 27 | + displayName: "Node.js", |
| 28 | + }); |
| 29 | + }); |
| 30 | + |
| 31 | + it("returns null for a missing runtime instead of assuming node", () => { |
| 32 | + expect(parseRuntime(null)).toBeNull(); |
| 33 | + expect(parseRuntime(undefined)).toBeNull(); |
| 34 | + expect(parseRuntime("")).toBeNull(); |
| 35 | + }); |
| 36 | + |
| 37 | + it("returns null for an unrecognized runtime", () => { |
| 38 | + expect(parseRuntime("deno")).toBeNull(); |
| 39 | + expect(parseRuntime("python3.12")).toBeNull(); |
| 40 | + expect(parseRuntime("Node")).toBeNull(); |
| 41 | + }); |
| 42 | +}); |
| 43 | + |
| 44 | +describe("formatRuntimeWithVersion", () => { |
| 45 | + it("appends the version when there is one", () => { |
| 46 | + expect(formatRuntimeWithVersion("bun", "1.2.23")).toBe("Bun v1.2.23"); |
| 47 | + expect(formatRuntimeWithVersion("node-24", "24.9.0")).toBe("Node.js v24.9.0"); |
| 48 | + }); |
| 49 | + |
| 50 | + it("falls back to the display name without a version", () => { |
| 51 | + expect(formatRuntimeWithVersion("bun", null)).toBe("Bun"); |
| 52 | + expect(formatRuntimeWithVersion("node-24", undefined)).toBe("Node.js"); |
| 53 | + expect(formatRuntimeWithVersion("node", "")).toBe("Node.js"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("reports an unknown runtime rather than a default", () => { |
| 57 | + expect(formatRuntimeWithVersion(null, null)).toBe("Unknown runtime"); |
| 58 | + expect(formatRuntimeWithVersion(undefined, "24.9.0")).toBe("Unknown runtime"); |
| 59 | + expect(formatRuntimeWithVersion("deno", "2.1.0")).toBe("Unknown runtime"); |
| 60 | + }); |
| 61 | +}); |
0 commit comments