Skip to content

Commit

Permalink
chore: add test filtering during development (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik authored Nov 5, 2024
1 parent 3141f33 commit 0f8cfe0
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite"
],
"env": {
"MOCHA_GREP": "${input:mochaGrep}"
},
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "npm: compile:extension",
}
],
"inputs": [
{
"id": "mochaGrep",
"type": "promptString",
"description": "Enter an optional grep filter to run specific tests. Leave blank for all.",
}
],
"compounds": [
{
"name": "Extension + Server Inspector",
Expand Down
16 changes: 16 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ npm run watch

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.

### Running Tests

#### Using the VSCode debugger

You can launch a debugging task for tests inside VSCode with the **"Run Tests"** task. There you can also specify an optional test filter.

#### Using command line

You can run tests using command line along with an optional `MOCHA_GREP` environment variable to apply a grep filter on tests to run.

```shell
MOCHA_GREP="Participant .* prompt builders" npm test
```

It may be quicker to be more specific and use `npm run test-extension` or `npm run test-webview` after compiling.

### Using Proposed API

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.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
"pretest": "npm run compile",
"test": "npm run test-webview && npm run test-extension",
"test-extension": "cross-env NODE_OPTIONS=--no-force-async-hooks-checks xvfb-maybe node ./out/test/runTest.js",
"test-webview": "mocha -r ts-node/register --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx",
"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",
"test-webview": "mocha -r ts-node/register --grep=\"${MOCHA_GREP}\" --file ./src/test/setup-webview.ts src/test/suite/views/webview-app/**/*.test.tsx",
"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",
"analyze-bundle": "webpack --mode production --analyze",
"vscode:prepublish": "npm run clean && npm run compile:constants && npm run compile:resources && webpack --mode production",
"check": "npm run lint && npm run depcheck",
Expand Down
1 change: 1 addition & 0 deletions src/test/suite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function run(): Promise<void> {
reporterOptions,
ui: 'tdd',
color: true,
grep: process.env.MOCHA_GREP,
});

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

0 comments on commit 0f8cfe0

Please sign in to comment.