diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 620fc44e..3d476295 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -3,14 +3,13 @@ const fs = require('fs'), path = require('path'); -const unzipper = require('unzipper'); - const logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require("./constants"), config = require("./config"); const request = require('request'); +const decompress = require('decompress'); let BUILD_ARTIFACTS_TOTAL_COUNT = 0; @@ -127,10 +126,13 @@ const downloadAndUnzip = async (filePath, fileName, url) => { const unzipFile = async (filePath, fileName) => { return new Promise( async (resolve, reject) => { - await unzipper.Open.file(path.join(filePath, fileName)) - .then(d => d.extract({path: filePath, concurrency: 5})) - .catch((err) => reject(err)); - resolve(); + await decompress(path.join(filePath, fileName), filePath) + .then((files) => { + resolve(); + }) + .catch((error) => { + reject(error); + }); }); } diff --git a/bin/helpers/reporterHTML.js b/bin/helpers/reporterHTML.js index dd8f605c..5859b103 100644 --- a/bin/helpers/reporterHTML.js +++ b/bin/helpers/reporterHTML.js @@ -1,11 +1,11 @@ const fs = require('fs'), path = require('path'), request = require('request'), - unzipper = require('unzipper'), logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require('./constants'), - config = require("./config"); + config = require("./config"), + decompress = require('decompress'); let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => { let options = { @@ -150,14 +150,15 @@ function getReportResponse(filePath, fileName, reportJsonUrl) { const unzipFile = async (filePath, fileName) => { return new Promise( async (resolve, reject) => { - await unzipper.Open.file(path.join(filePath, fileName)) - .then(d => d.extract({path: filePath, concurrency: 5})) - .catch((err) => { - reject(err); - process.exitCode = Constants.ERROR_EXIT_CODE; - }); + await decompress(path.join(filePath, fileName), filePath) + .then((files) => { let message = "Unzipped the json and html successfully." resolve(message); + }) + .catch((error) => { + reject(error); + process.exitCode = Constants.ERROR_EXIT_CODE; + }); }); } diff --git a/package.json b/package.json index 420bdfab..2b927805 100644 --- a/package.json +++ b/package.json @@ -29,12 +29,12 @@ "request": "2.88.2", "requestretry": "7.1.0", "table": "5.4.6", - "unzipper": "0.10.11", "update-notifier": "5.1.0", "uuid": "8.3.2", "windows-release": "^5.1.0", "winston": "2.4.4", - "yargs": "14.2.3" + "yargs": "14.2.3", + "decompress": "4.2.1" }, "repository": { "type": "git", diff --git a/test/unit/bin/helpers/reporterHTML.js b/test/unit/bin/helpers/reporterHTML.js index 4bb6e451..56276464 100644 --- a/test/unit/bin/helpers/reporterHTML.js +++ b/test/unit/bin/helpers/reporterHTML.js @@ -7,7 +7,7 @@ const chai = require("chai"), const fs = require('fs'), path = require('path'), request = require('request'), - unzipper = require('unzipper'); + decompress = require('decompress'); Constants = require("../../../../bin/helpers/constants"), logger = require("../../../../bin/helpers/logger").winstonLogger, testObjects = require("../../support/fixtures/testObjects"), @@ -241,6 +241,40 @@ describe("calls API to generate report", () => { }); }); +describe("unzipFile", () => { + var sandbox; + beforeEach(() => { + sandbox = sinon.createSandbox(); + }); + + afterEach(() => { + sandbox.restore(); + sinon.restore(); + }); + + it("calls unzip and resolves with success message", () => { + let pathStub = sinon.stub(path, 'join'); + pathStub.calledOnceWith('abc','efg.txt'); + let decompressStub = sandbox.stub().returns(Promise.resolve("Unzipped the json and html successfully.")); + let rewireReporterHTML = rewire('../../../../bin/helpers/reporterHTML'); + rewireReporterHTML.__set__('decompress', decompressStub); + let unzipFile = rewireReporterHTML.__get__('unzipFile') + unzipFile('abc', 'efg'); + }); + + it("calls unzip and rejects with error message on failure", () => { + let pathStub = sinon.stub(path, 'join'); + pathStub.calledOnceWith('abc','efg.txt'); + let processStub = sinon.stub(process, 'exit'); + processStub.returns(Constants.ERROR_EXIT_CODE) + let decompressStub = sandbox.stub().returns(Promise.reject("Error")); + let rewireReporterHTML = rewire('../../../../bin/helpers/reporterHTML'); + rewireReporterHTML.__set__('decompress', decompressStub); + let unzipFile = rewireReporterHTML.__get__('unzipFile') + unzipFile('abc', 'efg'); + }); +}); + describe("generateCypressBuildReport", () => { var sandbox; beforeEach(() => {