forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensionBuildInstaller.unit.test.ts
More file actions
126 lines (119 loc) · 6.33 KB
/
extensionBuildInstaller.unit.test.ts
File metadata and controls
126 lines (119 loc) · 6.33 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import * as assert from 'assert';
import { expect } from 'chai';
import * as sinon from 'sinon';
import { anything, instance, mock, verify, when } from 'ts-mockito';
import { Progress, Uri } from 'vscode';
import { ApplicationShell } from '../../../client/common/application/applicationShell';
import { CommandManager } from '../../../client/common/application/commandManager';
import { IApplicationShell, ICommandManager } from '../../../client/common/application/types';
import { PVSC_EXTENSION_ID } from '../../../client/common/constants';
import {
developmentBuildUri,
InsidersBuildInstaller,
StableBuildInstaller,
vsixFileExtension,
} from '../../../client/common/installer/extensionBuildInstaller';
import { FileDownloader } from '../../../client/common/net/fileDownloader';
import { FileSystem } from '../../../client/common/platform/fileSystem';
import { IFileSystem } from '../../../client/common/platform/types';
import { DownloadOptions, IFileDownloader, IOutputChannel } from '../../../client/common/types';
import { ExtensionChannels } from '../../../client/common/utils/localize';
import { MockOutputChannel } from '../../../test/mockClasses';
type ProgressReporterData = { message?: string; increment?: number };
suite('Extension build installer - Stable build installer', async () => {
let output: IOutputChannel;
let cmdManager: ICommandManager;
let appShell: IApplicationShell;
let stableBuildInstaller: StableBuildInstaller;
let progressReporter: Progress<ProgressReporterData>;
let progressReportStub: sinon.SinonStub;
setup(() => {
output = mock(MockOutputChannel);
cmdManager = mock(CommandManager);
appShell = mock(ApplicationShell);
stableBuildInstaller = new StableBuildInstaller(instance(output), instance(cmdManager), instance(appShell));
progressReportStub = sinon.stub();
progressReporter = { report: progressReportStub };
});
test('Installing stable build logs progress and installs stable', async () => {
when(output.append(ExtensionChannels.installingStableMessage())).thenReturn();
when(output.appendLine(ExtensionChannels.installationCompleteMessage())).thenReturn();
when(
cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID, anything()),
).thenResolve(undefined);
when(appShell.withProgressCustomIcon(anything(), anything())).thenCall((_, cb) => cb(progressReporter));
await stableBuildInstaller.install();
verify(output.append(ExtensionChannels.installingStableMessage())).once();
verify(output.appendLine(ExtensionChannels.installationCompleteMessage())).once();
verify(appShell.withProgressCustomIcon(anything(), anything()));
expect(progressReportStub.callCount).to.equal(1);
verify(
cmdManager.executeCommand('workbench.extensions.installExtension', PVSC_EXTENSION_ID, anything()),
).once();
});
});
suite('Extension build installer - Insiders build installer', async () => {
let output: IOutputChannel;
let cmdManager: ICommandManager;
let fileDownloader: IFileDownloader;
let fs: IFileSystem;
let appShell: IApplicationShell;
let insidersBuildInstaller: InsidersBuildInstaller;
let progressReporter: Progress<ProgressReporterData>;
let progressReportStub: sinon.SinonStub;
setup(() => {
output = mock(MockOutputChannel);
fileDownloader = mock(FileDownloader);
fs = mock(FileSystem);
cmdManager = mock(CommandManager);
appShell = mock(ApplicationShell);
progressReportStub = sinon.stub();
progressReporter = { report: progressReportStub };
insidersBuildInstaller = new InsidersBuildInstaller(
instance(output),
instance(fileDownloader),
instance(fs),
instance(cmdManager),
instance(appShell),
);
});
test('Installing Insiders build downloads and installs Insiders', async () => {
const vsixFilePath = 'path/to/vsix';
const options = {
extension: vsixFileExtension,
outputChannel: output,
progressMessagePrefix: ExtensionChannels.downloadingInsidersMessage(),
};
when(output.append(ExtensionChannels.installingInsidersMessage())).thenReturn();
when(output.appendLine(ExtensionChannels.startingDownloadOutputMessage())).thenReturn();
when(output.appendLine(ExtensionChannels.downloadCompletedOutputMessage())).thenReturn();
when(output.appendLine(ExtensionChannels.installationCompleteMessage())).thenReturn();
when(fileDownloader.downloadFile(developmentBuildUri, anything())).thenCall(
(_, downloadOptions: DownloadOptions) => {
expect(downloadOptions.extension).to.equal(options.extension, 'Incorrect file extension');
expect(downloadOptions.progressMessagePrefix).to.equal(options.progressMessagePrefix);
return Promise.resolve(vsixFilePath);
},
);
when(appShell.withProgressCustomIcon(anything(), anything())).thenCall((_, cb) => cb(progressReporter));
when(cmdManager.executeCommand('workbench.extensions.installExtension', anything(), anything())).thenCall(
(_, uri, options) => {
assert.deepStrictEqual(uri, Uri.file(vsixFilePath), 'Wrong VSIX installed');
assert.deepStrictEqual(options, { installOnlyNewlyAddedFromExtensionPackVSIX: true });
},
);
when(fs.deleteFile(vsixFilePath)).thenResolve();
await insidersBuildInstaller.install();
verify(output.append(ExtensionChannels.installingInsidersMessage())).once();
verify(output.appendLine(ExtensionChannels.startingDownloadOutputMessage())).once();
verify(output.appendLine(ExtensionChannels.downloadCompletedOutputMessage())).once();
verify(output.appendLine(ExtensionChannels.installationCompleteMessage())).once();
verify(appShell.withProgressCustomIcon(anything(), anything()));
expect(progressReportStub.callCount).to.equal(1);
verify(cmdManager.executeCommand('workbench.extensions.installExtension', anything(), anything())).once();
verify(fs.deleteFile(vsixFilePath)).once();
});
});