Replace toBeCalledWith

This commit is contained in:
Nora
2024-01-16 15:28:07 +00:00
parent fed110f65f
commit abc71b5102
14 changed files with 56 additions and 54 deletions

View File

@@ -54,12 +54,12 @@ describe("OutputChannelLogger tests", function () {
it("should log to the output channel", async () => {
await logger.log("xxx");
expect(mockOutputChannel.appendLine).toBeCalledWith("xxx");
expect(mockOutputChannel.append).not.toBeCalledWith("xxx");
expect(mockOutputChannel.appendLine).toHaveBeenCalledWith("xxx");
expect(mockOutputChannel.append).not.toHaveBeenCalledWith("xxx");
await logger.log("yyy", { trailingNewline: false });
expect(mockOutputChannel.appendLine).not.toBeCalledWith("yyy");
expect(mockOutputChannel.append).toBeCalledWith("yyy");
expect(mockOutputChannel.appendLine).not.toHaveBeenCalledWith("yyy");
expect(mockOutputChannel.append).toHaveBeenCalledWith("yyy");
const hucairz = createSideLogger(logger, "hucairz");
await hucairz.log("zzz");

View File

@@ -139,7 +139,7 @@ describe("db config store", () => {
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(executeCommand).toBeCalledWith(
expect(executeCommand).toHaveBeenCalledWith(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
true,
@@ -157,7 +157,7 @@ describe("db config store", () => {
const configStore = new DbConfigStore(app, false);
await configStore.initialize();
expect(executeCommand).toBeCalledWith(
expect(executeCommand).toHaveBeenCalledWith(
"setContext",
"codeQLVariantAnalysisRepositories.configError",
false,

View File

@@ -610,7 +610,7 @@ describe("Variant Analysis Manager", () => {
it("should return cancel if valid", async () => {
await variantAnalysisManager.cancelVariantAnalysis(variantAnalysis.id);
expect(mockCancelVariantAnalysis).toBeCalledWith(
expect(mockCancelVariantAnalysis).toHaveBeenCalledWith(
app.credentials,
variantAnalysis,
);

View File

@@ -105,7 +105,7 @@ describe("Variant Analysis Manager", () => {
cancellationTokenSource.token,
);
expect(executeCommandSpy).toBeCalledWith(
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.monitorNewVariantAnalysis",
expect.objectContaining({
id: mockApiResponse.id,
@@ -126,7 +126,7 @@ describe("Variant Analysis Manager", () => {
cancellationTokenSource.token,
);
expect(executeCommandSpy).toBeCalledWith(
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.monitorNewVariantAnalysis",
expect.objectContaining({
id: mockApiResponse.id,
@@ -147,7 +147,7 @@ describe("Variant Analysis Manager", () => {
cancellationTokenSource.token,
);
expect(executeCommandSpy).toBeCalledWith(
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.monitorNewVariantAnalysis",
expect.objectContaining({
id: mockApiResponse.id,
@@ -319,7 +319,7 @@ describe("Variant Analysis Manager", () => {
);
expect(mockSubmitVariantAnalysis).toBeCalledTimes(1);
expect(executeCommandSpy).toBeCalledWith(
expect(executeCommandSpy).toHaveBeenCalledWith(
"codeQL.monitorNewVariantAnalysis",
expect.objectContaining({
query: expect.objectContaining({ filePath: fileUri.fsPath }),

View File

@@ -130,13 +130,13 @@ describe("local databases", () => {
await (databaseManager as any).addDatabaseItem(mockDbItem);
expect((databaseManager as any)._databaseItems).toEqual([mockDbItem]);
expect(updateSpy).toBeCalledWith("databaseList", [
expect(updateSpy).toHaveBeenCalledWith("databaseList", [
{
options: mockDbOptions(),
uri: dbLocationUri(dir).toString(true),
},
]);
expect(onDidChangeDatabaseItem).toBeCalledWith({
expect(onDidChangeDatabaseItem).toHaveBeenCalledWith({
item: undefined,
kind: DatabaseEventKind.Add,
});
@@ -147,8 +147,8 @@ describe("local databases", () => {
// now remove the item
await databaseManager.removeDatabaseItem(mockDbItem);
expect((databaseManager as any)._databaseItems).toEqual([]);
expect(updateSpy).toBeCalledWith("databaseList", []);
expect(onDidChangeDatabaseItem).toBeCalledWith({
expect(updateSpy).toHaveBeenCalledWith("databaseList", []);
expect(onDidChangeDatabaseItem).toHaveBeenCalledWith({
item: undefined,
kind: DatabaseEventKind.Remove,
});
@@ -164,14 +164,14 @@ describe("local databases", () => {
await databaseManager.renameDatabaseItem(mockDbItem, "new name");
expect(mockDbItem.name).toBe("new name");
expect(updateSpy).toBeCalledWith("databaseList", [
expect(updateSpy).toHaveBeenCalledWith("databaseList", [
{
options: { ...mockDbOptions(), displayName: "new name" },
uri: dbLocationUri(dir).toString(true),
},
]);
expect(onDidChangeDatabaseItem).toBeCalledWith({
expect(onDidChangeDatabaseItem).toHaveBeenCalledWith({
item: undefined,
kind: DatabaseEventKind.Rename,
});
@@ -187,7 +187,7 @@ describe("local databases", () => {
await (databaseManager as any).addDatabaseItem(mockDbItem);
expect(databaseManager.databaseItems).toEqual([mockDbItem]);
expect(updateSpy).toBeCalledWith("databaseList", [
expect(updateSpy).toHaveBeenCalledWith("databaseList", [
{
uri: dbLocationUri(dir).toString(true),
options: mockDbOptions(),
@@ -198,7 +198,7 @@ describe("local databases", () => {
item: undefined,
kind: DatabaseEventKind.Add,
};
expect(onDidChangeDatabaseItem).toBeCalledWith(mockEvent);
expect(onDidChangeDatabaseItem).toHaveBeenCalledWith(mockEvent);
});
it("should add a database item source archive", async () => {
@@ -234,9 +234,9 @@ describe("local databases", () => {
await databaseManager.removeDatabaseItem(mockDbItem);
expect(databaseManager.databaseItems).toEqual([]);
expect(updateSpy).toBeCalledWith("databaseList", []);
expect(updateSpy).toHaveBeenCalledWith("databaseList", []);
// should remove the folder
expect(workspace.updateWorkspaceFolders).toBeCalledWith(0, 1);
expect(workspace.updateWorkspaceFolders).toHaveBeenCalledWith(0, 1);
// should also delete the db contents
await expect(pathExists(mockDbItem.databaseUri.fsPath)).resolves.toBe(
@@ -262,9 +262,9 @@ describe("local databases", () => {
await databaseManager.removeDatabaseItem(mockDbItem);
expect(databaseManager.databaseItems).toEqual([]);
expect(updateSpy).toBeCalledWith("databaseList", []);
expect(updateSpy).toHaveBeenCalledWith("databaseList", []);
// should remove the folder
expect(workspace.updateWorkspaceFolders).toBeCalledWith(0, 1);
expect(workspace.updateWorkspaceFolders).toHaveBeenCalledWith(0, 1);
// should NOT delete the db contents
await expect(pathExists(mockDbItem.databaseUri.fsPath)).resolves.toBe(
@@ -279,12 +279,12 @@ describe("local databases", () => {
await (databaseManager as any).addDatabaseItem(mockDbItem);
// Should have registered this database
expect(registerSpy).toBeCalledWith(mockDbItem);
expect(registerSpy).toHaveBeenCalledWith(mockDbItem);
await databaseManager.removeDatabaseItem(mockDbItem);
// Should have deregistered this database
expect(deregisterSpy).toBeCalledWith(mockDbItem);
expect(deregisterSpy).toHaveBeenCalledWith(mockDbItem);
});
});

View File

@@ -39,7 +39,7 @@ describe("QueryTreeDataProvider", () => {
);
expect(dataProvider.getChildren()).toEqual([]);
expect(executeCommand).toBeCalledWith(
expect(executeCommand).toHaveBeenCalledWith(
"setContext",
"codeQL.noQueries",
true,
@@ -118,7 +118,7 @@ describe("QueryTreeDataProvider", () => {
onDidChangeQueriesEmitter.fire();
expect(dataProvider.getChildren().length).toEqual(2);
expect(executeCommand).toBeCalledWith(
expect(executeCommand).toHaveBeenCalledWith(
"setContext",
"codeQL.noQueries",
false,

View File

@@ -18,17 +18,17 @@ describe("helpers", () => {
listener({ length: secondStep });
expect(progressSpy).toBeCalledTimes(3);
expect(progressSpy).toBeCalledWith({
expect(progressSpy).toHaveBeenCalledWith({
step: 0,
maxStep: max,
message: "My prefix [0.0 MB of 4.0 MB]",
});
expect(progressSpy).toBeCalledWith({
expect(progressSpy).toHaveBeenCalledWith({
step: firstStep,
maxStep: max,
message: "My prefix [1.6 MB of 4.0 MB]",
});
expect(progressSpy).toBeCalledWith({
expect(progressSpy).toHaveBeenCalledWith({
step: firstStep + secondStep,
maxStep: max,
message: "My prefix [3.6 MB of 4.0 MB]",
@@ -51,7 +51,7 @@ describe("helpers", () => {
expect(mockReadable.on).not.toHaveBeenCalled();
expect(progressSpy).toBeCalledTimes(1);
expect(progressSpy).toBeCalledWith({
expect(progressSpy).toHaveBeenCalledWith({
step: 1,
maxStep: 2,
message: "My prefix (Size unknown)",

View File

@@ -55,9 +55,9 @@ describe("AstBuilder", () => {
const bqrsPath = path.normalize("/a/b/c/results.bqrs");
const options = { entities: ["id", "url", "string"] };
expect(mockCli.bqrsDecode).toBeCalledWith(bqrsPath, "nodes", options);
expect(mockCli.bqrsDecode).toBeCalledWith(bqrsPath, "edges", options);
expect(mockCli.bqrsDecode).toBeCalledWith(
expect(mockCli.bqrsDecode).toHaveBeenCalledWith(bqrsPath, "nodes", options);
expect(mockCli.bqrsDecode).toHaveBeenCalledWith(bqrsPath, "edges", options);
expect(mockCli.bqrsDecode).toHaveBeenCalledWith(
bqrsPath,
"graphProperties",
options,

View File

@@ -86,7 +86,7 @@ describe("AstViewer", () => {
const mockEvent = createMockEvent(selectionRange, fileUri);
(viewer as any).updateTreeSelection(mockEvent);
if (expectedSelection) {
expect(revealMock).toBeCalledWith(expectedSelection);
expect(revealMock).toHaveBeenCalledWith(expectedSelection);
} else {
expect(revealMock).not.toHaveBeenCalled();
}

View File

@@ -49,7 +49,7 @@ describe("qlpackOfDatabase", () => {
dbschemePack: "my-qlpack",
dbschemePackIsLibraryPack: false,
});
expect(getPrimaryDbschemeSpy).toBeCalledWith("/path/to/database");
expect(getPrimaryDbschemeSpy).toHaveBeenCalledWith("/path/to/database");
});
});

View File

@@ -619,7 +619,7 @@ describe("QueryHistoryManager", () => {
const inProgress1 = variantAnalysisHistory[1];
await queryHistoryManager.handleCancel([inProgress1]);
expect(cancelVariantAnalysisSpy).toBeCalledWith(
expect(cancelVariantAnalysisSpy).toHaveBeenCalledWith(
inProgress1.variantAnalysis.id,
);
});
@@ -632,10 +632,10 @@ describe("QueryHistoryManager", () => {
const inProgress2 = variantAnalysisHistory[3];
await queryHistoryManager.handleCancel([inProgress1, inProgress2]);
expect(cancelVariantAnalysisSpy).toBeCalledWith(
expect(cancelVariantAnalysisSpy).toHaveBeenCalledWith(
inProgress1.variantAnalysis.id,
);
expect(cancelVariantAnalysisSpy).toBeCalledWith(
expect(cancelVariantAnalysisSpy).toHaveBeenCalledWith(
inProgress2.variantAnalysis.id,
);
});
@@ -675,7 +675,7 @@ describe("QueryHistoryManager", () => {
const completedVariantAnalysis = variantAnalysisHistory[0];
await queryHistoryManager.handleCancel([completedVariantAnalysis]);
expect(cancelVariantAnalysisSpy).not.toBeCalledWith(
expect(cancelVariantAnalysisSpy).not.toHaveBeenCalledWith(
completedVariantAnalysis.variantAnalysis,
);
});
@@ -691,10 +691,10 @@ describe("QueryHistoryManager", () => {
completedVariantAnalysis,
failedVariantAnalysis,
]);
expect(cancelVariantAnalysisSpy).not.toBeCalledWith(
expect(cancelVariantAnalysisSpy).not.toHaveBeenCalledWith(
completedVariantAnalysis.variantAnalysis.id,
);
expect(cancelVariantAnalysisSpy).not.toBeCalledWith(
expect(cancelVariantAnalysisSpy).not.toHaveBeenCalledWith(
failedVariantAnalysis.variantAnalysis.id,
);
});
@@ -718,9 +718,9 @@ describe("QueryHistoryManager", () => {
const item = variantAnalysisHistory[1];
await queryHistoryManager.handleCopyRepoList(item);
expect(variantAnalysisManagerStub.copyRepoListToClipboard).toBeCalledWith(
item.variantAnalysis.id,
);
expect(
variantAnalysisManagerStub.copyRepoListToClipboard,
).toHaveBeenCalledWith(item.variantAnalysis.id);
});
});
@@ -739,7 +739,7 @@ describe("QueryHistoryManager", () => {
const item = variantAnalysisHistory[1];
await queryHistoryManager.handleExportResults(item);
expect(variantAnalysisManagerStub.exportResults).toBeCalledWith(
expect(variantAnalysisManagerStub.exportResults).toHaveBeenCalledWith(
item.variantAnalysis.id,
);
});

View File

@@ -184,7 +184,9 @@ describe("Variant Analyses and QueryHistoryManager", () => {
await qhm.readQueryHistory();
await qhm.handleItemClicked(qhm.treeDataProvider.allHistory[0]);
expect(showViewStub).toBeCalledWith(rawQueryHistory[0].variantAnalysis.id);
expect(showViewStub).toHaveBeenCalledWith(
rawQueryHistory[0].variantAnalysis.id,
);
});
it("should get the query text", async () => {

View File

@@ -130,7 +130,7 @@ describe("query-results", () => {
queryPath,
"sortedResults-cc8589f226adc134f87f2438e10075e0667571c72342068e2281e0b3b65e1092.bqrs",
);
expect(spy).toBeCalledWith(
expect(spy).toHaveBeenCalledWith(
expectedResultsPath,
expectedSortedResultsPath,
"a-result-set-name",
@@ -189,7 +189,7 @@ describe("query-results", () => {
);
expect(results).toEqual({ a: "1234", t: "SarifInterpretationData" });
expect(spy).toBeCalledWith(
expect(spy).toHaveBeenCalledWith(
metadata,
resultsPath,
interpretedResultsPath,
@@ -214,7 +214,7 @@ describe("query-results", () => {
sourceInfo as SourceInfo,
);
expect(results).toEqual({ a: "1234", t: "SarifInterpretationData" });
expect(spy).toBeCalledWith(
expect(spy).toHaveBeenCalledWith(
{ kind: "my-kind", id: "dummy-id", scored: undefined },
resultsPath,
interpretedResultsPath,

View File

@@ -161,23 +161,23 @@ describe("test-runner", () => {
).toBeGreaterThan(openDatabaseSpy.mock.invocationCallOrder[0]);
expect(removeDatabaseItemSpy).toBeCalledTimes(1);
expect(removeDatabaseItemSpy).toBeCalledWith(preTestDatabaseItem);
expect(removeDatabaseItemSpy).toHaveBeenCalledWith(preTestDatabaseItem);
expect(openDatabaseSpy).toBeCalledTimes(1);
expect(openDatabaseSpy).toBeCalledWith(
expect(openDatabaseSpy).toHaveBeenCalledWith(
preTestDatabaseItem.databaseUri,
preTestDatabaseItem.origin,
false,
);
expect(renameDatabaseItemSpy).toBeCalledTimes(1);
expect(renameDatabaseItemSpy).toBeCalledWith(
expect(renameDatabaseItemSpy).toHaveBeenCalledWith(
postTestDatabaseItem,
preTestDatabaseItem.name,
);
expect(setCurrentDatabaseItemSpy).toBeCalledTimes(1);
expect(setCurrentDatabaseItemSpy).toBeCalledWith(
expect(setCurrentDatabaseItemSpy).toHaveBeenCalledWith(
postTestDatabaseItem,
true,
);