Custom message for assertions about files existing in packs
This commit is contained in:
@@ -20,10 +20,47 @@ import { ExtensionApp } from "../../../../src/common/vscode/vscode-app";
|
||||
import { DbConfigStore } from "../../../../src/databases/config/db-config-store";
|
||||
import { mockedQuickPickItem } from "../../utils/mocking.helpers";
|
||||
import { QueryLanguage } from "../../../../src/common/query-language";
|
||||
import type { QueryPackFS } from "../../utils/bundled-pack-helpers";
|
||||
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 type { ExpectationResult } from "expect";
|
||||
|
||||
/**
|
||||
* Custom Jest matcher to check if a file exists in a query pack.
|
||||
*/
|
||||
function toExistInPack(
|
||||
this: jest.MatcherContext,
|
||||
actual: unknown,
|
||||
packFS: QueryPackFS,
|
||||
): ExpectationResult {
|
||||
if (typeof actual !== "string") {
|
||||
throw new TypeError("Expected actual value to be a string.");
|
||||
}
|
||||
|
||||
const pass = packFS.fileExists(actual);
|
||||
if (pass) {
|
||||
return {
|
||||
pass: true,
|
||||
message: () => `expected ${actual} not to exist in pack`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: () => `expected ${actual} to exist in pack`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
expect.extend({ toExistInPack });
|
||||
|
||||
declare module "expect" {
|
||||
interface Matchers<R> {
|
||||
toExistInPack(packFS: QueryPackFS): R;
|
||||
}
|
||||
}
|
||||
|
||||
describe("Variant Analysis Manager", () => {
|
||||
let cli: CodeQLCliServer;
|
||||
@@ -331,14 +368,14 @@ describe("Variant Analysis Manager", () => {
|
||||
|
||||
const packFS = await readBundledPack(request.query.pack);
|
||||
filesThatExist.forEach((file) => {
|
||||
expect(packFS.fileExists(file)).toBe(true);
|
||||
expect(file).toExistInPack(packFS);
|
||||
});
|
||||
|
||||
qlxFilesThatExist.forEach((file) => {
|
||||
expect(packFS.fileExists(file)).toBe(true);
|
||||
expect(file).toExistInPack(packFS);
|
||||
});
|
||||
filesThatDoNotExist.forEach((file) => {
|
||||
expect(packFS.fileExists(file)).toBe(false);
|
||||
expect(file).not.toExistInPack(packFS);
|
||||
});
|
||||
|
||||
expect(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { extract as tar_extract } from "tar-stream";
|
||||
import { pipeline } from "stream/promises";
|
||||
import { createGunzip } from "zlib";
|
||||
|
||||
interface QueryPackFS {
|
||||
export interface QueryPackFS {
|
||||
fileExists: (name: string) => boolean;
|
||||
fileContents: (name: string) => Buffer;
|
||||
directoryContents: (name: string) => string[];
|
||||
|
||||
Reference in New Issue
Block a user