Skip to content

Commit b20aeb3

Browse files
authored
Merge pull request #2058 from github/koesie10/improve-test-setup
Improve test setup
2 parents 851a42f + 930def8 commit b20aeb3

18 files changed

+132
-56
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ jobs:
132132
- name: Run unit tests
133133
working-directory: extensions/ql-vscode
134134
run: |
135-
npm run test
135+
npm run test:unit
136+
137+
- name: Run view tests
138+
working-directory: extensions/ql-vscode
139+
run: |
140+
npm run test:view
136141
137142
test:
138143
name: Test
@@ -173,15 +178,15 @@ jobs:
173178
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
174179
run: |
175180
unset DBUS_SESSION_BUS_ADDRESS
176-
/usr/bin/xvfb-run npm run integration
181+
/usr/bin/xvfb-run npm run test:vscode-integration
177182
178183
- name: Run integration tests (Windows)
179184
if: matrix.os == 'windows-latest'
180185
working-directory: extensions/ql-vscode
181186
env:
182187
VSCODE_CODEQL_GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
183188
run: |
184-
npm run integration
189+
npm run test:vscode-integration
185190
186191
set-matrix:
187192
name: Set Matrix for cli-test
@@ -254,10 +259,10 @@ jobs:
254259
if: matrix.os == 'ubuntu-latest'
255260
run: |
256261
unset DBUS_SESSION_BUS_ADDRESS
257-
/usr/bin/xvfb-run npm run cli-integration
262+
/usr/bin/xvfb-run npm run test:cli-integration
258263
259264
- name: Run CLI tests (Windows)
260265
working-directory: extensions/ql-vscode
261266
if: matrix.os == 'windows-latest'
262267
run: |
263-
npm run cli-integration
268+
npm run test:cli-integration

CONTRIBUTING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ We have several types of tests:
9898
* Unit tests: these live in the `tests/unit-tests/` directory
9999
* View tests: these live in `src/view/variant-analysis/__tests__/`
100100
* VSCode integration tests:
101-
* `test/vscode-tests/no-workspace` tests: These are intended to cover functionality that is meant to work before you even have a workspace open.
101+
* `test/vscode-tests/activated-extension` tests: These are intended to cover functionality that require the full extension to be activated but don't require the CLI. This suite is not run against multiple versions of the CLI in CI.
102+
* `test/vscode-tests/no-workspace` tests: These are intended to cover functionality around not having a workspace. The extension is not activated in these tests.
102103
* `test/vscode-tests/minimal-workspace` tests: These are intended to cover functionality that need a workspace but don't require the full extension to be activated.
103104
* CLI integration tests: these live in `test/vscode-tests/cli-integration`
104-
* These tests are intendended to be cover functionality that is related to the integration between the CodeQL CLI and the extension.
105+
* These tests are intended to cover functionality that is related to the integration between the CodeQL CLI and the extension. These tests are run against each supported versions of the CLI in CI.
105106

106107
The CLI integration tests require an instance of the CodeQL CLI to run so they will require some extra setup steps. When adding new tests to our test suite, please be mindful of whether they need to be in the cli-integration folder. If the tests don't depend on the CLI, they are better suited to being a VSCode integration test.
107108

@@ -119,7 +120,7 @@ Then, from the `extensions/ql-vscode` directory, use the appropriate command to
119120

120121
* Unit tests: `npm run test:unit`
121122
* View Tests: `npm test:view`
122-
* VSCode integration tests: `npm run integration`
123+
* VSCode integration tests: `npm run test:vscode-integration`
123124

124125
###### CLI integration tests
125126

@@ -130,7 +131,7 @@ The CLI integration tests require the CodeQL standard libraries in order to run
130131
2. Run your test command:
131132

132133
```shell
133-
cd extensions/ql-vscode && npm run cli-integration
134+
cd extensions/ql-vscode && npm run test:cli-integration
134135
```
135136

