From 4708ede0a4a3dfec357faf093b5d5bc64ab21693 Mon Sep 17 00:00:00 2001 From: roshan04 Date: Tue, 6 Jun 2023 14:10:15 +0530 Subject: [PATCH 1/3] added decompress module changes --- bin/helpers/buildArtifacts.js | 12 ++++++++---- bin/helpers/reporterHTML.js | 16 +++++++++------- package.json | 3 ++- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index 620fc44e..c3ee0a90 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -11,6 +11,7 @@ const logger = require('./logger').winstonLogger, config = require("./config"); const request = require('request'); +const decompress = require('decompress'); let BUILD_ARTIFACTS_TOTAL_COUNT = 0; @@ -127,10 +128,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..aff0c7e5 100644 --- a/bin/helpers/reporterHTML.js +++ b/bin/helpers/reporterHTML.js @@ -5,7 +5,8 @@ const fs = require('fs'), 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 +151,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 503d3961..898255ee 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "update-notifier": "5.1.0", "uuid": "8.3.2", "winston": "2.4.4", - "yargs": "14.2.3" + "yargs": "14.2.3", + "decompress": "4.2.1" }, "repository": { "type": "git", From 2a580efdf68db96b2de70f76f293db4cc6d81a3d Mon Sep 17 00:00:00 2001 From: roshan04 Date: Tue, 4 Jul 2023 13:37:37 +0530 Subject: [PATCH 2/3] added rspecs for decompress --- test/unit/bin/helpers/reporterHTML.js | 36 ++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) 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(() => { From 7ef6debfd362b60b70ab301c6ed8ddf9171ff8ba Mon Sep 17 00:00:00 2001 From: roshan04 Date: Tue, 4 Jul 2023 13:38:29 +0530 Subject: [PATCH 3/3] removed the unzipper --- bin/helpers/buildArtifacts.js | 2 -- bin/helpers/reporterHTML.js | 1 - package.json | 1 - 3 files changed, 4 deletions(-) diff --git a/bin/helpers/buildArtifacts.js b/bin/helpers/buildArtifacts.js index c3ee0a90..3d476295 100644 --- a/bin/helpers/buildArtifacts.js +++ b/bin/helpers/buildArtifacts.js @@ -3,8 +3,6 @@ const fs = require('fs'), path = require('path'); -const unzipper = require('unzipper'); - const logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require("./constants"), diff --git a/bin/helpers/reporterHTML.js b/bin/helpers/reporterHTML.js index aff0c7e5..5859b103 100644 --- a/bin/helpers/reporterHTML.js +++ b/bin/helpers/reporterHTML.js @@ -1,7 +1,6 @@ const fs = require('fs'), path = require('path'), request = require('request'), - unzipper = require('unzipper'), logger = require('./logger').winstonLogger, utils = require("./utils"), Constants = require('./constants'), diff --git a/package.json b/package.json index ebdbba07..74ad6696 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "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", "winston": "2.4.4",