forked from github/vscode-codeql
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackaging.test.ts
More file actions
109 lines (90 loc) · 3.23 KB
/
packaging.test.ts
File metadata and controls
109 lines (90 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import * as sinon from 'sinon';
import { extensions, window } from 'vscode';
import 'mocha';
import * as path from 'path';
import * as pq from 'proxyquire';
import { CodeQLCliServer } from '../../cli';
import { CodeQLExtensionInterface } from '../../extension';
import { expect } from 'chai';
const proxyquire = pq.noPreserveCache();
describe('Packaging commands', function() {
let sandbox: sinon.SinonSandbox;
// up to 3 minutes per test
this.timeout(3 * 60 * 1000);
let cli: CodeQLCliServer;
let progress: sinon.SinonSpy;
let quickPickSpy: sinon.SinonStub;
let inputBoxSpy: sinon.SinonStub;
let showAndLogErrorMessageSpy: sinon.SinonStub;
let showAndLogInformationMessageSpy: sinon.SinonStub;
let mod: any;
beforeEach(async function() {
sandbox = sinon.createSandbox();
const extension = await extensions
.getExtension<CodeQLExtensionInterface | Record<string, never>>(
'GitHub.vscode-codeql'
)!
.activate();
if ('cliServer' in extension) {
cli = extension.cliServer;
} else {
throw new Error(
'Extension not initialized. Make sure cli is downloaded and installed properly.'
);
}
progress = sandbox.spy();
quickPickSpy = sandbox.stub(window, 'showQuickPick');
inputBoxSpy = sandbox.stub(window, 'showInputBox');
showAndLogErrorMessageSpy = sandbox.stub();
showAndLogInformationMessageSpy = sandbox.stub();
mod = proxyquire('../../packaging', {
'./helpers': {
showAndLogErrorMessage: showAndLogErrorMessageSpy,
showAndLogInformationMessage: showAndLogInformationMessageSpy,
},
});
});
afterEach(() => {
sandbox.restore();
});
it('should download all core query packs', async () => {
quickPickSpy.resolves('Download all core query packs');
await mod.handleDownloadPacks(cli, progress);
expect(showAndLogInformationMessageSpy.firstCall.args[0]).to.contain(
'Finished downloading packs.'
);
});
it('should download valid user-specified pack', async () => {
quickPickSpy.resolves('Download custom specified pack');
inputBoxSpy.resolves('codeql/csharp-solorigate-queries');
await mod.handleDownloadPacks(cli, progress);
expect(showAndLogInformationMessageSpy.firstCall.args[0]).to.contain(
'Finished downloading packs.'
);
});
it('should show error for invalid user-specified pack', async () => {
quickPickSpy.resolves('Download custom specified pack');
inputBoxSpy.resolves('foo/not-a-real-pack@0.0.1');
await mod.handleDownloadPacks(cli, progress);
expect(showAndLogErrorMessageSpy.firstCall.args[0]).to.contain(
'Unable to download all packs.'
);
});
it('should attempt to install selected workspace packs', async () => {
const rootDir = path.join(__dirname, '../../../src/vscode-tests/cli-integration/data');
quickPickSpy.resolves([
{
label: 'integration-test-queries-javascript',
packRootDir: [rootDir],
},
]);
try {
await mod.handleInstallPacks(cli, progress);
expect(showAndLogInformationMessageSpy.firstCall.args[0]).to.contain(
'Finished installing packs.'
);
} catch (error) {
expect(error.message).to.contain('Unable to install packs:');
}
});
});