import { describe, expect, it } from "vitest"; import { summarizeTestRunResult } from "./summarize-test-run-result.ts"; import type { TestRunExecutionResult } from "./execute-test-run-plan.ts"; function testRunResult( overrides: Partial = {}, ): TestRunExecutionResult { return { ok: true, displayCommand: "go test -race ./...", stdout: "PASS\n", stderr: "", exitCode: 0, killed: false, ...overrides, }; } describe("summarizeTestRunResult", () => { it("summarizes passing tests as an info notification", () => { expect(summarizeTestRunResult(testRunResult())).toEqual({ message: "go test -race ./... passed", type: "info", }); }); it("summarizes non-zero exit codes as failed without including command output", () => { const result = summarizeTestRunResult( testRunResult({ ok: false, stdout: "full stdout should not appear", stderr: "full stderr should not appear", exitCode: 1, }), ); expect(result).toEqual({ message: "go test -race ./... failed", type: "error", }); }); it("summarizes killed executions as killed or timeout without including command output", () => { expect( summarizeTestRunResult( testRunResult({ ok: false, stdout: "full stdout should not appear", stderr: "full stderr should not appear", exitCode: 0, killed: true, }), ), ).toEqual({ message: "go test -race ./... killed or timeout", type: "error", }); }); it("prioritizes killed or timeout over failed when both are present", () => { expect( summarizeTestRunResult( testRunResult({ ok: false, stdout: "full stdout should not appear", stderr: "full stderr should not appear", exitCode: 1, killed: true, }), ), ).toEqual({ message: "go test -race ./... killed or timeout", type: "error", }); }); });