Skip to content

Commit 0f8cfe0

Browse files
authored
chore: add test filtering during development (#862)
1 parent 3141f33 commit 0f8cfe0

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

.vscode/launch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,20 @@
5252
"--extensionDevelopmentPath=${workspaceFolder}",
5353
"--extensionTestsPath=${workspaceFolder}/out/test/suite"
5454
],
55+
"env": {
56+
"MOCHA_GREP": "${input:mochaGrep}"
57+
},
5558
"outFiles": ["${workspaceFolder}/out/**/*.js"],
5659
"preLaunchTask": "npm: compile:extension",
5760
}
5861
],
62+
"inputs": [
63+
{
64+
"id": "mochaGrep",
65+
"type": "promptString",
66+
"description": "Enter an optional grep filter to run specific tests. Leave blank for all.",
67+
}
68+
],
5969
"compounds": [
6070
{
6171
"name": "Extension + Server Inspector",

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ npm run watch
3535

3636
2. Inside of [VS Code Insiders](https://code.visualstudio.com/insiders/) open this directory and press `F5` to begin debugging the extension. This should launch a new VSCode window which is running the extension.
3737

38+
### Running Tests
39+
40+
#### Using the VSCode debugger
41+
42+
You can launch a debugging task for tests inside VSCode with the **"Run Tests"** task. There you can also specify an optional test filter.
43+
44+
#### Using command line
45+
46+
You can run tests using command line along with an optional `MOCHA_GREP` environment variable to apply a grep filter on tests to run.
47+
48+
```shell
49+
MOCHA_GREP="Participant .* prompt builders" npm test
50+
```
51+
52+
It may be quicker to be more specific and use `npm run test-extension` or `npm run test-webview` after compiling.
53+
3854
### Using Proposed API
3955

4056
The vscode extension will occasionally need to use [proposed API](https://code.visualstudio.com/api/advanced-topics/using-proposed-api) that haven't been promoted to stable yet. To enable an API proposal, add it to the `enabledApiProposals` section in `package.json`, then run `cd src/vscode-dts && npx @vscode/dts dev` to install the type definitions for the API you want to enable.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
"pretest": "npm run compile",
5454
"test": "npm run test-webview && npm run test-extension",
5555
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
56-
"test-webview": "mocha -r ts-node/register --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx",
57-
"ai-accuracy-tests": "env TS_NODE_FILES=true mocha -r ts-node/register --file ./src/test/ai-accuracy-tests/test-setup.ts ./src/test/ai-accuracy-tests/ai-accuracy-tests.ts",
56+
"test-webview": "mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx",
57+
"ai-accuracy-tests": "env TS_NODE_FILES=true mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/ai-accuracy-tests/test-setup.ts ./src/test/ai-accuracy-tests/ai-accuracy-tests.ts",
5858
"analyze-bundle": "webpack --mode production --analyze",
5959
"vscode:prepublish": "npm run clean && npm run compile:constants && npm run compile:resources && webpack --mode production",
6060
"check": "npm run lint && npm run depcheck",

src/test/suite/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export async function run(): Promise<void> {
1919
reporterOptions,
2020
ui: 'tdd',
2121
color: true,
22+
grep: process.env.MOCHA_GREP,
2223
});
2324

2425
const testsRoot = path.join(__dirname, '..');

0 commit comments

Comments
 (0)