diff --git a/.vscode/launch.json b/.vscode/launch.json index 9d596e5fd..533cbba63 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0e3168a2c..87aa3e686 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/package.json b/package.json index 2a35a4935..a8a10c25e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/test/suite/index.ts b/src/test/suite/index.ts index 9833e8055..b9c7f2f42 100644 --- a/src/test/suite/index.ts +++ b/src/test/suite/index.ts @@ -19,6 +19,7 @@ export async function run(): Promise { reporterOptions, ui: 'tdd', color: true, + grep: process.env.MOCHA_GREP, }); const testsRoot = path.join(__dirname, '..');