From d7e555248140f5b50bcc0fc5295df0c03c9e69c4 Mon Sep 17 00:00:00 2001 From: Dave Bartolomeo Date: Wed, 17 Jan 2024 17:48:44 -0500 Subject: [PATCH] Fix broken test code --- .../test/matchers/toExistInCodeQLPack.ts | 29 ++++++++++++------- .../variant-analysis-manager.test.ts | 3 +- extensions/ql-vscode/test/vscode-tests/cli.ts | 4 +-- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/extensions/ql-vscode/test/matchers/toExistInCodeQLPack.ts b/extensions/ql-vscode/test/matchers/toExistInCodeQLPack.ts index 5021c6bdb..622c41200 100644 --- a/extensions/ql-vscode/test/matchers/toExistInCodeQLPack.ts +++ b/extensions/ql-vscode/test/matchers/toExistInCodeQLPack.ts @@ -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 { - 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 { + toExistInCodeQLPack(packFS: QueryPackFS): R; + } } } diff --git a/extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-manager.test.ts b/extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-manager.test.ts index ee2bc14b6..e3eb13d4f 100644 --- a/extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-manager.test.ts +++ b/extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-manager.test.ts @@ -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; diff --git a/extensions/ql-vscode/test/vscode-tests/cli.ts b/extensions/ql-vscode/test/vscode-tests/cli.ts index 8ed3a9b4f..9dca8eaf1 100644 --- a/extensions/ql-vscode/test/vscode-tests/cli.ts +++ b/extensions/ql-vscode/test/vscode-tests/cli.ts @@ -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"; }); }