Skip to content

Commit f830c23

Browse files
committed
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.
1 parent 52e2a63 commit f830c23

1 file changed

Lines changed: 54 additions & 6 deletions

File tree

extensions/ql-vscode/src/vscode-tests/cli-integration/remote-queries/variant-analysis-submission-integration.test.ts

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as path from "path";
22

33
import {
4+
authentication,
45
commands,
56
extensions,
67
QuickPickItem,
@@ -12,7 +13,6 @@ import * as Octokit from "@octokit/rest";
1213
import { retry } from "@octokit/plugin-retry";
1314

1415
import { CodeQLExtensionInterface } from "../../../extension";
15-
import * as config from "../../../config";
1616
import { Credentials } from "../../../authentication";
1717
import { MockGitHubApiServer } from "../../../mocks/mock-gh-api-server";
1818

@@ -38,18 +38,66 @@ describe("Variant Analysis Submission Integration", () => {
3838
let showErrorMessageSpy: jest.SpiedFunction<typeof window.showErrorMessage>;
3939

4040
beforeEach(async () => {
41-
jest.spyOn(config, "isCanary").mockReturnValue(true);
41+
const originalGetConfiguration = workspace.getConfiguration;
42+
4243
jest
43-
.spyOn(config, "isVariantAnalysisLiveResultsEnabled")
44-
.mockReturnValue(true);
44+
.spyOn(workspace, "getConfiguration")
45+
.mockImplementation((section, scope) => {
46+
const configuration = originalGetConfiguration(section, scope);
47+
48+
return {
49+
get(key: string, defaultValue?: unknown) {
50+
if (section === "codeQL.variantAnalysis" && key === "liveResults") {
51+
return true;
52+
}
53+
if (section === "codeQL" && key == "canary") {
54+
return true;
55+
}
56+
if (
57+
section === "codeQL.variantAnalysis" &&
58+
key === "controllerRepo"
59+
) {
60+
return "github/vscode-codeql";
61+
}
62+
return configuration.get(key, defaultValue);
63+
},
64+
has(key: string) {
65+
return configuration.has(key);
66+
},
67+
inspect(key: string) {
68+
return configuration.inspect(key);
69+
},
70+
update(
71+
key: string,
72+
value: unknown,
73+
configurationTarget?: boolean,
74+
overrideInLanguage?: boolean,
75+
) {
76+
return configuration.update(
77+
key,
78+
value,
79+
configurationTarget,
80+
overrideInLanguage,
81+
);
82+
},
83+
};
84+
});
85+
86+
jest.spyOn(authentication, "getSession").mockResolvedValue({
87+
id: "test",
88+
accessToken: "test-token",
89+
scopes: [],
90+
account: {
91+
id: "test",
92+
label: "test",
93+
},
94+
});
4595

4696
const mockCredentials = {
4797
getOctokit: () => Promise.resolve(new Octokit.Octokit({ retry })),
4898
} as unknown as Credentials;
4999
jest.spyOn(Credentials, "initialize").mockResolvedValue(mockCredentials);
50100

51-
await config.setRemoteControllerRepo("github/vscode-codeql");
52-
53101
quickPickSpy = jest
54102
.spyOn(window, "showQuickPick")
55103
.mockResolvedValue(undefined);

0 commit comments

Comments
 (0)