136137
##### 2. From VSCode
@@ -161,13 +162,13 @@ The easiest way to run a single test is to change the `it` of the test to `it.on
161162
to only run tests for this specific file. For example, to run the test `test/vscode-tests/cli-integration/run-queries.test.ts`:
162163

163164
```shell
164-
npm run cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts
165+
npm run test:cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts
165166
```
166167

167168
You can also use the `--testNamePattern` option to run a specific test within a file. For example, to run the test `test/vscode-tests/cli-integration/run-queries.test.ts`:
168169

169170
```shell
170-
npm run cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts --testNamePattern "should create a QueryEvaluationInfo"
171+
npm run test:cli-integration -- --runTestsByPath test/vscode-tests/cli-integration/run-queries.test.ts --testNamePattern "should create a QueryEvaluationInfo"
171172
```
172173

173174
##### 2. From VSCode

extensions/ql-vscode/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = {
88
projects: [
99
"<rootDir>/src/view",
1010
"<rootDir>/test/unit-tests",
11+
"<rootDir>/test/vscode-tests/activated-extension",
1112
"<rootDir>/test/vscode-tests/cli-integration",
1213
"<rootDir>/test/vscode-tests/no-workspace",
1314
"<rootDir>/test/vscode-tests/minimal-workspace",

extensions/ql-vscode/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,13 +1326,14 @@
13261326
"scripts": {
13271327
"build": "gulp",
13281328
"watch": "gulp watch",
1329-
"test": "npm-run-all -p test:*",
1329+
"test": "npm-run-all test:*",
13301330
"test:unit": "cross-env TZ=UTC LANG=en-US jest --projects test/unit-tests",
13311331
"test:view": "jest --projects src/view",
1332-
"integration": "npm-run-all integration:*",
1333-
"integration:no-workspace": "jest --projects test/vscode-tests/no-workspace",
1334-
"integration:minimal-workspace": "jest --projects test/vscode-tests/minimal-workspace",
1335-
"cli-integration": "jest --projects test/vscode-tests/cli-integration",
1332+
"test:vscode-integration": "npm-run-all test:vscode-integration:*",
1333+
"test:vscode-integration:activated-extension": "jest --projects test/vscode-tests/activated-extension",
1334+
"test:vscode-integration:no-workspace": "jest --projects test/vscode-tests/no-workspace",
1335+
"test:vscode-integration:minimal-workspace": "jest --projects test/vscode-tests/minimal-workspace",
1336+
"test:cli-integration": "jest --projects test/vscode-tests/cli-integration",
13361337
"update-vscode": "node ./node_modules/vscode/bin/install",
13371338
"format": "prettier --write **/*.{ts,tsx} && eslint . --ext .ts,.tsx --fix",
13381339
"lint": "eslint . --ext .js,.ts,.tsx --max-warnings=0",

extensions/ql-vscode/test/vscode-tests/cli-integration/databases/db-panel.test.ts renamed to extensions/ql-vscode/test/vscode-tests/activated-extension/databases/db-panel.test.ts

File renamed without changes.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const path = require("path");
2+
3+
const {
4+
config: baseConfig,
5+
rootDir,
6+
} = require("../jest-runner-vscode.config.base");
7+
8+
/** @type import("jest-runner-vscode").RunnerOptions */
9+
const config = {
10+
...baseConfig,
11+
launchArgs: [
12+
...(baseConfig.launchArgs ?? []),
13+
// explicitly disable extensions that are known to interfere with the CLI integration tests
14+
"--disable-extension",
15+
"eamodio.gitlens",
16+
"--disable-extension",
17+
"github.codespaces",
18+
"--disable-extension",
19+
"github.copilot",
20+
path.resolve(rootDir, "test/data"),
21+
],
22+
extensionTestsEnv: {
23+
...baseConfig.extensionTestsEnv,
24+
INTEGRATION_TEST_MODE: "true",
25+
},
26+
retries: 3,
27+
};
28+
29+
module.exports = config;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Config } from "jest";
2+
3+
import baseConfig from "../jest.config.base";
4+
5+
const config: Config = {
6+
...baseConfig,
7+
runner: "<rootDir>/../jest-runner-installed-extensions.ts",
8+
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
9+
};
10+
11+
export default config;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {
2+
beforeAllAction,
3+
beforeEachAction,
4+
} from "../jest.activated-extension.setup";
5+
6+
beforeAll(async () => {
7+
await beforeAllAction();
8+
});
9+
10+
beforeEach(async () => {
11+
await beforeEachAction();
12+
});

extensions/ql-vscode/test/vscode-tests/cli-integration/databaseFetcher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
importArchiveDatabase,
99
promptImportInternetDatabase,
1010
} from "../../../src/databaseFetcher";
11-
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "./global.helper";
11+
import { cleanDatabases, dbLoc, DB_URL, storagePath } from "../global.helper";
1212

1313
jest.setTimeout(60_000);
1414

extensions/ql-vscode/test/vscode-tests/cli-integration/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import baseConfig from "../jest.config.base";
44

55
const config: Config = {
66
...baseConfig,
7-
runner: "<rootDir>/jest-runner-cli-integration.ts",
7+
runner: "<rootDir>/../jest-runner-installed-extensions.ts",
88
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
99
};
1010

0 commit comments

Comments
 (0)