Fix broken test code
This commit is contained in:
@@ -1,16 +1,16 @@
|
|||||||
import { expect } from "@jest/globals";
|
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 type { QueryPackFS } from "../vscode-tests/utils/bundled-pack-helpers";
|
||||||
import { EOL } from "os";
|
import { EOL } from "os";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom Jest matcher to check if a file exists in a query pack.
|
* Custom Jest matcher to check if a file exists in a query pack.
|
||||||
*/
|
*/
|
||||||
function toExistInPack(
|
// eslint-disable-next-line func-style -- We need to set the type of this function
|
||||||
this: jest.MatcherContext,
|
const toExistInCodeQLPack: MatcherFunction<[packFS: QueryPackFS]> = function (
|
||||||
actual: unknown,
|
actual,
|
||||||
packFS: QueryPackFS,
|
packFS,
|
||||||
): ExpectationResult {
|
) {
|
||||||
if (typeof actual !== "string") {
|
if (typeof actual !== "string") {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
`Expected actual value to be a string. Found ${typeof actual}`,
|
`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}`,
|
`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" {
|
declare global {
|
||||||
interface Matchers<R> {
|
// eslint-disable-next-line @typescript-eslint/no-namespace -- We need to extend this global declaration
|
||||||
toExistInCodeQLPack(packFS: QueryPackFS): R;
|
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 { load } from "js-yaml";
|
||||||
import type { ExtensionPackMetadata } from "../../../../src/model-editor/extension-pack-metadata";
|
import type { ExtensionPackMetadata } from "../../../../src/model-editor/extension-pack-metadata";
|
||||||
import type { QlPackLockFile } from "../../../../src/packaging/qlpack-lock-file";
|
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", () => {
|
describe("Variant Analysis Manager", () => {
|
||||||
let cli: CodeQLCliServer;
|
let cli: CodeQLCliServer;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { dirname } from "path";
|
import { basename } from "path";
|
||||||
import { workspace } from "vscode";
|
import { workspace } from "vscode";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,7 +8,7 @@ import { workspace } from "vscode";
|
|||||||
function hasCodeQL() {
|
function hasCodeQL() {
|
||||||
const folders = workspace.workspaceFolders;
|
const folders = workspace.workspaceFolders;
|
||||||
return !!folders?.some((folder) => {
|
return !!folders?.some((folder) => {
|
||||||
const name = dirname(folder.uri.fsPath);
|
const name = basename(folder.uri.fsPath);
|
||||||
return name === "codeql" || name === "ql";
|
return name === "codeql" || name === "ql";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user