import { describe, expect, it } from "vitest"; import { parseDiagnostics } from "./diagnostics"; describe("parseDiagnostics", () => { it("returns nothing for empty output", () => { expect(parseDiagnostics("", "")).toEqual([]); }); it("returns nothing when output has no recognizable diagnostics", () => { expect(parseDiagnostics("Build succeeded in 1.2s\n", "")).toEqual([]); }); it("parses TypeScript compiler errors", () => { const stdout = "src/foo.ts(12,34): error TS2345: Argument of type 'string' is not assignable.\n"; expect(parseDiagnostics(stdout, "")).toEqual([ { kind: "typecheck", severity: "error", file: "src/foo.ts", line: 12, column: 34, code: "TS2345", message: "Argument of type 'string' is not assignable.", }, ]); }); it("parses ESLint/Biome-style file:line:column diagnostics", () => { const stdout = "src/bar.ts:5:1 error: 'foo' is defined but never used.\n"; const [diagnostic] = parseDiagnostics(stdout, ""); expect(diagnostic).toMatchObject({ kind: "lint", severity: "error", file: "src/bar.ts", line: 5, column: 1, }); }); it("parses Rust compiler errors", () => { const stderr = "error[E0432]: unresolved import `foo`\n --> src/main.rs:10:5\n"; expect(parseDiagnostics("", stderr)).toEqual([ { kind: "compiler", severity: "error", file: "src/main.rs", line: 10, column: 5, code: "E0432", message: "unresolved import `foo`", }, ]); }); it("parses vitest FAIL lines", () => { const stdout = "FAIL src/foo.test.ts > does the thing\n"; const [diagnostic] = parseDiagnostics(stdout, ""); expect(diagnostic).toMatchObject({ kind: "test", severity: "error", file: "src/foo.test.ts", }); }); it("caps output at 200 diagnostics", () => { const stdout = Array.from({ length: 300 }, (_, i) => `src/file${i}.ts(${i},1): error TS0000: repeated error.`).join( "\n", ); expect(parseDiagnostics(stdout, "")).toHaveLength(200); }); });