Merge pull request #3327 from github/robertbrignull/VsCodeWindow

Introduce VsCodeWindow to provide types for the fields we're reading/writing
This commit is contained in:
Robert
2024-02-08 10:32:48 +00:00
committed by GitHub
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")); await userEvent.click(screen.getByText("Show paths"));
expect((window as any).vsCodeApi.postMessage).toHaveBeenCalledWith({ expect(window.vsCodeApi.postMessage).toHaveBeenCalledWith({
t: "showDataFlowPaths", t: "showDataFlowPaths",
dataFlowPaths: { dataFlowPaths: {
codeFlows: createMockCodeFlows(), codeFlows: createMockCodeFlows(),

View File

@@ -16,14 +16,12 @@ Object.defineProperty(window, "matchMedia", {
}); });
// Used by Primer React // Used by Primer React
(window as any).CSS = { window.CSS.supports = jest.fn().mockResolvedValue(false);
supports: jest.fn().mockResolvedValue(false),
};
// Store this on the window so we can mock it // Store this on the window so we can mock it
(window as any).vsCodeApi = { window.vsCodeApi = {
postMessage: jest.fn(), postMessage: jest.fn(),
setState: 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", t: "requestRepositoryResults",
repositoryFullName: "octodemo/hello-world-1", 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;
}
}