Fix variant analysis submission integration test
Apparently, we're not importing the same `config` file as is used by the actual extension, so mocking methods in this file does not do anything. However, we can mock the `vscode` module, so we can use this for returning different values in the configuration. We also need to mock the authentication session since we don't have one.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import * as path from "path";
|
||||
|
||||
import {
|
||||
authentication,
|
||||
commands,
|
||||
extensions,
|
||||
QuickPickItem,
|
||||
@@ -12,7 +13,6 @@ import * as Octokit from "@octokit/rest";
|
||||
import { retry } from "@octokit/plugin-retry";
|
||||
|
||||
import { CodeQLExtensionInterface } from "../../../extension";
|
||||
import * as config from "../../../config";
|
||||
import { Credentials } from "../../../authentication";
|
||||
import { MockGitHubApiServer } from "../../../mocks/mock-gh-api-server";
|
||||
|
||||
@@ -38,18 +38,66 @@ describe("Variant Analysis Submission Integration", () => {
|
||||
let showErrorMessageSpy: jest.SpiedFunction<typeof window.showErrorMessage>;
|
||||
|
||||
beforeEach(async () => {
|
||||
jest.spyOn(config, "isCanary").mockReturnValue(true);
|
||||
const originalGetConfiguration = workspace.getConfiguration;
|
||||
|
||||
jest
|
||||
.spyOn(config, "isVariantAnalysisLiveResultsEnabled")
|
||||
.mockReturnValue(true);
|
||||
.spyOn(workspace, "getConfiguration")
|
||||
.mockImplementation((section, scope) => {
|
||||
const configuration = originalGetConfiguration(section, scope);
|
||||
|
||||
return {
|
||||
get(key: string, defaultValue?: unknown) {
|
||||
if (section === "codeQL.variantAnalysis" && key === "liveResults") {
|
||||
return true;
|
||||
}
|
||||
if (section === "codeQL" && key == "canary") {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
section === "codeQL.variantAnalysis" &&
|
||||
key === "controllerRepo"
|
||||
) {
|
||||
return "github/vscode-codeql";
|
||||
}
|
||||
return configuration.get(key, defaultValue);
|
||||
},
|
||||
has(key: string) {
|
||||
return configuration.has(key);
|
||||
},
|
||||
inspect(key: string) {
|
||||
return configuration.inspect(key);
|
||||
},
|
||||
update(
|
||||
key: string,
|
||||
value: unknown,
|
||||
configurationTarget?: boolean,
|
||||
overrideInLanguage?: boolean,
|
||||
) {
|
||||
return configuration.update(
|
||||
key,
|
||||
value,
|
||||
configurationTarget,
|
||||
overrideInLanguage,
|
||||
);
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
jest.spyOn(authentication, "getSession").mockResolvedValue({
|
||||
id: "test",
|
||||
accessToken: "test-token",
|
||||
scopes: [],
|
||||
account: {
|
||||
id: "test",
|
||||
label: "test",
|
||||
},
|
||||
});
|
||||
|
||||
const mockCredentials = {
|
||||
getOctokit: () => Promise.resolve(new Octokit.Octokit({ retry })),
|
||||
} as unknown as Credentials;
|
||||
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
|
||||
|
||||
await config.setRemoteControllerRepo("github/vscode-codeql");
|
||||
|
||||
quickPickSpy = jest
|
||||
.spyOn(window, "showQuickPick")
|
||||
.mockResolvedValue(undefined);
|
||||
|
||||
Reference in New Issue
Block a user