This commit is contained in:
Dave Bartolomeo 2024-01-17 17:48:44 -05:00
Родитель 65fbb6bca8
Коммит d7e5552481
3 изменённых файлов: 22 добавлений и 14 удалений

Просмотреть файл

@ -1,16 +1,16 @@
import { expect } from "@jest/globals";
import type { ExpectationResult } from "expect";
import type { MatcherFunction } from "expect";
import type { QueryPackFS } from "../vscode-tests/utils/bundled-pack-helpers";
import { EOL } from "os";
/**
* Custom Jest matcher to check if a file exists in a query pack.
*/
function toExistInPack(
this: jest.MatcherContext,
actual: unknown,
packFS: QueryPackFS,
): ExpectationResult {
// eslint-disable-next-line func-style -- We need to set the type of this function
const toExistInCodeQLPack: MatcherFunction<[packFS: QueryPackFS]> = function (
actual,
packFS,
) {
if (typeof actual !== "string") {
throw new TypeError(
`Expected actual value to be a string. Found ${typeof actual}`,
@ -32,12 +32,19 @@ function toExistInPack(
`expected ${actual} to exist in pack.\nThe following files were found in the pack:\n${filesString}`,
};
}
}
};
expect.extend({ toExistInPack });
expect.extend({ toExistInCodeQLPack });
declare module "expect" {
interface Matchers<R> {
toExistInCodeQLPack(packFS: QueryPackFS): R;
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace -- We need to extend this global declaration
namespace jest {
interface AsymmetricMatchers {
toExistInCodeQLPack(packFS: QueryPackFS): void;
}
interface Matchers<R> {
toExistInCodeQLPack(packFS: QueryPackFS): R;
}
}
}

Просмотреть файл

@ -24,7 +24,8 @@ import { readBundledPack } from "../../utils/bundled-pack-helpers";
import { load } from "js-yaml";
import type { ExtensionPackMetadata } from "../../../../src/model-editor/extension-pack-metadata";
import type { QlPackLockFile } from "../../../../src/packaging/qlpack-lock-file";
import { expect } from "@jest/globals";
//import { expect } from "@jest/globals";
import "../../../matchers/toExistInCodeQLPack";
describe("Variant Analysis Manager", () => {
let cli: CodeQLCliServer;

Просмотреть файл

@ -1,4 +1,4 @@
import { dirname } from "path";
import { basename } from "path";
import { workspace } from "vscode";
/**
@ -8,7 +8,7 @@ import { workspace } from "vscode";
function hasCodeQL() {
const folders = workspace.workspaceFolders;
return !!folders?.some((folder) => {
const name = dirname(folder.uri.fsPath);
const name = basename(folder.uri.fsPath);
return name === "codeql" || name === "ql";
});
}