Skip to content

Commit 6a4bcb8

Browse files
aeisenbergaofaof0907
authored andcommitted
Add integration tests with the CLI
This commit adds integration tests that run commands using the CLI. This change introduces a number of enhancements in order to get there. 1. Augments the index-template.ts file so that it downloads an appropriate cli version if requested. 2. Adds the ensureCli.ts that performs the download if a a suitable version is not already installed. See the comments in the file for how this is done. 3. Changes how run-integration-tests is done so that the directories run are specified through a cli argument. 4. Updates the main.yml workflow so that it also runs the cli-integration tests. 5. Takes advantage of the return value of the call to `activate` on the extension. This allows the integration tests to have access to internal variables of the extension like the context, cli, and query server. 6. And of course, adds a handful of simple tests that ensure we have a cli installed of the correct version.
1 parent 7bea2bf commit 6a4bcb8

22 files changed

Lines changed: 689 additions & 193 deletions

.github/workflows/main.yml

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ jobs:
2020

2121
- uses: actions/setup-node@v1
2222
with:
23-
node-version: '10.18.1'
23+
node-version: '14.14.0'
2424

2525
- name: Install dependencies
26+
working-directory: extensions/ql-vscode
2627
run: |
27-
cd extensions/ql-vscode
2828
npm install
2929
shell: bash
3030

3131
- name: Build
32-
env:
33-
APP_INSIGHTS_KEY: '${{ secrets.APP_INSIGHTS_KEY }}'
32+
working-directory: extensions/ql-vscode
3433
run: |
35-
cd extensions/ql-vscode
3634
npm run build
3735
shell: bash
3836

@@ -63,26 +61,23 @@ jobs:
6361

6462
- uses: actions/setup-node@v1
6563
with:
66-
node-version: '10.18.1'
64+
node-version: '14.14.0'
6765

68-
# We have to build the dependencies in `lib` before running any tests.
6966
- name: Install dependencies
67+
working-directory: extensions/ql-vscode
7068
run: |
71-
cd extensions/ql-vscode
7269
npm install
7370
shell: bash
7471

7572
- name: Build
76-
env:
77-
APP_INSIGHTS_KEY: '${{ secrets.APP_INSIGHTS_KEY }}'
73+
working-directory: extensions/ql-vscode
7874
run: |
79-
cd extensions/ql-vscode
8075
npm run build
8176
shell: bash
8277

8378
- name: Lint
79+
working-directory: extensions/ql-vscode
8480
run: |
85-
cd extensions/ql-vscode
8681
npm run lint
8782
8883
- name: Install CodeQL
@@ -95,27 +90,71 @@ jobs:
9590
shell: bash
9691

9792
- name: Run unit tests (Linux)
93+
working-directory: extensions/ql-vscode
9894
if: matrix.os == 'ubuntu-latest'
9995
run: |
100-
cd extensions/ql-vscode
10196
CODEQL_PATH=$GITHUB_WORKSPACE/codeql-home/codeql/codeql npm run test
10297
10398
- name: Run unit tests (Windows)
10499
if: matrix.os == 'windows-latest'
100+
working-directory: extensions/ql-vscode
105101
run: |
106-
cd extensions/ql-vscode
107102
$env:CODEQL_PATH=$(Join-Path $env:GITHUB_WORKSPACE -ChildPath 'codeql-home/codeql/codeql.exe')
108103
npm run test
109104
110105
- name: Run integration tests (Linux)
111106
if: matrix.os == 'ubuntu-latest'
107+
working-directory: extensions/ql-vscode
112108
run: |
113-
cd extensions/ql-vscode
114109
sudo apt-get install xvfb
115110
/usr/bin/xvfb-run npm run integration
116111
117112
- name: Run integration tests (Windows)
118113
if: matrix.os == 'windows-latest'
114+
working-directory: extensions/ql-vscode
119115
run: |
120-
cd extensions/ql-vscode
121116
npm run integration
117+
118+
cli-test:
119+
name: CLI Test
120+
runs-on: ${{ matrix.os }}
121+
strategy:
122+
matrix:
123+
os: [ubuntu-latest, windows-latest]
124+
version: ['v2.3.1', 'v2.3.0']
125+
env:
126+
CLI_VERSION: ${{ matrix.version }}
127+
128+
steps:
129+
- name: Checkout
130+
uses: actions/checkout@v2
131+
with:
132+
fetch-depth: 1
133+
134+
- uses: actions/setup-node@v1
135+
with:
136+
node-version: '14.14.0'
137+
138+
- name: Install dependencies
139+
working-directory: extensions/ql-vscode
140+
run: |
141+
npm install
142+
shell: bash
143+
144+
- name: Build
145+
working-directory: extensions/ql-vscode
146+
run: |
147+
npm run build
148+
shell: bash
149+
150+
- name: Run CLI tests (Linux)
151+
working-directory: extensions/ql-vscode
152+
if: matrix.os == 'ubuntu-latest'
153+
run: |
154+
/usr/bin/xvfb-run npm run cli-integration
155+
156+
- name: Run CLI tests (Windows)
157+
working-directory: extensions/ql-vscode
158+
if: matrix.os == 'windows-latest'
159+
run: |
160+
npm run cli-integration

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Generated files
55
/dist/
66
out/
7+
build/
78
server/
89
node_modules/
910
gen/

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@
7777
"outFiles": [
7878
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
7979
],
80+
},
81+
{
82+
"name": "Launch Integration Tests - With CLI",
83+
"type": "extensionHost",
84+
"request": "launch",
85+
"runtimeExecutable": "${execPath}",
86+
"args": [
87+
"--extensionDevelopmentPath=${workspaceRoot}/extensions/ql-vscode",
88+
"--extensionTestsPath=${workspaceRoot}/extensions/ql-vscode/out/vscode-tests/cli-integration/index",
89+
"${workspaceRoot}/extensions/ql-vscode/test/data"
90+
],
91+
"stopOnEntry": false,
92+
"sourceMaps": true,
93+
"outFiles": [
94+
"${workspaceRoot}/extensions/ql-vscode/out/**/*.js",
95+
],
8096
}
8197
]
8298
}

