From 620c53829546f65bad22410ee40c78564a881550 Mon Sep 17 00:00:00 2001 From: Barry Jaspan Date: Wed, 15 Nov 2023 08:47:01 -0500 Subject: [PATCH] Move vscode-common's TestHelpers interface to its own file. (#2032) This makes it easier to excise the related test-specific code from the repo. --------- Co-authored-by: Barry Jaspan Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- packages/vscode-common/src/TestHelpers.ts | 54 ++++++++++++++++++ packages/vscode-common/src/getExtensionApi.ts | 56 +------------------ packages/vscode-common/src/index.ts | 1 + 3 files changed, 57 insertions(+), 54 deletions(-) create mode 100644 packages/vscode-common/src/TestHelpers.ts diff --git a/packages/vscode-common/src/TestHelpers.ts b/packages/vscode-common/src/TestHelpers.ts new file mode 100644 index 0000000000..467c8d2782 --- /dev/null +++ b/packages/vscode-common/src/TestHelpers.ts @@ -0,0 +1,54 @@ +import type { + CommandServerApi, + ExcludableSnapshotField, + ExtraSnapshotField, + HatTokenMap, + IDE, + NormalizedIDE, + ScopeProvider, + SerializedMarks, + TargetPlainObject, + TestCaseSnapshot, + TextEditor, +} from "@cursorless/common"; +import * as vscode from "vscode"; +import { VscodeApi } from "./VscodeApi"; + +export interface TestHelpers { + ide: NormalizedIDE; + injectIde: (ide: IDE) => void; + + scopeProvider: ScopeProvider; + + hatTokenMap: HatTokenMap; + + commandServerApi: CommandServerApi; + + toVscodeEditor(editor: TextEditor): vscode.TextEditor; + + setStoredTarget( + editor: vscode.TextEditor, + key: string, + targets: TargetPlainObject[] | undefined, + ): void; + + // FIXME: Remove this once we have a better way to get this function + // accessible from our tests + takeSnapshot( + excludeFields: ExcludableSnapshotField[], + extraFields: ExtraSnapshotField[], + editor: TextEditor, + ide: IDE, + marks: SerializedMarks | undefined, + forceRealClipboard: boolean, + ): Promise; + + runIntegrationTests(): Promise; + + cursorlessTalonStateJsonPath: string; + + /** + * A thin wrapper around the VSCode API that allows us to mock it for testing. + */ + vscodeApi: VscodeApi; +} diff --git a/packages/vscode-common/src/getExtensionApi.ts b/packages/vscode-common/src/getExtensionApi.ts index c88b1b0b3d..fb1ed72c43 100644 --- a/packages/vscode-common/src/getExtensionApi.ts +++ b/packages/vscode-common/src/getExtensionApi.ts @@ -1,59 +1,7 @@ -import type { - CommandServerApi, - ExcludableSnapshotField, - ExtraSnapshotField, - HatTokenMap, - IDE, - NormalizedIDE, - ScopeProvider, - SerializedMarks, - SnippetMap, - TargetPlainObject, - TestCaseSnapshot, - TextEditor, -} from "@cursorless/common"; +import type { CommandServerApi, SnippetMap } from "@cursorless/common"; import * as vscode from "vscode"; import type { Language, SyntaxNode, Tree } from "web-tree-sitter"; -import { VscodeApi } from "./VscodeApi"; - -export interface TestHelpers { - ide: NormalizedIDE; - injectIde: (ide: IDE) => void; - - scopeProvider: ScopeProvider; - - hatTokenMap: HatTokenMap; - - commandServerApi: CommandServerApi; - - toVscodeEditor(editor: TextEditor): vscode.TextEditor; - - setStoredTarget( - editor: vscode.TextEditor, - key: string, - targets: TargetPlainObject[] | undefined, - ): void; - - // FIXME: Remove this once we have a better way to get this function - // accessible from our tests - takeSnapshot( - excludeFields: ExcludableSnapshotField[], - extraFields: ExtraSnapshotField[], - editor: TextEditor, - ide: IDE, - marks: SerializedMarks | undefined, - forceRealClipboard: boolean, - ): Promise; - - runIntegrationTests(): Promise; - - cursorlessTalonStateJsonPath: string; - - /** - * A thin wrapper around the VSCode API that allows us to mock it for testing. - */ - vscodeApi: VscodeApi; -} +import { TestHelpers } from "./TestHelpers"; export interface CursorlessApi { testHelpers: TestHelpers | undefined; diff --git a/packages/vscode-common/src/index.ts b/packages/vscode-common/src/index.ts index c6a679e3bc..ca15cb6dad 100644 --- a/packages/vscode-common/src/index.ts +++ b/packages/vscode-common/src/index.ts @@ -1,4 +1,5 @@ export * from "./getExtensionApi"; +export * from "./TestHelpers"; export * from "./notebook"; export * from "./testUtil/openNewEditor"; export * from "./vscodeUtil";