Files
vscode-codeql/extensions/ql-vscode/test/pure-tests/log-summary-parser.test.ts
Koen Vlaswinkel 0974700557 Convert pure tests to Jest
This converts all pure tests to Jest. This was done by first running
`npx jest-codemods` with the Mocha transformation, then manually fixing
any places where it hadn't automatically converted the correct thing
or had missed things (mostly Sinon).

This also sets up VSCode correctly for running Jest.
2022-11-22 10:39:21 +01:00

48 lines
1.7 KiB
TypeScript

import * as path from "path";
import { parseViewerData } from "../../src/pure/log-summary-parser";
describe("Evaluator log summary tests", () => {
describe("for a valid summary text", () => {
it("should return only valid EvalLogData objects", async () => {
const validSummaryPath = path.join(
__dirname,
"evaluator-log-summaries/valid-summary.jsonl",
);
const logDataItems = await parseViewerData(validSummaryPath);
expect(logDataItems).toBeDefined();
expect(logDataItems.length).toBe(3);
for (const item of logDataItems) {
expect(item.predicateName).not.toHaveLength(0);
expect(item.millis).toEqual(expect.any(Number));
expect(item.resultSize).toEqual(expect.any(Number));
expect(item.ra).toBeDefined();
expect(Object.keys(item.ra)).not.toHaveLength(0);
for (const [pipeline, steps] of Object.entries(item.ra)) {
expect(Object.keys(pipeline)).not.toHaveLength(0);
expect(steps).toBeDefined();
expect(steps.length).toBeGreaterThan(0);
}
}
});
it("should not parse a summary header object", async () => {
const invalidHeaderPath = path.join(
__dirname,
"evaluator-log-summaries/invalid-header.jsonl",
);
const logDataItems = await parseViewerData(invalidHeaderPath);
expect(logDataItems.length).toBe(0);
});
it("should not parse a log event missing RA or millis fields", async () => {
const invalidSummaryPath = path.join(
__dirname,
"evaluator-log-summaries/invalid-summary.jsonl",
);
const logDataItems = await parseViewerData(invalidSummaryPath);
expect(logDataItems.length).toBe(0);
});
});
});