File tree 5 files changed +49
-0
lines changed
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";
20
20
import * as vscode from "vscode" ;
21
21
import { VscodeIDE } from "./ide/vscode/VscodeIDE" ;
22
22
import { toVscodeEditor } from "./ide/vscode/toVscodeEditor" ;
23
+ import { vscodeApi } from "./vscodeApi" ;
23
24
24
25
export function constructTestHelpers (
25
26
commandServerApi : CommandServerApi | null ,
@@ -74,5 +75,6 @@ export function constructTestHelpers(
74
75
} ,
75
76
hatTokenMap,
76
77
runIntegrationTests,
78
+ vscodeApi,
77
79
} ;
78
80
}
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 {
13
13
} from "@cursorless/common" ;
14
14
import * as vscode from "vscode" ;
15
15
import type { Language , SyntaxNode , Tree } from "web-tree-sitter" ;
16
+ import { VscodeApi } from "./VscodeApi" ;
16
17
17
18
export interface TestHelpers {
18
19
ide : NormalizedIDE ;
@@ -42,6 +43,11 @@ export interface TestHelpers {
42
43
) : Promise < TestCaseSnapshot > ;
43
44
44
45
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 ;
45
51
}
46
52
47
53
export interface CursorlessApi {
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ export * from "./notebook";
3
3
export * from "./testUtil/openNewEditor" ;
4
4
export * from "./vscodeUtil" ;
5
5
export * from "./runCommand" ;
6
+ export * from "./VscodeApi" ;
You can’t perform that action at this time.
0 commit comments