Skip to content

Commit 857fff9

Browse files
committed
Clean up the tests
1 parent 6a3c9fb commit 857fff9

File tree

4 files changed

+12
-45
lines changed

4 files changed

+12
-45
lines changed

test/unitTests/Packages/PackageManager.test.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@ const ServerMock = require("mock-http-server");
2323
const getPort = require('get-port');
2424

2525
suite("Package Manager", () => {
26-
let tmpSourceDir: TmpAsset;
2726
let tmpInstallDir: TmpAsset;
2827
let server: any;
2928
let downloadUrl: string;
30-
let testDirPath: string;
3129
let allFiles: Array<{ content: string, path: string }>;
3230
let installationPath: string;
3331
let eventBus: Array<BaseEvent>;
@@ -55,7 +53,6 @@ suite("Package Manager", () => {
5553

5654
setup(async () => {
5755
eventBus = [];
58-
tmpSourceDir = await CreateTmpDir(true);
5956
tmpInstallDir = await CreateTmpDir(true);
6057
installationPath = tmpInstallDir.name;
6158
packages = <Package[]>[
@@ -67,13 +64,12 @@ suite("Package Manager", () => {
6764
architectures: [windowsPlatformInfo.architecture]
6865
}];
6966
allFiles = [...Files, ...Binaries];
70-
testDirPath = tmpSourceDir.name + "/test.zip";
71-
await createTestZipAsync(testDirPath, allFiles);
67+
let buffer = await createTestZipAsync(allFiles);
7268
await new Promise(resolve => server.start(resolve)); //start the server
7369
server.on(getRequestHandler('GET', '/package', 200, {
7470
"content-type": "application/zip",
75-
"content-length": (await fs.stat(testDirPath)).size
76-
}, await fs.readFile(testDirPath)));
71+
"content-length": buffer.length
72+
}, buffer));
7773
});
7874

7975
test("Downloads the package and installs at the specified path", async () => {
@@ -105,9 +101,6 @@ suite("Package Manager", () => {
105101
});
106102

107103
teardown(async () => {
108-
if (tmpSourceDir) {
109-
tmpSourceDir.dispose();
110-
}
111104
if (tmpInstallDir) {
112105
tmpInstallDir.dispose();
113106
}

test/unitTests/Packages/ZipInstaller.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@ import { EventStream } from '../../../src/EventStream';
1313
import { PlatformInformation } from '../../../src/platform';
1414
import { BaseEvent, InstallationStart } from '../../../src/omnisharp/loggingEvents';
1515
import { Files, Binaries, createTestZipAsync } from '../testAssets/CreateTestZip';
16-
import ReadFileIntoBuffer from '../testAssets/ReadFileIntoBuffer';
1716

1817
chai.use(require("chai-as-promised"));
1918
let expect = chai.expect;
2019

2120
suite('ZipInstaller', () => {
22-
let tmpSourceDir: TmpAsset;
2321
let tmpInstallDir: TmpAsset;
24-
let testDirPath: string;
2522
let installationPath: string;
2623
let testBuffer: Buffer;
2724

@@ -33,13 +30,10 @@ suite('ZipInstaller', () => {
3330

3431
setup(async () => {
3532
eventBus = [];
36-
tmpSourceDir = await CreateTmpDir(true);
3733
tmpInstallDir = await CreateTmpDir(true);
3834
installationPath = tmpInstallDir.name;
3935
allFiles = [...Files, ...Binaries];
40-
testDirPath = tmpSourceDir.name + "/test.zip";
41-
await createTestZipAsync(testDirPath, allFiles);
42-
testBuffer = await ReadFileIntoBuffer(testDirPath);
36+
testBuffer = await createTestZipAsync(allFiles);
4337
util.setExtensionPath(tmpInstallDir.name);
4438
});
4539

@@ -76,7 +70,8 @@ suite('ZipInstaller', () => {
7670
});
7771

7872
teardown(async () => {
79-
tmpSourceDir.dispose();
80-
tmpInstallDir.dispose();
73+
if (tmpInstallDir) {
74+
tmpInstallDir.dispose();
75+
}
8176
});
8277
});

test/unitTests/testAssets/CreateTestZip.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as archiver from 'archiver';
7-
import * as fs from 'async-file';
87

98
export const Files = [
109
{
@@ -26,14 +25,9 @@ export const Binaries = [
2625
];
2726

2827

29-
export async function createTestZipAsync(dirPath: string, filesToAdd: Array<{ content: string, path: string }>): Promise<{}> {
30-
let output = fs.createWriteStream(dirPath);
31-
32-
return new Promise((resolve, reject) => {
33-
output.on('close', function () {
34-
resolve(); // the installer needs to wait for the filestream to be closed here
35-
});
36-
28+
export async function createTestZipAsync(filesToAdd: Array<{ content: string, path: string }>): Promise<Buffer> {
29+
let buffers: any[] = [];
30+
return new Promise<Buffer>((resolve, reject) => {
3731
let archive = archiver('zip');
3832
archive.on('warning', function (err: any) {
3933
if (err.code === 'ENOENT') {
@@ -43,9 +37,9 @@ export async function createTestZipAsync(dirPath: string, filesToAdd: Array<{ co
4337
reject(err);
4438
}
4539
});
46-
40+
archive.on('data', data => buffers.push(data));
4741
archive.on('error', reject);
48-
archive.pipe(output);
42+
archive.on('end', () => resolve(Buffer.concat(buffers)));
4943
filesToAdd.forEach(elem => archive.append(elem.content, { name: elem.path }));
5044
archive.finalize();
5145
});

test/unitTests/testAssets/ReadFileIntoBuffer.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)