Skip to content

Commit 7d67236

Browse files
authored
Migrate test running to the new vscode-test-cli (#4079)
Migrate test running to the new vscode-test-cli (#4079) ### Motivation The test setup for VS Code extensions has changed a bit since the time when we created the Ruby LSP. This PR migrates us to the latest recommendations. ### Implementation Basically, we now use `@vscode/test-cli` which allows us to configure our tests in a declarative way. This allows us to get rid of some boiler plate files like `index.ts`. The other side of this is that we can now run tests through the test explorer panel, allowing us to easily run a single example at a time. Much better DX. Co-authored-by: vinistock <18742907+vinistock@users.noreply.github.com>
1 parent b4e6c9b commit 7d67236

11 files changed

Lines changed: 286 additions & 99 deletions

File tree

.vscode/extensions.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"recommendations": [
33
"shopify.ruby-extensions-pack",
4-
"dbaeumer.vscode-eslint"
4+
"dbaeumer.vscode-eslint",
5+
"ms-vscode.extension-test-runner"
56
]
67
}

AGENTS.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,36 @@ is the client).
198198

199199
```bash
200200
pnpm run lint # Lint TypeScript code
201-
pnpm run test # Run extension tests
201+
pnpm run test # Run extension tests (compiles via the `pretest` hook, then runs vscode-test)
202+
```
203+
204+
### Running targeted tests
205+
206+
Pass flags through `pnpm run test --` so they reach `vscode-test` instead of being consumed by pnpm:
207+
208+
```bash
209+
# Run a single compiled test file (use the .js path, not .ts)
210+
pnpm run test -- --run out/test/suite/workspace.test.js
211+
212+
# Run several files at once
213+
pnpm run test -- --run out/test/suite/workspace.test.js --run out/test/suite/client.test.js
214+
215+
# Filter by suite or test name (regex match against the full "suite > test" name)
216+
pnpm run test -- --grep "Workspace"
217+
pnpm run test -- --grep "does not restart when watched files"
218+
219+
# Literal string match (no regex) — useful when the test name has regex metacharacters
220+
pnpm run test -- --fgrep "repeated rebase steps"
221+
222+
# Invert the match — run everything except what `--grep`/`--fgrep` selects
223+
pnpm run test -- --grep "slow integration" --invert
224+
225+
# Combine file scoping with name filtering for the fastest feedback loop
226+
pnpm run test -- --run out/test/suite/testController.test.js --grep "discovers tests"
227+
228+
# List which tests would run without executing them (great for verifying a filter)
229+
pnpm run test -- --dry-run --grep "Workspace"
230+
231+
# Stop at the first failure
232+
pnpm run test -- --bail --grep "Client"
202233
```

vscode/.vscode-test.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from "@vscode/test-cli";
2+
3+
export default defineConfig({
4+
files: "out/test/suite/**/*.test.js",
5+
mocha: {
6+
ui: "tdd",
7+
color: true,
8+
},
9+
});

vscode/.vscode/launch.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// Use IntelliSense to learn about possible attributes.
33
// Hover to view descriptions of existing attributes.
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
//
6+
// To debug extension tests, install the "Extension Test Runner" extension
7+
// (ms-vscode.extension-test-runner). It reads .vscode-test.mjs and exposes
8+
// the tests in the Test Explorer with debugging support.
59
{
610
"version": "0.2.0",
711
"configurations": [
@@ -16,19 +20,6 @@
1620
"${workspaceFolder}/out/**/*.js"
1721
],
1822
"preLaunchTask": "${defaultBuildTask}"
19-
},
20-
{
21-
"name": "Extension Tests",
22-
"type": "extensionHost",
23-
"request": "launch",
24-
"args": [
25-
"--extensionDevelopmentPath=${workspaceFolder}",
26-
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
27-
],
28-
"outFiles": [
29-
"${workspaceFolder}/out/test/**/*.js"
30-
],
31-
"preLaunchTask": "${defaultBuildTask}"
3223
}
3324
]
3425
}

vscode/.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"files.exclude": {
3+
"**/out": false
4+
},
5+
"search.exclude": {
6+
"**/out": false
7+
}
8+
}

vscode/.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.vscode/**
22
.vscode-test/**
3+
.vscode-test.mjs
34
src/**
45
.gitignore
56
vsc-extension-quickstart.md

vscode/eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export default tseslint.config(
2727
{
2828
ignores: [
2929
"**/.vscode-test/**",
30+
".vscode-test.mjs",
3031
"eslint.config.mjs",
3132
"**/out/",
3233
"src/test/suite/fakeTestServer.js",

vscode/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@
810810
"pretest": "pnpm run compile",
811811
"format": "eslint . --fix && prettier '**/*.{ts,json,md,yaml,yml}' --write",
812812
"lint": "eslint . && prettier '**/*.{ts,json,md,yaml,yml}' --check",
813-
"test": "node ./out/test/runTest.js"
813+
"test": "vscode-test"
814814
},
815815
"pnpm": {
816816
"overrides": {
@@ -825,12 +825,12 @@
825825
"@types/node": "25.x",
826826
"@types/sinon": "^21.0.1",
827827
"@types/vscode": "^1.91.0",
828+
"@vscode/test-cli": "^0.0.12",
828829
"@vscode/test-electron": "^2.5.2",
829830
"@vscode/vsce": "^3.9.1",
830831
"esbuild": "^0.28.0",
831832
"eslint": "^9.30.1",
832833
"eslint-plugin-prettier": "^5.5.5",
833-
"glob": "^13.0.6",
834834
"mocha": "^11.7.5",
835835
"ovsx": "^0.10.11",
836836
"prettier": "^3.8.3",

0 commit comments

Comments
 (0)