Skip to content

Commit 16eac45

Browse files
committed
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 06a1fd9 commit 16eac45

22 files changed

Lines changed: 501 additions & 141 deletions

.github/workflows/main.yml

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +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+
working-directory: extensions/ql-vscode
3233
run: |
33-
cd extensions/ql-vscode
3434
npm run build
3535
shell: bash
3636

@@ -61,24 +61,23 @@ jobs:
6161

6262
- uses: actions/setup-node@v1
6363
with:
64-
node-version: '10.18.1'
64+
node-version: '14.14.0'
6565

66-
# We have to build the dependencies in `lib` before running any tests.
6766
- name: Install dependencies
67+
working-directory: extensions/ql-vscode
6868
run: |
69-
cd extensions/ql-vscode
7069
npm install
7170
shell: bash
7271

7372
- name: Build
73+
working-directory: extensions/ql-vscode
7474
run: |
75-
cd extensions/ql-vscode
7675
npm run build
7776
shell: bash
7877

7978
- name: Lint
79+
working-directory: extensions/ql-vscode
8080
run: |
81-
cd extensions/ql-vscode
8281
npm run lint
8382
8483
- name: Install CodeQL
@@ -91,27 +90,71 @@ jobs:
9190
shell: bash
9291

9392
- name: Run unit tests (Linux)
93+
working-directory: extensions/ql-vscode
9494
if: matrix.os == 'ubuntu-latest'
9595
run: |
96-
cd extensions/ql-vscode
9796
CODEQL_PATH=$GITHUB_WORKSPACE/codeql-home/codeql/codeql npm run test
9897
9998
- name: Run unit tests (Windows)
10099
if: matrix.os == 'windows-latest'
100+
working-directory: extensions/ql-vscode
101101
run: |
102-
cd extensions/ql-vscode
103102
$env:CODEQL_PATH=$(Join-Path $env:GITHUB_WORKSPACE -ChildPath 'codeql-home/codeql/codeql.exe')
104103
npm run test
105104
106105
- name: Run integration tests (Linux)
107106
if: matrix.os == 'ubuntu-latest'
107+
working-directory: extensions/ql-vscode
108108
run: |
109-
cd extensions/ql-vscode
110109
sudo apt-get install xvfb
111110
/usr/bin/xvfb-run npm run integration
112111
113112
- name: Run integration tests (Windows)
114113
if: matrix.os == 'windows-latest'
114+
working-directory: extensions/ql-vscode
115115
run: |
116-
cd extensions/ql-vscode
117116
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
@@ -708,7 +708,8 @@
708708
"watch:extension": "tsc --watch",
709709
"test": "mocha --exit -r ts-node/register test/pure-tests/**/*.ts",
710710
"preintegration": "rm -rf ./out/vscode-tests && gulp",
711-
"integration": "node ./out/vscode-tests/run-integration-tests.js",
711+
"integration": "node ./out/vscode-tests/run-integration-tests.js no-workspace,minimal-workspace",
712+
"cli-integration": "npm run preintegration && node ./out/vscode-tests/run-integration-tests.js cli-integration",
712713
"update-vscode": "node ./node_modules/vscode/bin/install",
713714
"format": "tsfmt -r && eslint src test --ext .ts,.tsx --fix",
714715
"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
@@ -52,7 +52,8 @@ const QUERY_HISTORY_FORMAT_SETTING = new Setting('format', QUERY_HISTORY_SETTING
5252
const DISTRIBUTION_CHANGE_SETTINGS = [CUSTOM_CODEQL_PATH_SETTING, INCLUDE_PRERELEASE_SETTING, PERSONAL_ACCESS_TOKEN_SETTING];
5353

5454
export interface DistributionConfig {
55-
customCodeQlPath?: string;
55+
readonly customCodeQlPath?: string;
56+
updateCustomCodeQlPath: (newPath: string | undefined) => Promise<void>;
5657
includePrerelease: boolean;
5758
personalAccessToken?: string;
5859
ownerName?: string;
@@ -149,6 +150,10 @@ export class DistributionConfigListener extends ConfigListener implements Distri
149150
return PERSONAL_ACCESS_TOKEN_SETTING.getValue() || undefined;
150151
}
151152

153+
public async updateCustomCodeQlPath(newPath: string | undefined) {
154+
await CUSTOM_CODEQL_PATH_SETTING.updateValue(newPath, ConfigurationTarget.Global);
155+
}
156+
152157
protected handleDidChangeConfiguration(e: ConfigurationChangeEvent): void {
153158
this.handleDidChangeConfigurationForRelevantSettings(DISTRIBUTION_CHANGE_SETTINGS, e);
154159
}

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)