@@ -20,10 +20,47 @@ import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
2020import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
2121import { mockedQuickPickItem } from "../../utils/mocking.helpers";
2222import { QueryLanguage } from "../../../../src/common/query-language";
23+ import type { QueryPackFS } from "../../utils/bundled-pack-helpers";
2324import { readBundledPack } from "../../utils/bundled-pack-helpers";
2425import { load } from "js-yaml";
2526import type { ExtensionPackMetadata } from "../../../../src/model-editor/extension-pack-metadata";
2627import type { QlPackLockFile } from "../../../../src/packaging/qlpack-lock-file";
28+ import { expect } from "@jest/globals";
29+ import type { ExpectationResult } from "expect";
30+
31+ /**
32+ * Custom Jest matcher to check if a file exists in a query pack.
33+ */
34+ function toExistInPack(
35+ this: jest.MatcherContext,
36+ actual: unknown,
37+ packFS: QueryPackFS,
38+ ): ExpectationResult {
39+ if (typeof actual !== "string") {
40+ throw new TypeError("Expected actual value to be a string.");
41+ }
42+
43+ const pass = packFS.fileExists(actual);
44+ if (pass) {
45+ return {
46+ pass: true,
47+ message: () => `expected ${actual} not to exist in pack`,
48+ };
49+ } else {
50+ return {
51+ pass: false,
52+ message: () => `expected ${actual} to exist in pack`,
53+ };
54+ }
55+ }
56+
57+ expect.extend({ toExistInPack });
58+
59+ declare module "expect" {
60+ interface Matchers<R> {
61+ toExistInPack(packFS: QueryPackFS): R;
62+ }
63+ }
2764
2865describe("Variant Analysis Manager", () => {
2966 let cli: CodeQLCliServer;
@@ -331,14 +368,14 @@ describe("Variant Analysis Manager", () => {
331368
332369 const packFS = await readBundledPack(request.query.pack);
333370 filesThatExist.forEach((file) => {
334- expect(packFS.fileExists( file)).toBe(true );
371+ expect(file).toExistInPack(packFS );
335372 });
336373
337374 qlxFilesThatExist.forEach((file) => {
338- expect(packFS.fileExists( file)).toBe(true );
375+ expect(file).toExistInPack(packFS );
339376 });
340377 filesThatDoNotExist.forEach((file) => {
341- expect(packFS.fileExists( file)).toBe(false );
378+ expect(file).not.toExistInPack(packFS );
342379 });
343380
344381 expect(
0 commit comments