Skip to content

Commit d7e5552

Browse files
author
Dave Bartolomeo
committed
Fix broken test code
1 parent 65fbb6b commit d7e5552

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

extensions/ql-vscode/test/matchers/toExistInCodeQLPack.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { expect } from "@jest/globals";
2-
import type { ExpectationResult } from "expect";
2+
import type { MatcherFunction } from "expect";
33
import type { QueryPackFS } from "../vscode-tests/utils/bundled-pack-helpers";
44
import { EOL } from "os";
55

66
/**
77
* Custom Jest matcher to check if a file exists in a query pack.
88
*/
9-
function toExistInPack(
10-
this: jest.MatcherContext,
11-
actual: unknown,
12-
packFS: QueryPackFS,
13-
): ExpectationResult {
9+
// eslint-disable-next-line func-style -- We need to set the type of this function
10+
const toExistInCodeQLPack: MatcherFunction<[packFS: QueryPackFS]> = function (
11+
actual,
12+
packFS,
13+
) {
1414
if (typeof actual !== "string") {
1515
throw new TypeError(
1616
`Expected actual value to be a string. Found ${typeof actual}`,
@@ -32,12 +32,19 @@ function toExistInPack(
3232
`expected ${actual} to exist in pack.\nThe following files were found in the pack:\n${filesString}`,
3333
};
3434
}
35-
}
35+
};
36+
37+
expect.extend({ toExistInCodeQLPack });
3638

37-
expect.extend({ toExistInPack });
39+
declare global {
40+
// eslint-disable-next-line @typescript-eslint/no-namespace -- We need to extend this global declaration
41+
namespace jest {
42+
interface AsymmetricMatchers {
43+
toExistInCodeQLPack(packFS: QueryPackFS): void;
44+
}
3845

39-
declare module "expect" {
40-
interface Matchers<R> {
41-
toExistInCodeQLPack(packFS: QueryPackFS): R;
46+
interface Matchers<R> {
47+
toExistInCodeQLPack(packFS: QueryPackFS): R;
48+
}
4249
}
4350
}

extensions/ql-vscode/test/vscode-tests/cli-integration/variant-analysis/variant-analysis-manager.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import { readBundledPack } from "../../utils/bundled-pack-helpers";
2424
import { load } from "js-yaml";
2525
import type { ExtensionPackMetadata } from "../../../../src/model-editor/extension-pack-metadata";
2626
import type { QlPackLockFile } from "../../../../src/packaging/qlpack-lock-file";
27-
import { expect } from "@jest/globals";
27+
//import { expect } from "@jest/globals";
28+
import "../../../matchers/toExistInCodeQLPack";
2829

2930
describe("Variant Analysis Manager", () => {
3031
let cli: CodeQLCliServer;

extensions/ql-vscode/test/vscode-tests/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { dirname } from "path";
1+
import { basename } from "path";
22
import { workspace } from "vscode";
33

44
/**
@@ -8,7 +8,7 @@ import { workspace } from "vscode";
88
function hasCodeQL() {
99
const folders = workspace.workspaceFolders;
1010
return !!folders?.some((folder) => {
11-
const name = dirname(folder.uri.fsPath);
11+
const name = basename(folder.uri.fsPath);
1212
return name === "codeql" || name === "ql";
1313
});
1414
}

0 commit comments

Comments
 (0)