Skip to content

Commit 007664f

Browse files
author
Archish Thakkar
authored
Merge branch 'master' into deploy
2 parents b16ade3 + a4b975a commit 007664f

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

bin/helpers/buildArtifacts.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
const fs = require('fs'),
44
path = require('path');
55

6-
const unzipper = require('unzipper');
7-
86
const logger = require('./logger').winstonLogger,
97
utils = require("./utils"),
108
Constants = require("./constants"),
119
config = require("./config");
1210

1311
const request = require('request');
12+
const decompress = require('decompress');
1413

1514

1615
let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
@@ -127,10 +126,13 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
127126

128127
const unzipFile = async (filePath, fileName) => {
129128
return new Promise( async (resolve, reject) => {
130-
await unzipper.Open.file(path.join(filePath, fileName))
131-
.then(d => d.extract({path: filePath, concurrency: 5}))
132-
.catch((err) => reject(err));
133-
resolve();
129+
await decompress(path.join(filePath, fileName), filePath)
130+
.then((files) => {
131+
resolve();
132+
})
133+
.catch((error) => {
134+
reject(error);
135+
});
134136
});
135137
}
136138

bin/helpers/reporterHTML.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
const fs = require('fs'),
22
path = require('path'),
33
request = require('request'),
4-
unzipper = require('unzipper'),
54
logger = require('./logger').winstonLogger,
65
utils = require("./utils"),
76
Constants = require('./constants'),
8-
config = require("./config");
7+
config = require("./config"),
8+
decompress = require('decompress');
99

1010
let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
1111
let options = {
@@ -150,14 +150,15 @@ function getReportResponse(filePath, fileName, reportJsonUrl) {
150150

151151
const unzipFile = async (filePath, fileName) => {
152152
return new Promise( async (resolve, reject) => {
153-
await unzipper.Open.file(path.join(filePath, fileName))
154-
.then(d => d.extract({path: filePath, concurrency: 5}))
155-
.catch((err) => {
156-
reject(err);
157-
process.exitCode = Constants.ERROR_EXIT_CODE;
158-
});
153+
await decompress(path.join(filePath, fileName), filePath)
154+
.then((files) => {
159155
let message = "Unzipped the json and html successfully."
160156
resolve(message);
157+
})
158+
.catch((error) => {
159+
reject(error);
160+
process.exitCode = Constants.ERROR_EXIT_CODE;
161+
});
161162
});
162163
}
163164

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
"request": "2.88.2",
3030
"requestretry": "7.1.0",
3131
"table": "5.4.6",
32-
"unzipper": "0.10.11",
3332
"update-notifier": "5.1.0",
3433
"uuid": "8.3.2",
3534
"windows-release": "^5.1.0",
3635
"winston": "2.4.4",
37-
"yargs": "14.2.3"
36+
"yargs": "14.2.3",
37+
"decompress": "4.2.1"
3838
},
3939
"repository": {
4040
"type": "git",

test/unit/bin/helpers/reporterHTML.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require("chai"),
77
const fs = require('fs'),
88
path = require('path'),
99
request = require('request'),
10-
unzipper = require('unzipper');
10+
decompress = require('decompress');
1111
Constants = require("../../../../bin/helpers/constants"),
1212
logger = require("../../../../bin/helpers/logger").winstonLogger,
1313
testObjects = require("../../support/fixtures/testObjects"),
@@ -241,6 +241,40 @@ describe("calls API to generate report", () => {
241241
});
242242
});
243243

244+
describe("unzipFile", () => {
245+
var sandbox;
246+
beforeEach(() => {
247+
sandbox = sinon.createSandbox();
248+
});
249+
250+
afterEach(() => {
251+
sandbox.restore();
252+
sinon.restore();
253+
});
254+
255+
it("calls unzip and resolves with success message", () => {
256+
let pathStub = sinon.stub(path, 'join');
257+
pathStub.calledOnceWith('abc','efg.txt');
258+
let decompressStub = sandbox.stub().returns(Promise.resolve("Unzipped the json and html successfully."));
259+
let rewireReporterHTML = rewire('../../../../bin/helpers/reporterHTML');
260+
rewireReporterHTML.__set__('decompress', decompressStub);
261+
let unzipFile = rewireReporterHTML.__get__('unzipFile')
262+
unzipFile('abc', 'efg');
263+
});
264+
265+
it("calls unzip and rejects with error message on failure", () => {
266+
let pathStub = sinon.stub(path, 'join');
267+
pathStub.calledOnceWith('abc','efg.txt');
268+
let processStub = sinon.stub(process, 'exit');
269+
processStub.returns(Constants.ERROR_EXIT_CODE)
270+
let decompressStub = sandbox.stub().returns(Promise.reject("Error"));
271+
let rewireReporterHTML = rewire('../../../../bin/helpers/reporterHTML');
272+
rewireReporterHTML.__set__('decompress', decompressStub);
273+
let unzipFile = rewireReporterHTML.__get__('unzipFile')
274+
unzipFile('abc', 'efg');
275+
});
276+
});
277+
244278
describe("generateCypressBuildReport", () => {
245279
var sandbox;
246280
beforeEach(() => {

0 commit comments

Comments
 (0)