|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { |
| 3 | + parseBuildOutputs, |
| 4 | + successSet, |
| 5 | + type BuildOutcome, |
| 6 | + type ServiceBuildResult, |
| 7 | +} from "../build-outputs"; |
| 8 | + |
| 9 | +const sample: ServiceBuildResult[] = [ |
| 10 | + { service: "showcase-mastra", status: "success" }, |
| 11 | + { service: "showcase-ag2", status: "failure" }, |
| 12 | + { service: "shell-docs", status: "skipped" }, |
| 13 | + { service: "showcase-aimock", status: "success" }, |
| 14 | +]; |
| 15 | + |
| 16 | +describe("build-outputs", () => { |
| 17 | + it("parses a JSON array of {service,status} entries", () => { |
| 18 | + const json = JSON.stringify(sample); |
| 19 | + expect(parseBuildOutputs(json)).toEqual(sample); |
| 20 | + }); |
| 21 | + |
| 22 | + it("throws on malformed JSON", () => { |
| 23 | + expect(() => parseBuildOutputs("not json")).toThrow(/parse/i); |
| 24 | + }); |
| 25 | + |
| 26 | + it("throws on entries missing fields", () => { |
| 27 | + expect(() => parseBuildOutputs(JSON.stringify([{ service: "x" }]))).toThrow( |
| 28 | + /status/i, |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it("throws on an unknown status value", () => { |
| 33 | + const bad = JSON.stringify([{ service: "x", status: "weird" }]); |
| 34 | + expect(() => parseBuildOutputs(bad)).toThrow(/status/i); |
| 35 | + }); |
| 36 | + |
| 37 | + it("successSet returns only services with status === 'success'", () => { |
| 38 | + expect(successSet(sample).sort()).toEqual( |
| 39 | + ["showcase-aimock", "showcase-mastra"].sort(), |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + it("successSet returns empty when no services succeeded", () => { |
| 44 | + const allFailed: ServiceBuildResult[] = [ |
| 45 | + { service: "a", status: "failure" }, |
| 46 | + { service: "b", status: "failure" }, |
| 47 | + ]; |
| 48 | + expect(successSet(allFailed)).toEqual([]); |
| 49 | + }); |
| 50 | + |
| 51 | + it("type BuildOutcome enumerates success|failure|skipped", () => { |
| 52 | + const outcomes: BuildOutcome[] = ["success", "failure", "skipped"]; |
| 53 | + expect(outcomes).toHaveLength(3); |
| 54 | + }); |
| 55 | +}); |
0 commit comments