Skip to content

Commit ccce2a0

Browse files
Run scope tests as unit test outside of vscode (#3210)
We're getting quite a lot of scope test by now and running all of them inside of the yes code is very slow. This updates allow us to run the scope test as unit tests outside of the vscode. It also refactors the test workflow so all unit tests run outside of the editors. As a side defect of running into quite a lot of bugs for this implementation I added better error messages, missing error logging, missing types etc in various files.
1 parent fac40c0 commit ccce2a0

48 files changed

Lines changed: 703 additions & 1265 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/test.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,25 @@ jobs:
6262
- name: Build
6363
run: pnpm --color --filter '!cursorless-org' --filter '!cursorless-org-*' build
6464

65-
- name: Run tests (Linux)
65+
- name: Lint
66+
run: pnpm --color lint
67+
68+
- name: Run unit tests (Linux)
6669
run: xvfb-run -a pnpm --color test
6770
if: runner.os == 'Linux'
6871

69-
- name: Run tests (Win,Mac)
72+
- name: Run unit tests (Win,Mac)
7073
run: pnpm --color test
7174
if: runner.os != 'Linux'
7275

76+
- name: Run VSCode tests (Linux)
77+
run: xvfb-run -a pnpm -F @cursorless/test-harness test:vscode
78+
if: runner.os == 'Linux'
79+
80+
- name: Run VSCode tests (Win,Mac)
81+
run: pnpm -F @cursorless/test-harness test:vscode
82+
if: runner.os != 'Linux'
83+
7384
- name: Run Talon-JS tests (Linux)
7485
run: xvfb-run -a pnpm -F @cursorless/test-harness test:talonJs
7586
if: runner.os == 'Linux' && matrix.app_version == 'stable'

.vscode/launch.json

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -202,41 +202,6 @@
202202
]
203203
},
204204

205-
// Unit tests launch configs
206-
{
207-
"name": "Unit tests: Test",
208-
"type": "node",
209-
"request": "launch",
210-
"program": "${workspaceFolder}/packages/test-harness/dist/runUnitTestsOnly.cjs",
211-
"env": {
212-
"CURSORLESS_MODE": "test",
213-
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
214-
},
215-
"outFiles": ["${workspaceFolder}/**/out/**/*.js"],
216-
"preLaunchTask": "VSCode: Build extension and tests",
217-
"resolveSourceMapLocations": [
218-
"${workspaceFolder}/**",
219-
"!**/node_modules/**"
220-
]
221-
},
222-
{
223-
"name": "Unit tests: Update test fixtures",
224-
"type": "node",
225-
"request": "launch",
226-
"program": "${workspaceFolder}/packages/test-harness/dist/runUnitTestsOnly.cjs",
227-
"env": {
228-
"CURSORLESS_MODE": "test",
229-
"CURSORLESS_TEST_UPDATE_FIXTURES": "true",
230-
"CURSORLESS_REPO_ROOT": "${workspaceFolder}"
231-
},
232-
"outFiles": ["${workspaceFolder}/**/out/**/*.js"],
233-
"preLaunchTask": "VSCode: Build extension and tests",
234-
"resolveSourceMapLocations": [
235-
"${workspaceFolder}/**",
236-
"!**/node_modules/**"
237-
]
238-
},
239-
240205
// Docusaurus launch configs
241206
{
242207
"name": "Docusaurus: Run",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"meta-updater:base": "pnpm --filter=@cursorless/meta-updater build && meta-updater",
2727
"preinstall": "npx only-allow pnpm",
2828
"test-compile": "tsc --build",
29-
"test": "pnpm compile && pnpm lint && pnpm -F '!test-harness' test && pnpm -F test-harness test",
29+
"test": "pnpm -r test",
3030
"generate-grammar": "pnpm -r generate-grammar",
3131
"transform-recorded-tests": "./packages/common/scripts/my-ts-node.js packages/cursorless-engine/src/scripts/transformRecordedTests/index.ts",
3232
"watch": "pnpm run -w --parallel '/^watch:.*/'",

packages/common/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"cross-spawn": "^7.0.6",
3939
"fast-check": "^4.5.3",
4040
"js-yaml": "^4.1.1",
41-
"mocha": "^11.7.5"
41+
"mocha": "^11.7.5",
42+
"web-tree-sitter": "^0.26.6"
4243
}
4344
}

packages/common/scripts/my-ts-node.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ async function main() {
8888
bundle: true,
8989
format: "cjs",
9090
outfile: outFile,
91+
external: ["./reporters/parallel-buffered", "./worker.js"],
9192
});
9293