extensions/ql-vscode/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,8 @@
720720
"watch:extension": "tsc --watch",
721721
"test": "mocha --exit -r ts-node/register test/pure-tests/**/*.ts",
722722
"preintegration": "rm -rf ./out/vscode-tests && gulp",
723-
"integration": "node ./out/vscode-tests/run-integration-tests.js",
723+
"integration": "node ./out/vscode-tests/run-integration-tests.js no-workspace,minimal-workspace",
724+
"cli-integration": "npm run preintegration && node ./out/vscode-tests/run-integration-tests.js cli-integration",
724725
"update-vscode": "node ./node_modules/vscode/bin/install",
725726
"format": "tsfmt -r && eslint src test --ext .ts,.tsx --fix",
726727
"lint": "eslint src test --ext .ts,.tsx --max-warnings=0",

extensions/ql-vscode/src/astViewer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AstViewerDataProvider extends DisposableObject implements TreeDataProvider
4040
public db: DatabaseItem | undefined;
4141

4242
private _onDidChangeTreeData =
43-
new EventEmitter<AstItem | undefined>();
43+
this.push(new EventEmitter<AstItem | undefined>());
4444
readonly onDidChangeTreeData: Event<AstItem | undefined> =
4545
this._onDidChangeTreeData.event;
4646

extensions/ql-vscode/src/config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ const QUERY_HISTORY_FORMAT_SETTING = new Setting('format', QUERY_HISTORY_SETTING
6060
const DISTRIBUTION_CHANGE_SETTINGS = [CUSTOM_CODEQL_PATH_SETTING, INCLUDE_PRERELEASE_SETTING, PERSONAL_ACCESS_TOKEN_SETTING];
6161

6262
export interface DistributionConfig {
63-
customCodeQlPath?: string;
63+
readonly customCodeQlPath?: string;
64+
updateCustomCodeQlPath: (newPath: string | undefined) => Promise<void>;
6465
includePrerelease: boolean;
6566
personalAccessToken?: string;
6667
ownerName?: string;
@@ -157,6 +158,10 @@ export class DistributionConfigListener extends ConfigListener implements Distri
157158
return PERSONAL_ACCESS_TOKEN_SETTING.getValue() || undefined;
158159
}
159160

161+
public async updateCustomCodeQlPath(newPath: string | undefined) {
162+
await CUSTOM_CODEQL_PATH_SETTING.updateValue(newPath, ConfigurationTarget.Global);
163+
}
164+
160165
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
161166
this.handleDidChangeConfigurationForRelevantSettings(DISTRIBUTION_CHANGE_SETTINGS, e);
162167
}

extensions/ql-vscode/src/databases-ui.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class DatabaseTreeDataProvider extends DisposableObject
8181
implements TreeDataProvider<DatabaseItem> {
8282
private _sortOrder = SortOrder.NameAsc;
8383

84-
private readonly _onDidChangeTreeData = new EventEmitter<DatabaseItem | undefined>();
84+
private readonly _onDidChangeTreeData = this.push(new EventEmitter<DatabaseItem | undefined>());
8585
private currentDatabaseItem: DatabaseItem | undefined;
8686

8787
constructor(

0 commit comments

Comments
 (0)