omnisharp-vscode/test/unitTests/OmnisharpDownloader.test.ts

83 строки
4.0 KiB
TypeScript
Исходник Постоянная ссылка Обычный вид История

2018-05-26 04:37:05 +03:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { OmnisharpDownloader } from "../../src/omnisharp/OmnisharpDownloader";
import NetworkSettings from "../../src/NetworkSettings";
import { EventStream } from "../../src/EventStream";
import { PlatformInformation } from "../../src/platform";
import { CreateTmpDir, TmpAsset } from "../../src/CreateTmpAsset";
import * as util from '../../src/common';
import * as path from 'path';
import MockHttpsServer from "./testAssets/MockHttpsServer";
import {expect} from 'chai';
import TestZip from "./testAssets/TestZip";
import { createTestFile } from "./testAssets/TestFile";
2018-06-01 11:51:50 +03:00
import { PackageInstallation, LogPlatformInfo, DownloadStart, DownloadSizeObtained, DownloadProgress, DownloadSuccess, InstallationStart, InstallationSuccess } from "../../src/omnisharp/loggingEvents";
import TestEventBus from "./testAssets/TestEventBus";
2018-06-03 09:29:20 +03:00
import { testPackageJSON } from "./testAssets/testAssets";
2018-05-26 04:37:05 +03:00
suite('OmnisharpDownloader', () => {
const networkSettingsProvider = () => new NetworkSettings(undefined, false);
let eventStream : EventStream;
const installPath = "somePath";
let platformInfo = new PlatformInformation("win32", "x86");
let downloader: OmnisharpDownloader;
let server: MockHttpsServer;
let extensionPath: string;
const version = "1.2.3";
let tmpDir: TmpAsset;
let testZip: TestZip;
2018-06-01 11:51:50 +03:00
let eventBus: TestEventBus;
2018-05-26 04:37:05 +03:00
setup(async () => {
eventStream = new EventStream();
2018-06-01 11:51:50 +03:00
eventBus = new TestEventBus(eventStream);
2018-05-26 04:37:05 +03:00
tmpDir = await CreateTmpDir(true);
extensionPath = tmpDir.name;
2018-07-03 01:13:11 +03:00
downloader = new OmnisharpDownloader(networkSettingsProvider, eventStream, testPackageJSON, platformInfo, extensionPath);
2018-05-26 04:37:05 +03:00
server = await MockHttpsServer.CreateMockHttpsServer();
testZip = await TestZip.createTestZipAsync(createTestFile("Foo", "foo.txt"));
await server.start();
server.addRequestHandler('GET', `/releases/${version}/omnisharp-win-x86.zip`, 200, {
"content-type": "application/zip",
"content-length": testZip.size
}, testZip.buffer);
});
test('Throws error if request is made for a version that doesnot exist on the server', () => {
expect(downloader.DownloadAndInstallOmnisharp("1.00000001.0000", server.baseUrl, installPath)).to.be.rejectedWith(Error);
});
test('Packages are downloaded and installed', async () => {
await downloader.DownloadAndInstallOmnisharp(version, server.baseUrl, installPath);
for (let elem of testZip.files) {
let filePath = path.join(extensionPath, installPath, version, elem.path);
expect(await util.fileExists(filePath)).to.be.true;
}
});
test('Events are created', async () => {
let expectedSequence = [
new PackageInstallation('OmniSharp Version = 1.2.3'),
new LogPlatformInfo(new PlatformInformation("win32", "x86")),
new DownloadStart('OmniSharp for Windows (.NET 4.6 / x86), Version = 1.2.3'),
new DownloadSizeObtained(testZip.size),
new DownloadProgress(100, 'OmniSharp for Windows (.NET 4.6 / x86), Version = 1.2.3'),
new DownloadSuccess(' Done!'),
new InstallationStart('OmniSharp for Windows (.NET 4.6 / x86), Version = 1.2.3'),
new InstallationSuccess()
];
2018-06-01 11:51:50 +03:00
expect(eventBus.getEvents()).to.be.empty;
2018-05-26 04:37:05 +03:00
await downloader.DownloadAndInstallOmnisharp(version, server.baseUrl, installPath);
2018-06-01 11:51:50 +03:00
expect(eventBus.getEvents()).to.be.deep.equal(expectedSequence);
2018-05-26 04:37:05 +03:00
});
teardown(async () => {
tmpDir.dispose();
await server.stop();
2018-06-01 11:51:50 +03:00
eventBus.dispose();
2018-05-26 04:37:05 +03:00
});
});