Skip to content

Commit 4f11f75

Browse files
Introduce VsCodeWindow to provide types for the fields we're reading/writing
1 parent 5fe5f70 commit 4f11f75

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

extensions/ql-vscode/src/view/common/CodePaths/__tests__/CodePaths.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe(CodePaths.name, () => {
2929

3030
await userEvent.click(screen.getByText("Show paths"));
3131

32-
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
32+
expect(window.vsCodeApi.postMessage).toHaveBeenCalledWith({
3333
t: "showDataFlowPaths",
3434
dataFlowPaths: {
3535
codeFlows: createMockCodeFlows(),

extensions/ql-vscode/src/view/jest.setup.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@ Object.defineProperty(window, "matchMedia", {
1616
});
1717

1818
// Used by Primer React
19-
(window as any).CSS = {
20-
supports: jest.fn().mockResolvedValue(false),
21-
};
19+
window.CSS.supports = jest.fn().mockResolvedValue(false);
2220

2321
// Store this on the window so we can mock it
24-
(window as any).vsCodeApi = {
22+
window.vsCodeApi = {
2523
postMessage: jest.fn(),
2624
setState: jest.fn(),
2725
};
2826

29-
(window as any).acquireVsCodeApi = () => (window as any).vsCodeApi;
27+
window.acquireVsCodeApi = () => window.vsCodeApi;

extensions/ql-vscode/src/view/variant-analysis/__tests__/RepoRow.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ describe(RepoRow.name, () => {
355355
);
356356
});
357357

358-
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
358+
expect(window.vsCodeApi.postMessage).toHaveBeenCalledWith({
359359
t: "requestRepositoryResults",
360360
repositoryFullName: "octodemo/hello-world-1",
361361
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { VsCodeApi } from "./vscode-api";
2+
3+
declare global {
4+
interface Window {
5+
CSS: {
6+
supports: () => Promise<boolean>;
7+
};
8+
vsCodeApi: VsCodeApi;
9+
acquireVsCodeApi: () => VsCodeApi;
10+
}
11+
}

0 commit comments

Comments
 (0)