Use resetMocks option to reset mocks before every test
This commit is contained in:
@@ -102,7 +102,7 @@ const config: Config = {
|
|||||||
// reporters: undefined,
|
// reporters: undefined,
|
||||||
|
|
||||||
// Automatically reset mock state before every test
|
// Automatically reset mock state before every test
|
||||||
// resetMocks: false,
|
resetMocks: true,
|
||||||
|
|
||||||
// Reset the module registry before running each individual test
|
// Reset the module registry before running each individual test
|
||||||
// resetModules: false,
|
// resetModules: false,
|
||||||
|
|||||||
@@ -3,7 +3,3 @@ import { env } from "vscode";
|
|||||||
(env as any).openExternal = () => {
|
(env as any).openExternal = () => {
|
||||||
/**/
|
/**/
|
||||||
};
|
};
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
jest.restoreAllMocks();
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -28,18 +28,18 @@ describe("queryResolver", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
writeFileSpy.mockReset().mockImplementation(() => Promise.resolve());
|
writeFileSpy.mockImplementation(() => Promise.resolve());
|
||||||
|
|
||||||
getQlPackForDbschemeSpy.mockReset().mockResolvedValue({
|
getQlPackForDbschemeSpy.mockResolvedValue({
|
||||||
dbschemePack: "dbschemePack",
|
dbschemePack: "dbschemePack",
|
||||||
dbschemePackIsLibraryPack: false,
|
dbschemePackIsLibraryPack: false,
|
||||||
});
|
});
|
||||||
getPrimaryDbschemeSpy.mockReset().mockResolvedValue("primaryDbscheme");
|
getPrimaryDbschemeSpy.mockResolvedValue("primaryDbscheme");
|
||||||
|
|
||||||
mockCli.resolveQueriesInSuite.mockReset();
|
mockCli.resolveQueriesInSuite;
|
||||||
mockCli.cliConstraints.supportsAllowLibraryPacksInResolveQueries
|
mockCli.cliConstraints.supportsAllowLibraryPacksInResolveQueries.mockReturnValue(
|
||||||
.mockReset()
|
true,
|
||||||
.mockReturnValue(true);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("resolveQueries", () => {
|
describe("resolveQueries", () => {
|
||||||
|
|||||||
@@ -25,9 +25,7 @@ describe("databaseFetcher", () => {
|
|||||||
} as unknown as Octokit.Octokit;
|
} as unknown as Octokit.Octokit;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
quickPickSpy.mockReset().mockResolvedValue(undefined);
|
quickPickSpy.mockResolvedValue(undefined);
|
||||||
progressSpy.mockReset();
|
|
||||||
mockRequest.mockReset();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert a GitHub nwo to a database url", async () => {
|
it("should convert a GitHub nwo to a database url", async () => {
|
||||||
@@ -135,8 +133,7 @@ describe("databaseFetcher", () => {
|
|||||||
const progressSpy = jest.fn();
|
const progressSpy = jest.fn();
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
quickPickSpy.mockReset().mockResolvedValue(undefined);
|
quickPickSpy.mockResolvedValue(undefined);
|
||||||
progressSpy.mockReset();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should convert a project url to a database url", async () => {
|
it("should convert a project url to a database url", async () => {
|
||||||
|
|||||||
@@ -206,13 +206,13 @@ describe("Launcher path", () => {
|
|||||||
let launcherThatExists = "";
|
let launcherThatExists = "";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
warnSpy.mockClear().mockResolvedValue(undefined);
|
warnSpy.mockResolvedValue(undefined);
|
||||||
errorSpy.mockClear().mockResolvedValue(undefined);
|
errorSpy.mockResolvedValue(undefined);
|
||||||
logSpy.mockClear().mockResolvedValue(undefined);
|
logSpy.mockResolvedValue(undefined);
|
||||||
pathExistsSpy.mockClear().mockImplementation(async (path: string) => {
|
pathExistsSpy.mockImplementation(async (path: string) => {
|
||||||
return path.endsWith(launcherThatExists);
|
return path.endsWith(launcherThatExists);
|
||||||
});
|
});
|
||||||
platformSpy.mockClear().mockReturnValue("win32");
|
platformSpy.mockReturnValue("win32");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not warn with proper launcher name", async () => {
|
it("should not warn with proper launcher name", async () => {
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ describe("helpers", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
showInformationMessageSpy.mockClear().mockResolvedValue(undefined);
|
showInformationMessageSpy.mockResolvedValue(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
const resolveArg =
|
const resolveArg =
|
||||||
|
|||||||
@@ -74,16 +74,12 @@ describe("query-history", () => {
|
|||||||
let variantAnalysisHistory: VariantAnalysisHistoryItem[];
|
let variantAnalysisHistory: VariantAnalysisHistoryItem[];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
showTextDocumentSpy
|
showTextDocumentSpy.mockResolvedValue(undefined as unknown as TextEditor);
|
||||||
.mockClear()
|
|
||||||
.mockResolvedValue(undefined as unknown as TextEditor);
|
|
||||||
|
|
||||||
showInformationMessageSpy.mockClear().mockResolvedValue(undefined);
|
showInformationMessageSpy.mockResolvedValue(undefined);
|
||||||
showQuickPickSpy.mockClear().mockResolvedValue(undefined);
|
showQuickPickSpy.mockResolvedValue(undefined);
|
||||||
executeCommandSpy.mockClear().mockResolvedValue(undefined);
|
executeCommandSpy.mockResolvedValue(undefined);
|
||||||
logSpy.mockClear().mockResolvedValue(undefined);
|
logSpy.mockResolvedValue(undefined);
|
||||||
|
|
||||||
doCompareCallback.mockReset();
|
|
||||||
|
|
||||||
tryOpenExternalFile = (QueryHistoryManager.prototype as any)
|
tryOpenExternalFile = (QueryHistoryManager.prototype as any)
|
||||||
.tryOpenExternalFile;
|
.tryOpenExternalFile;
|
||||||
@@ -478,10 +474,10 @@ describe("query-history", () => {
|
|||||||
request: getOctokitStub,
|
request: getOctokitStub,
|
||||||
}),
|
}),
|
||||||
} as unknown as Credentials;
|
} as unknown as Credentials;
|
||||||
credentialsSpy.mockReset().mockResolvedValue(mockCredentials);
|
credentialsSpy.mockResolvedValue(mockCredentials);
|
||||||
|
|
||||||
mockCancelRemoteQuery.mockClear().mockResolvedValue();
|
mockCancelRemoteQuery.mockResolvedValue();
|
||||||
getOctokitStub.mockClear();
|
getOctokitStub;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("if the item is in progress", () => {
|
describe("if the item is in progress", () => {
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ describe("query-results", () => {
|
|||||||
const sourceInfo = {};
|
const sourceInfo = {};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
spy.mockReset().mockReturnValue({ a: "1234" });
|
spy.mockReturnValue({ a: "1234" });
|
||||||
|
|
||||||
mockServer = {
|
mockServer = {
|
||||||
interpretBqrsSarif: spy,
|
interpretBqrsSarif: spy,
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ describe("export results", () => {
|
|||||||
describe("exportRemoteQueryAnalysisResults", () => {
|
describe("exportRemoteQueryAnalysisResults", () => {
|
||||||
const mockCredentials = {} as unknown as Credentials;
|
const mockCredentials = {} as unknown as Credentials;
|
||||||
|
|
||||||
jest.spyOn(markdownGenerator, "generateMarkdown").mockReturnValue([]);
|
beforeEach(() => {
|
||||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
jest.spyOn(markdownGenerator, "generateMarkdown").mockReturnValue([]);
|
||||||
|
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||||
|
});
|
||||||
|
|
||||||
it("should call the GitHub Actions API with the correct gist title", async function () {
|
it("should call the GitHub Actions API with the correct gist title", async function () {
|
||||||
const mockCreateGist = jest
|
const mockCreateGist = jest
|
||||||
|
|||||||
@@ -20,10 +20,6 @@ describe("gh-actions-api-client mock responses", () => {
|
|||||||
}),
|
}),
|
||||||
} as unknown as Credentials;
|
} as unknown as Credentials;
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
mockRequest.mockReset();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("cancelRemoteQuery", () => {
|
describe("cancelRemoteQuery", () => {
|
||||||
it("should cancel a remote query", async () => {
|
it("should cancel a remote query", async () => {
|
||||||
mockRequest.mockReturnValue({ status: 202 });
|
mockRequest.mockReturnValue({ status: 202 });
|
||||||
|
|||||||
@@ -80,10 +80,6 @@ describe("Remote queries and query history manager", () => {
|
|||||||
|
|
||||||
disposables = new DisposableBucket();
|
disposables = new DisposableBucket();
|
||||||
|
|
||||||
rehydrateRemoteQueryStub.mockReset();
|
|
||||||
removeRemoteQueryStub.mockReset();
|
|
||||||
openRemoteQueryResultsStub.mockReset();
|
|
||||||
|
|
||||||
rawQueryHistory = fs.readJSONSync(
|
rawQueryHistory = fs.readJSONSync(
|
||||||
path.join(STORAGE_DIR, "workspace-query-history.json"),
|
path.join(STORAGE_DIR, "workspace-query-history.json"),
|
||||||
).queries;
|
).queries;
|
||||||
|
|||||||
@@ -23,15 +23,15 @@ describe("repository selection", () => {
|
|||||||
const fsReadFileStub = jest.spyOn(fs, "readFile");
|
const fsReadFileStub = jest.spyOn(fs, "readFile");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
quickPickSpy.mockReset().mockResolvedValue(undefined);
|
quickPickSpy.mockResolvedValue(undefined);
|
||||||
showInputBoxSpy.mockReset().mockResolvedValue(undefined);
|
showInputBoxSpy.mockResolvedValue(undefined);
|
||||||
|
|
||||||
getRemoteRepositoryListsSpy.mockReset().mockReturnValue(undefined);
|
getRemoteRepositoryListsSpy.mockReturnValue(undefined);
|
||||||
getRemoteRepositoryListsPathSpy.mockReset().mockReturnValue(undefined);
|
getRemoteRepositoryListsPathSpy.mockReturnValue(undefined);
|
||||||
|
|
||||||
pathExistsStub.mockReset().mockImplementation(() => false);
|
pathExistsStub.mockImplementation(() => false);
|
||||||
fsStatStub.mockReset().mockRejectedValue(new Error("not found"));
|
fsStatStub.mockRejectedValue(new Error("not found"));
|
||||||
fsReadFileStub.mockReset().mockRejectedValue(new Error("not found"));
|
fsReadFileStub.mockRejectedValue(new Error("not found"));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("repo lists from settings", () => {
|
describe("repo lists from settings", () => {
|
||||||
|
|||||||
@@ -77,10 +77,6 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
|||||||
|
|
||||||
disposables = new DisposableBucket();
|
disposables = new DisposableBucket();
|
||||||
|
|
||||||
rehydrateVariantAnalysisStub.mockReset();
|
|
||||||
removeVariantAnalysisStub.mockReset();
|
|
||||||
showViewStub.mockReset();
|
|
||||||
|
|
||||||
rawQueryHistory = fs.readJSONSync(
|
rawQueryHistory = fs.readJSONSync(
|
||||||
path.join(STORAGE_DIR, "workspace-query-history.json"),
|
path.join(STORAGE_DIR, "workspace-query-history.json"),
|
||||||
).queries;
|
).queries;
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ describe("run-queries", () => {
|
|||||||
const isCanarySpy = jest.spyOn(config, "isCanary");
|
const isCanarySpy = jest.spyOn(config, "isCanary");
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
isCanarySpy.mockReset().mockReturnValue(false);
|
isCanarySpy.mockReturnValue(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should create a QueryEvaluationInfo", () => {
|
it("should create a QueryEvaluationInfo", () => {
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ describe("telemetry reporting", () => {
|
|||||||
|
|
||||||
ctx = createMockExtensionContext();
|
ctx = createMockExtensionContext();
|
||||||
|
|
||||||
sendTelemetryEventSpy.mockReset().mockReturnValue(undefined);
|
sendTelemetryEventSpy.mockReturnValue(undefined);
|
||||||
sendTelemetryExceptionSpy.mockReset().mockReturnValue(undefined);
|
sendTelemetryExceptionSpy.mockReturnValue(undefined);
|
||||||
disposeSpy.mockReset().mockResolvedValue(undefined);
|
disposeSpy.mockResolvedValue(undefined);
|
||||||
|
|
||||||
showInformationMessageSpy.mockReset().mockResolvedValue(undefined);
|
showInformationMessageSpy.mockResolvedValue(undefined);
|
||||||
|
|
||||||
originalTelemetryExtension = workspace
|
originalTelemetryExtension = workspace
|
||||||
.getConfiguration()
|
.getConfiguration()
|
||||||
|
|||||||
@@ -42,12 +42,12 @@ describe("test-adapter", () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockRunTests();
|
mockRunTests();
|
||||||
openDatabaseSpy.mockReset().mockResolvedValue(postTestDatabaseItem);
|
openDatabaseSpy.mockResolvedValue(postTestDatabaseItem);
|
||||||
removeDatabaseItemSpy.mockReset().mockResolvedValue(undefined);
|
removeDatabaseItemSpy.mockResolvedValue(undefined);
|
||||||
renameDatabaseItemSpy.mockReset().mockResolvedValue(undefined);
|
renameDatabaseItemSpy.mockResolvedValue(undefined);
|
||||||
setCurrentDatabaseItemSpy.mockReset().mockResolvedValue(undefined);
|
setCurrentDatabaseItemSpy.mockResolvedValue(undefined);
|
||||||
resolveQlpacksSpy.mockReset().mockResolvedValue({});
|
resolveQlpacksSpy.mockResolvedValue({});
|
||||||
resolveTestsSpy.mockReset().mockResolvedValue([]);
|
resolveTestsSpy.mockResolvedValue([]);
|
||||||
fakeDatabaseManager = {
|
fakeDatabaseManager = {
|
||||||
openDatabase: openDatabaseSpy,
|
openDatabase: openDatabaseSpy,
|
||||||
removeDatabaseItem: removeDatabaseItemSpy,
|
removeDatabaseItem: removeDatabaseItemSpy,
|
||||||
@@ -124,7 +124,7 @@ describe("test-adapter", () => {
|
|||||||
databaseItems = [preTestDatabaseItem];
|
databaseItems = [preTestDatabaseItem];
|
||||||
await adapter.run(["/path/to/test/dir"]);
|
await adapter.run(["/path/to/test/dir"]);
|
||||||
|
|
||||||
expect(removeDatabaseItemSpy.mock.invocationCallOrder[0]).toBeGreaterThan(
|
expect(removeDatabaseItemSpy.mock.invocationCallOrder[0]).toBeLessThan(
|
||||||
runTestsSpy.mock.invocationCallOrder[0],
|
runTestsSpy.mock.invocationCallOrder[0],
|
||||||
);
|
);
|
||||||
expect(openDatabaseSpy.mock.invocationCallOrder[0]).toBeGreaterThan(
|
expect(openDatabaseSpy.mock.invocationCallOrder[0]).toBeGreaterThan(
|
||||||
|
|||||||
Reference in New Issue
Block a user