Files
vscode-codeql/extensions/ql-vscode/test/vscode-tests/minimal-workspace/determining-selected-query-test.ts
Alexander Eyers-Taylor 22172d5d74 Add support for quick eval count to the query runner (#2417)
* Add support for quick eval count to the query runner

This only adds support internally to the query runner,
without any UI support.

* Fix some tests
2023-05-30 14:12:47 +01:00

64 lines
2.1 KiB
TypeScript

import { resolve, join } from "path";
import * as vscode from "vscode";
import { Uri } from "vscode";
import {
getQuickEvalContext,
validateQueryUri,
} from "../../../src/run-queries-shared";
async function showQlDocument(name: string): Promise<vscode.TextDocument> {
const folderPath = vscode.workspace.workspaceFolders![0].uri.fsPath;
const documentPath = resolve(folderPath, name);
const document = await vscode.workspace.openTextDocument(documentPath);
await vscode.window.showTextDocument(document!);
return document;
}
export function run() {
describe("Determining selected query", () => {
it("should allow ql files to be queried", async () => {
const queryPath = validateQueryUri(
Uri.parse("file:///tmp/queryname.ql"),
false,
);
expect(queryPath).toBe(join("/", "tmp", "queryname.ql"));
});
it("should allow ql files to be quick-evaled", async () => {
await showQlDocument("query.ql");
const q = await getQuickEvalContext(undefined, false);
expect(
q.quickEvalPosition.fileName.endsWith(
join("ql-vscode", "test", "data", "query.ql"),
),
).toBe(true);
});
it("should allow qll files to be quick-evaled", async () => {
await showQlDocument("library.qll");
const q = await getQuickEvalContext(undefined, false);
expect(
q.quickEvalPosition.fileName.endsWith(
join("ql-vscode", "test", "data", "library.qll"),
),
).toBe(true);
});
it("should reject non-ql files when running a query", async () => {
expect(() =>
validateQueryUri(Uri.parse("file:///tmp/queryname.txt"), false),
).toThrow("The selected resource is not a CodeQL query file");
expect(() =>
validateQueryUri(Uri.parse("file:///tmp/queryname.qll"), false),
).toThrow("The selected resource is not a CodeQL query file");
});
it("should reject non-ql[l] files when running a quick eval", async () => {
await showQlDocument("textfile.txt");
await expect(getQuickEvalContext(undefined, false)).rejects.toThrow(
"The selected resource is not a CodeQL file",
);
});
});
}