Introduce VsCodeWindow to provide types for the fields we're reading/writing

This commit is contained in:
Robert
2024-02-07 15:58:15 +00:00
parent 5fe5f70867
commit 4f11f7560b
4 changed files with 16 additions and 7 deletions

View File

@@ -29,7 +29,7 @@ describe(CodePaths.name, () => {
await userEvent.click(screen.getByText("Show paths"));
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
expect(window.vsCodeApi.postMessage).toHaveBeenCalledWith({
t: "showDataFlowPaths",
dataFlowPaths: {
codeFlows: createMockCodeFlows(),

View File

@@ -16,14 +16,12 @@ Object.defineProperty(window, "matchMedia", {
});
// Used by Primer React
(window as any).CSS = {
supports: jest.fn().mockResolvedValue(false),
};
window.CSS.supports = jest.fn().mockResolvedValue(false);
// Store this on the window so we can mock it
(window as any).vsCodeApi = {
window.vsCodeApi = {
postMessage: jest.fn(),
setState: jest.fn(),
};
(window as any).acquireVsCodeApi = () => (window as any).vsCodeApi;
window.acquireVsCodeApi = () => window.vsCodeApi;

View File

@@ -355,7 +355,7 @@ describe(RepoRow.name, () => {
);
});
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({
expect(window.vsCodeApi.postMessage).toHaveBeenCalledWith({
t: "requestRepositoryResults",
repositoryFullName: "octodemo/hello-world-1",
});

View File

@@ -0,0 +1,11 @@
import type { VsCodeApi } from "./vscode-api";
declare global {
interface Window {
CSS: {
supports: () => Promise<boolean>;
};
vsCodeApi: VsCodeApi;
acquireVsCodeApi: () => VsCodeApi;
}
}