46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { parseTscExtendedDiagnostics } from "../../scripts/scale/collect-tsc-diagnostics.ts";
|
|
|
|
describe("parseTscExtendedDiagnostics", () => {
|
|
it("parses the documented diagnostic fields", () => {
|
|
const text = `
|
|
Files: 321
|
|
Types: 12000
|
|
Symbols: 18000
|
|
Instantiations: 5000
|
|
Memory used: 128000K
|
|
Total time: 4.20s
|
|
`;
|
|
|
|
expect(parseTscExtendedDiagnostics(text)).toMatchObject({
|
|
files: 321,
|
|
types: 12_000,
|
|
symbols: 18_000,
|
|
instantiations: 5_000,
|
|
memoryKb: 128_000,
|
|
totalTimeSeconds: 4.2,
|
|
});
|
|
});
|
|
|
|
it("parses real TypeScript 7 output captured from this repository", async () => {
|
|
const text = await readFile(
|
|
path.resolve("tests/scale/fixtures/typescript/extended-diagnostics.txt"),
|
|
"utf8",
|
|
);
|
|
const parsed = parseTscExtendedDiagnostics(text);
|
|
expect(parsed.files).toBeGreaterThan(0);
|
|
expect(parsed.types).toBeGreaterThan(0);
|
|
expect(parsed.instantiations).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("fails loudly when a required metric is missing", () => {
|
|
expect(() => parseTscExtendedDiagnostics("Files: 1\nTypes: 2\n")).toThrow(
|
|
/symbols/,
|
|
);
|
|
});
|
|
});
|