9394
const nodeProcess = runCommand(

packages/common/src/ide/fake/FakeIDE.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { pull } from "lodash-es";
2-
import type { EditableTextEditor, NotebookEditor, TextEditor } from "../..";
2+
import type {
3+
EditableTextEditor,
4+
Messages,
5+
NotebookEditor,
6+
TextEditor,
7+
} from "../..";
38
import type { GeneralizedRange } from "../../types/GeneralizedRange";
49
import type { TextDocument } from "../../types/TextDocument";
510
import type { TextDocumentChangeEvent } from "../types/Events";
@@ -24,11 +29,11 @@ import FakeKeyValueStore from "./FakeKeyValueStore";
2429
import FakeMessages from "./FakeMessages";
2530

2631
export class FakeIDE implements IDE {
27-
configuration: FakeConfiguration = new FakeConfiguration();
28-
messages: FakeMessages = new FakeMessages();
29-
keyValueStore: FakeKeyValueStore = new FakeKeyValueStore();
30-
clipboard: FakeClipboard = new FakeClipboard();
31-
capabilities: FakeCapabilities = new FakeCapabilities();
32+
configuration = new FakeConfiguration();
33+
keyValueStore = new FakeKeyValueStore();
34+
clipboard = new FakeClipboard();
35+
capabilities = new FakeCapabilities();
36+
messages: Messages;
3237

3338
runMode: RunMode = "test";
3439
cursorlessVersion: string = "0.0.0";
@@ -37,6 +42,10 @@ export class FakeIDE implements IDE {
3742
private assetsRoot_: string | undefined;
3843
private quickPickReturnValue: string | undefined = undefined;
3944

45+
constructor(messages: Messages = new FakeMessages()) {
46+
this.messages = messages;
47+
}
48+
4049
async flashRanges(_flashDescriptors: FlashDescriptor[]): Promise<void> {
4150
// empty
4251
}
@@ -57,8 +66,9 @@ export class FakeIDE implements IDE {
5766
dummyEvent;
5867
onDidChangeTextEditorVisibleRanges: Event<TextEditorVisibleRangesChangeEvent> =
5968
dummyEvent;
69+
onDidChangeTextDocument: Event<TextDocumentChangeEvent> = dummyEvent;
6070

61-
public mockAssetsRoot(_assetsRoot: string) {
71+
mockAssetsRoot(_assetsRoot: string) {
6272
this.assetsRoot_ = _assetsRoot;
6373
}
6474

@@ -71,41 +81,41 @@ export class FakeIDE implements IDE {
7181
}
7282

7383
get activeTextEditor(): TextEditor | undefined {
74-
throw Error("Not implemented");
84+
throw Error("activeTextEditor: not implemented");
7585
}
7686

7787
get activeEditableTextEditor(): EditableTextEditor | undefined {
78-
throw Error("Not implemented");
88+
throw Error("activeEditableTextEditor: not implemented");
7989
}
8090

8191
get visibleTextEditors(): TextEditor[] {
82-
throw Error("Not implemented");
92+
return [];
8393
}
8494

8595
get visibleNotebookEditors(): NotebookEditor[] {
86-
throw Error("Not implemented");
96+
return [];
8797
}
8898

8999
public getEditableTextEditor(_editor: TextEditor): EditableTextEditor {
90-
throw Error("Not implemented");
100+
throw Error("getEditableTextEditor: not implemented");
91101
}
92102

93103
public findInDocument(_query: string, _editor: TextEditor): Promise<void> {
94-
throw Error("Not implemented");
104+
throw Error("findInDocument: not implemented");
95105
}
96106

97107
public findInWorkspace(_query: string): Promise<void> {
98-
throw Error("Not implemented");
108+
throw Error("findInWorkspace: not implemented");
99109
}
100110

101111
public openTextDocument(_path: string): Promise<TextEditor> {
102-
throw Error("Not implemented");
112+
throw Error("openTextDocument: not implemented");
103113
}
104114

105115
public openUntitledTextDocument(
106116
_options: OpenUntitledTextDocumentOptions,
107117
): Promise<TextEditor> {
108-
throw Error("Not implemented");
118+
throw Error("openUntitledTextDocument: not implemented");
109119
}
110120

111121
public setQuickPickReturnValue(value: string | undefined) {
@@ -120,17 +130,11 @@ export class FakeIDE implements IDE {
120130
}
121131

122132
public showInputBox(_options?: any): Promise<string | undefined> {
123-
throw Error("Not implemented");
133+
throw Error("showInputBox: not implemented");
124134
}
125135

126136
executeCommand<T>(_command: string, ..._args: any[]): Promise<T | undefined> {
127-
throw new Error("Method not implemented.");
128-
}
129-
130-
public onDidChangeTextDocument(
131-
_listener: (event: TextDocumentChangeEvent) => void,
132-
): Disposable {
133-
throw Error("Not implemented");
137+
throw new Error("executeCommand: not implemented");
134138
}
135139

136140
disposeOnExit(...disposables: Disposable[]): () => void {

packages/common/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export * from "./util/DefaultMap";
104104
export * from "./util/disposableFrom";
105105
export * from "./util/ensureCommandShape";
106106
export * from "./util/getEnvironmentVariableStrict";
107+
export * from "./util/getErrorMessage";
107108
export * from "./util/itertools";
108109
export * from "./util/Notifier";
109110
export * from "./util/object";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function getErrorMessage(error: unknown): string {
2+
return error instanceof Error ? error.message : String(error);
3+
}

packages/cursorless-engine/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@
4141
"zod": "^4.3.6"
4242
},
4343
"devDependencies": {
44+
"@types/chai": "^5.2.3",
4445
"@types/js-yaml": "^4.0.9",
4546
"@types/lodash-es": "^4.17.12",
4647
"@types/mocha": "^10.0.10",
4748
"@types/moo": "^0.5.10",
4849
"@types/nearley": "^2.11.5",
4950
"@types/sinon": "^21.0.0",
51+
"chai": "^6.2.2",
5052
"js-yaml": "^4.1.1",
5153
"mocha": "^11.7.5",
52-
"sinon": "^21.0.2"
54+
"sinon": "^21.0.2",
55+
"vscode-uri": "^3.1.0",
56+
"web-tree-sitter": "^0.26.6"
5357
}
5458
}

packages/cursorless-engine/src/api/CursorlessEngineApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import type {
1313
} from "@cursorless/common";
1414
import type { CommandRunner } from "../CommandRunner";
1515
import type { StoredTargetMap } from "../core/StoredTargets";
16+
import type { LanguageDefinitions } from "../languages/LanguageDefinitions";
1617

1718
export interface CursorlessEngine {
1819
commandApi: CommandApi;
20+
languageDefinitions: LanguageDefinitions;
1921
scopeProvider: ScopeProvider;
2022
customSpokenFormGenerator: CustomSpokenFormGenerator;
2123
storedTargets: StoredTargetMap;

0 commit comments

Comments
 (0)