File tree Expand file tree Collapse file tree 5 files changed +49
-0
lines changed Expand file tree Collapse file tree 5 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { TestHelpers } from "@cursorless/vscode-common";
2020import * as vscode from "vscode" ;
2121import { VscodeIDE } from "./ide/vscode/VscodeIDE" ;
2222import { toVscodeEditor } from "./ide/vscode/toVscodeEditor" ;
23+ import { vscodeApi } from "./vscodeApi" ;
2324
2425export function constructTestHelpers (
2526 commandServerApi : CommandServerApi | null ,
@@ -74,5 +75,6 @@ export function constructTestHelpers(
7475 } ,
7576 hatTokenMap,
7677 runIntegrationTests,
78+ vscodeApi,
7779 } ;
7880}
Original file line number Diff line number Diff line change 1+ import { workspace , window } from "vscode" ;
2+ import { VscodeApi } from "@cursorless/vscode-common" ;
3+
4+ /**
5+ * A very thin wrapper around the VSCode API that allows us to mock it for
6+ * testing. This is necessary because the test harness gets bundled separately
7+ * from the extension code, so if we just import the VSCode API directly from
8+ * the extension code, and from the test harness, we'll end up with two copies
9+ * of the VSCode API, so the mocks won't work.
10+ */
11+ export const vscodeApi : VscodeApi = {
12+ workspace,
13+ window,
14+ editor : {
15+ setDecorations ( editor , ...args ) {
16+ return editor . setDecorations ( ...args ) ;
17+ } ,
18+ } ,
19+ } ;
Original file line number Diff line number Diff line change 1+ import { workspace , window , TextEditor } from "vscode" ;
2+
3+ /**
4+ * Subset of VSCode api that we need to be able to mock for testing
5+ */
6+ export interface VscodeApi {
7+ workspace : typeof workspace ;
8+ window : typeof window ;
9+
10+ /**
11+ * Wrapper around editor api for easy mocking. Provides various
12+ * {@link TextEditor} methods as static functions which take a text editor as
13+ * their first argument.
14+ */
15+ editor : {
16+ setDecorations (
17+ editor : TextEditor ,
18+ ...args : Parameters < TextEditor [ "setDecorations" ] >
19+ ) : ReturnType < TextEditor [ "setDecorations" ] > ;
20+ } ;
21+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import type {
1313} from "@cursorless/common" ;
1414import * as vscode from "vscode" ;
1515import type { Language , SyntaxNode , Tree } from "web-tree-sitter" ;
16+ import { VscodeApi } from "./VscodeApi" ;
1617
1718export interface TestHelpers {
1819 ide : NormalizedIDE ;
@@ -42,6 +43,11 @@ export interface TestHelpers {
4243 ) : Promise < TestCaseSnapshot > ;
4344
4445 runIntegrationTests ( ) : Promise < void > ;
46+
47+ /**
48+ * A thin wrapper around the VSCode API that allows us to mock it for testing.
49+ */
50+ vscodeApi : VscodeApi ;
4551}
4652
4753export interface CursorlessApi {
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ export * from "./notebook";
33export * from "./testUtil/openNewEditor" ;
44export * from "./vscodeUtil" ;
55export * from "./runCommand" ;
6+ export * from "./VscodeApi" ;
You can’t perform that action at this time.
0 commit comments