Skip to content

Commit 595b14c

Browse files
authored
Merge pull request #1797 from github/jest-migration/docs
Add documentation for running a single test
2 parents 858a326 + 24a61d3 commit 595b14c

4 files changed

Lines changed: 39 additions & 1 deletion

File tree

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"amodio.tsl-problem-matcher",
77
"dbaeumer.vscode-eslint",
88
"esbenp.prettier-vscode",
9+
"firsttris.vscode-jest-runner",
910
"Orta.vscode-jest",
1011
],
1112
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@
4242
"LANG": "en-US",
4343
"TZ": "UTC"
4444
},
45+
// Uncomment to debug integration tests
46+
// "jestrunner.debugOptions": {
47+
// "attachSimplePort": 9223,
48+
// "env": {
49+
// "VSCODE_WAIT_FOR_DEBUGGER": "true",
50+
// }
51+
// },
4552
"[typescript]": {
4653
"editor.defaultFormatter": "esbenp.prettier-vscode",
4754
"editor.formatOnSave": true,

CONTRIBUTING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,32 @@ The CLI integration tests require the CodeQL standard libraries in order to run
150150

151151
3. Run the VSCode task from the "Run and Debug" view called _Launch Integration Tests - With CLI_.
152152

153+
#### Running a single test
154+
155+
##### 1. From the terminal
156+
157+
The easiest way to run a single test is to change the `it` of the test to `it.only` and then run the test command with some additional options
158+
to only run tests for this specific file. For example, to run the test `src/vscode-tests/cli-integration/run-queries.test.ts`:
159+
160+
```shell
161+
npm run cli-integration -- --runTestsByPath src/vscode-tests/cli-integration/run-queries.test.ts
162+
```
163+
164+
You can also use the `--testNamePattern` option to run a specific test within a file. For example, to run the test `src/vscode-tests/cli-integration/run-queries.test.ts`:
165+
166+
```shell
167+
npm run cli-integration -- --runTestsByPath src/vscode-tests/cli-integration/run-queries.test.ts --testNamePattern "should create a QueryEvaluationInfo"
168+
```
169+
170+
##### 2. From VSCode
171+
172+
Alternatively, you can run a single test inside VSCode. To do so, install the [Jest Runner](https://marketplace.visualstudio.com/items?itemName=firsttris.vscode-jest-runner) extension. Then,
173+
you will have quicklinks to run a single test from within test files. To run a single unit or integration test, click the "Run" button. Debugging a single test is currently only supported
174+
for unit tests by default. To debug integration tests, open the `.vscode/settings.json` file and uncomment the `jestrunner.debugOptions` lines. This will allow you to debug integration tests.
175+
Please make sure to revert this change before committing; with this setting enabled, it is not possible to debug unit tests.
176+
177+
Without the Jest Runner extension, you can also use the "Launch Selected Unit Test (vscode-codeql)" launch configuration to run a single unit test.
178+
153179
#### Using a mock GitHub API server
154180

155181
Multi-Repo Variant Analyses (MRVA) rely on the GitHub API. In order to make development and testing easy, we have functionality that allows us to intercept requests to the GitHub API and provide mock responses.

extensions/ql-vscode/src/vscode-tests/jest-runner-vscode.config.base.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ const config = {
1717
};
1818

1919
if (process.env.VSCODE_INSPECTOR_OPTIONS) {
20-
config.launchArgs?.push("--inspect-extensions", "9223");
20+
if (process.env.VSCODE_WAIT_FOR_DEBUGGER === "true") {
21+
config.launchArgs?.push("--inspect-brk-extensions", "9223");
22+
} else {
23+
config.launchArgs?.push("--inspect-extensions", "9223");
24+
}
2125
}
2226

2327
module.exports = {

0 commit comments

Comments
 (0)