Skip to content

Commit 8bdf184

Browse files
Karan NagpalKaran Nagpal
authored andcommitted
handle null and empty array in downloads
1 parent 24ad351 commit 8bdf184

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module.exports = function run(args) {
139139
await new Promise(resolve => setTimeout(resolve, 5000));
140140

141141
// download build artifacts
142-
if (bsConfig.run_settings.downloads && bsConfig.run_settings.downloads.length) {
142+
if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
143143
await downloadBuildArtifacts(bsConfig, data.build_id, args);
144144
}
145145

@@ -149,7 +149,7 @@ module.exports = function run(args) {
149149
utils.handleSyncExit(exitCode, data.dashboard_url);
150150
});
151151
});
152-
} else if (bsConfig.run_settings.downloads && bsConfig.run_settings.downloads.length) {
152+
} else if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
153153
logger.info(Constants.userMessages.ASYNC_DOWNLOADS.replace('<build-id>', data.build_id));
154154
}
155155

bin/helpers/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ exports.isUndefined = value => (value === undefined || value === null);
335335

336336
exports.isFloat = (value) => Number(value) && Number(value) % 1 !== 0;
337337

338+
exports.nonEmptyArray = (value) => {
339+
if(!this.isUndefined(value) && value && value.length) {
340+
return true;
341+
}
342+
return false;
343+
}
344+
338345
exports.isParallelValid = (value) => {
339346
return this.isUndefined(value) || !(isNaN(value) || this.isFloat(value) || parseInt(value, 10) === 0 || parseInt(value, 10) < -1) || value === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE;
340347
}

test/unit/bin/commands/runs.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ const chai = require("chai"),
55
const Constants = require("../../../../bin/helpers/constants"),
66
logger = require("../../../../bin/helpers/logger").winstonLogger,
77
testObjects = require("../../support/fixtures/testObjects");
8-
const { initTimeComponents, markBlockStart, markBlockEnd } = require("../../../../bin/helpers/timeComponents");
9-
const { setHeaded, setupLocalTesting, stopLocalBinary, setUserSpecs, setLocalConfigFile } = require("../../../../bin/helpers/utils");
108

119
const proxyquire = require("proxyquire").noCallThru();
1210

@@ -665,6 +663,8 @@ describe("runs", () => {
665663
initTimeComponentsStub = sandbox.stub();
666664
markBlockStartStub = sandbox.stub();
667665
markBlockEndStub = sandbox.stub();
666+
stopLocalBinaryStub = sandbox.stub();
667+
nonEmptyArrayStub = sandbox.stub();
668668
});
669669

670670
afterEach(() => {
@@ -707,6 +707,8 @@ describe("runs", () => {
707707
isUndefined: isUndefinedStub,
708708
getNumberOfSpecFiles: getNumberOfSpecFilesStub,
709709
setLocalConfigFile: setLocalConfigFileStub,
710+
stopLocalBinary: stopLocalBinaryStub,
711+
nonEmptyArray: nonEmptyArrayStub,
710712
},
711713
'../helpers/capabilityHelper': {
712714
validate: capabilityValidatorStub,
@@ -745,6 +747,8 @@ describe("runs", () => {
745747
archiverStub.returns(Promise.resolve("Zipping completed"));
746748
checkUploadedStub.returns(Promise.resolve({ zipUrlPresent: false }))
747749
zipUploadStub.returns(Promise.resolve("zip uploaded"));
750+
stopLocalBinaryStub.returns(Promise.resolve("nothing"));
751+
nonEmptyArrayStub.returns(false);
748752
createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id', dashboard_url: dashboardUrl }));
749753

750754
return runs(args)

test/unit/bin/helpers/utils.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,4 +2083,19 @@ describe('utils', () => {
20832083
});
20842084
});
20852085

2086+
describe('nonEmptyArray', () => {
2087+
it('return true if non empty array', () => {
2088+
expect(utils.nonEmptyArray([1, 2, 3])).to.be.eql(true);
2089+
expect(utils.nonEmptyArray(["abc"])).to.be.eql(true);
2090+
});
2091+
2092+
it('return false if empty array', () => {
2093+
expect(utils.nonEmptyArray([])).to.be.eql(false);
2094+
});
2095+
2096+
it('return false if null', () => {
2097+
expect(utils.nonEmptyArray(null)).to.be.eql(false);
2098+
});
2099+
});
2100+
20862101
});

0 commit comments

Comments
 (0)