Skip to content

Commit c90659f

Browse files
committed
First attempt at tests
1 parent 30b7fe7 commit c90659f

2 files changed

Lines changed: 110 additions & 2 deletions

File tree

extensions/ql-vscode/src/packaging.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function handleDownloadPacks(
3737
maxStep: 2,
3838
});
3939
let packsToDownload: string[] = [];
40-
const queryPackOption = 'Download core query packs';
40+
const queryPackOption = 'Download all core query packs';
4141
const customPackOption = 'Download custom specified pack';
4242
const quickpick = await window.showQuickPick(
4343
[queryPackOption, customPackOption],
@@ -57,7 +57,7 @@ export async function handleDownloadPacks(
5757
throw new UserCancellationException('No pack specified.');
5858
}
5959
}
60-
if (packsToDownload && packsToDownload.length > 0) {
60+
if (packsToDownload?.length > 0) {
6161
progress({
6262
message: 'Downloading packs. This may take a few minutes.',
6363
step: 2,
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import * as sinon from 'sinon';
2+
import { extensions, window } from 'vscode';
3+
import 'mocha';
4+
import * as path from 'path';
5+
6+
import * as pq from 'proxyquire';
7+
8+
import { CodeQLCliServer } from '../../cli';
9+
import { CodeQLExtensionInterface } from '../../extension';
10+
import { expect } from 'chai';
11+
12+
const proxyquire = pq.noPreserveCache();
13+
14+
describe('Packaging commands', function() {
15+
let sandbox: sinon.SinonSandbox;
16+
17+
// up to 3 minutes per test
18+
this.timeout(3 * 60 * 1000);
19+
20+
let cli: CodeQLCliServer;
21+
let progress: sinon.SinonSpy;
22+
let quickPickSpy: sinon.SinonStub;
23+
let inputBoxSpy: sinon.SinonStub;
24+
let showAndLogErrorMessageSpy: sinon.SinonStub;
25+
let showAndLogInformationMessageSpy: sinon.SinonStub;
26+
let mod: any;
27+
28+
beforeEach(async function() {
29+
sandbox = sinon.createSandbox();
30+
31+
const extension = await extensions
32+
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
33+
'GitHub.vscode-codeql'
34+
)!
35+
.activate();
36+
if ('cliServer' in extension) {
37+
cli = extension.cliServer;
38+
} else {
39+
throw new Error(
40+
'Extension not initialized. Make sure cli is downloaded and installed properly.'
41+
);
42+
}
43+
44+
progress = sandbox.spy();
45+
quickPickSpy = sandbox.stub(window, 'showQuickPick');
46+
inputBoxSpy = sandbox.stub(window, 'showInputBox');
47+
showAndLogErrorMessageSpy = sandbox.stub();
48+
showAndLogInformationMessageSpy = sandbox.stub();
49+
mod = proxyquire('../../packaging', {
50+
'../helpers': {
51+
showAndLogErrorMessage: showAndLogErrorMessageSpy,
52+
showAndLogInformationMessage: showAndLogInformationMessageSpy,
53+
},
54+
});
55+
});
56+
57+
afterEach(() => {
58+
sandbox.restore();
59+
});
60+
61+
it('should download all core query packs', async () => {
62+
quickPickSpy.resolves('Download all core query packs');
63+
64+
await mod.handleDownloadPacks(cli, progress);
65+
expect(showAndLogInformationMessageSpy.firstCall.args[0]).to.contain(
66+
'Finished downloading packs.'
67+
);
68+
});
69+
70+
it('should download valid user-specified pack', async () => {
71+
quickPickSpy.resolves('Download custom specified pack');
72+
inputBoxSpy.resolves('codeql/csharp-solorigate-queries');
73+
74+
await mod.handleDownloadPacks(cli, progress);
75+
expect(showAndLogInformationMessageSpy.firstCall.args[0]).to.contain(
76+
'Finished downloading packs.'
77+
);
78+
});
79+
80+
it('should show error for invalid user-specified pack', async () => {
81+
quickPickSpy.resolves('Download custom specified pack');
82+
inputBoxSpy.resolves('foo/not-a-real-pack@0.0.1');
83+
84+
await mod.handleDownloadPacks(cli, progress);
85+
86+
expect(showAndLogErrorMessageSpy.firstCall.args[0]).to.contain(
87+
'Unable to download all packs.'
88+
);
89+
});
90+
91+
it('should install selected workspace packs', async () => {
92+
const rootDir = path.join(__dirname, '../../../src/vscode-tests/cli-integration/data');
93+
quickPickSpy.resolves(
94+
[
95+
{
96+
label: 'integration-test-queries-javascript',
97+
packRootDir: [rootDir],
98+
},
99+
]
100+
);
101+
102+
await mod.handleInstallPacks(cli, progress);
103+
104+
expect(showAndLogInformationMessageSpy.firstCall.args[0]).to.contain(
105+
'Finished installing packs.'
106+
);
107+
});
108+
});

0 commit comments

Comments
 (0)