From eb2c7dca166c978e95ef47b935f88a25b3623284 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 1 Nov 2024 13:37:56 +0100 Subject: [PATCH 1/4] Add test filtering --- .vscode/launch.json | 10 ++++++++++ CONTRIBUTING.md | 16 ++++++++++++++++ package.json | 4 ++-- src/test/suite/index.ts | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) 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..5b2af7c22 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 also can 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`. + ### 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..09198e5d5 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, '..'); From bcd260bbae9fe8f607daa93832c94020179884f0 Mon Sep 17 00:00:00 2001 From: Gagik Amaryan Date: Fri, 1 Nov 2024 13:42:43 +0100 Subject: [PATCH 2/4] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5b2af7c22..114b53f98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -49,7 +49,7 @@ You can run tests using command line along with an optional `MOCHA_GREP` environ 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`. +It may be quicker to be more specific and use `npm run test-extension` or `npm run test-webview` after compiling. ### Using Proposed API From a9beef11920316e7e44e521c0553a2b3104b26f3 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 1 Nov 2024 13:45:09 +0100 Subject: [PATCH 3/4] Escape the environment variable --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 09198e5d5..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 --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", + "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", From 33c995e3ad9ea6870d32c8cb75f8df576442929e Mon Sep 17 00:00:00 2001 From: Gagik Amaryan Date: Fri, 1 Nov 2024 14:18:53 +0100 Subject: [PATCH 4/4] Fix wording --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 114b53f98..87aa3e686 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,7 +39,7 @@ npm run watch #### Using the VSCode debugger -You can launch a debugging task for tests inside VSCode with the **"Run Tests"** task. There you also can specify an optional test filter. +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