Add a test of runVariantAnalysisFromPublishedPack

This commit is contained in:
Robert
2024-01-17 14:25:27 +00:00
parent be22964113
commit 1010239c29
2 changed files with 34 additions and 1 deletions

View File

@@ -214,7 +214,7 @@ export class VariantAnalysisManager
}
}
private async runVariantAnalysisFromPublishedPack(): Promise<void> {
public async runVariantAnalysisFromPublishedPack(): Promise<void> {
return withProgress(async (progress, token) => {
progress({
maxStep: 8,

View File

@@ -388,4 +388,37 @@ describe("Variant Analysis Manager", () => {
}
}
});
describe("runVariantAnalysisFromPublishedPack", () => {
it("should download pack for correct language and identify problem queries", async () => {
const showQuickPickSpy = jest
.spyOn(window, "showQuickPick")
.mockResolvedValue(
mockedQuickPickItem({
label: "JavaScript",
description: "javascript",
language: "javascript",
}),
);
const runVariantAnalysisMock = jest.fn();
variantAnalysisManager.runVariantAnalysis = runVariantAnalysisMock;
await variantAnalysisManager.runVariantAnalysisFromPublishedPack();
expect(showQuickPickSpy).toHaveBeenCalledTimes(1);
expect(runVariantAnalysisMock).toHaveBeenCalledTimes(1);
const queries: Uri[] = runVariantAnalysisMock.mock.calls[0][0];
// Should include queries. Just check that at least one known query exists.
// It doesn't particularly matter which query we check for.
expect(
queries.find((q) => q.fsPath.includes("CWE-201/PostMessageStar.ql")),
).toBeDefined();
// Should not include non-problem queries.
expect(
queries.find((q) => q.fsPath.includes("LinesOfCode.ql")),
).not.toBeDefined();
});
});
});