Skip to content

Commit

Permalink
Move vscode-common's TestHelpers interface to its own file. (#2032)
Browse files Browse the repository at this point in the history
This makes it easier to excise the related test-specific code from the
repo.

---------

Co-authored-by: Barry Jaspan <[email protected]>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 15, 2023
1 parent 024b5de commit 620c538
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 54 deletions.
54 changes: 54 additions & 0 deletions packages/vscode-common/src/TestHelpers.ts
Original file line number Diff line number Diff line change
@@ -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<TestCaseSnapshot>;

runIntegrationTests(): Promise<void>;

cursorlessTalonStateJsonPath: string;

/**
* A thin wrapper around the VSCode API that allows us to mock it for testing.
*/
vscodeApi: VscodeApi;
}
56 changes: 2 additions & 54 deletions packages/vscode-common/src/getExtensionApi.ts
Original file line number Diff line number Diff line change
@@ -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<TestCaseSnapshot>;

runIntegrationTests(): Promise<void>;

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;
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-common/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./getExtensionApi";
export * from "./TestHelpers";
export * from "./notebook";
export * from "./testUtil/openNewEditor";
export * from "./vscodeUtil";
Expand Down

0 comments on commit 620c538

Please sign in to comment.