Skip to content

Commit

Permalink
Deleting build_results.txt on start of run command.
Browse files Browse the repository at this point in the history
  • Loading branch information
karanshah-browserstack committed Aug 31, 2020
1 parent 4a4061e commit e133c53
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
2 changes: 2 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const archiver = require("../helpers/archiver"),

module.exports = function run(args) {
let bsConfigPath = utils.getConfigPath(args.cf);
//Delete build_results.txt from log folder if already present.
utils.deleteResults();

return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
Expand Down
5 changes: 5 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,8 @@ exports.exportResults = (buildId, buildUrl) => {
}
});
}

exports.deleteResults = () => {
fs.unlink("log/build_results.txt", function (err){
});
}
32 changes: 24 additions & 8 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("runs", () => {
return "end";
});
getErrorCodeFromErrStub = sandbox.stub().returns("random-error-code");
deleteResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -45,7 +46,8 @@ describe("runs", () => {
getErrorCodeFromErr: getErrorCodeFromErrStub,
sendUsageReport: sendUsageReportStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub
getConfigPath: getConfigPathStub,
deleteResults: deleteResultsStub
},
});

Expand All @@ -61,6 +63,7 @@ describe("runs", () => {
sinon.assert.calledOnce(validateBstackJsonStub);
sinon.assert.calledOnce(setUsageReportingFlagStub);
sinon.assert.calledOnce(getErrorCodeFromErrStub);
sinon.assert.calledOnce(deleteResultsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
null,
Expand Down Expand Up @@ -89,6 +92,7 @@ describe("runs", () => {
});
getErrorCodeFromMsgStub = sandbox.stub().returns("random-error-code");
capabilityValidatorStub = sandbox.stub();
deleteResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -110,7 +114,8 @@ describe("runs", () => {
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
getConfigPath: getConfigPathStub
getConfigPath: getConfigPathStub,
deleteResults: deleteResultsStub
},
"../helpers/capabilityHelper": {
validate: capabilityValidatorStub,
Expand All @@ -131,6 +136,7 @@ describe("runs", () => {
sinon.assert.calledOnce(capabilityValidatorStub);
sinon.assert.calledOnce(setUsageReportingFlagStub);
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
sinon.assert.calledOnce(deleteResultsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -161,6 +167,7 @@ describe("runs", () => {
capabilityValidatorStub = sandbox.stub();
archiverStub = sandbox.stub();
deleteZipStub = sandbox.stub();
deleteResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -182,7 +189,8 @@ describe("runs", () => {
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub
getConfigPath: getConfigPathStub,
deleteResults: deleteResultsStub
},
"../helpers/capabilityHelper": {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -212,6 +220,7 @@ describe("runs", () => {
sinon.assert.calledOnce(archiverStub);
sinon.assert.calledOnce(setUsageReportingFlagStub);
sinon.assert.calledOnce(deleteZipStub);
sinon.assert.calledOnce(deleteResultsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -243,6 +252,7 @@ describe("runs", () => {
archiverStub = sandbox.stub();
zipUploadStub = sandbox.stub();
deleteZipStub = sandbox.stub();
deleteResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -264,7 +274,8 @@ describe("runs", () => {
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub
getConfigPath: getConfigPathStub,
deleteResults: deleteResultsStub
},
"../helpers/capabilityHelper": {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -298,7 +309,7 @@ describe("runs", () => {
sinon.assert.calledOnce(archiverStub);
sinon.assert.calledOnce(setUsageReportingFlagStub);
sinon.assert.calledOnce(zipUploadStub);

sinon.assert.calledOnce(deleteResultsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down Expand Up @@ -334,6 +345,7 @@ describe("runs", () => {
zipUploadStub = sandbox.stub();
createBuildStub = sandbox.stub();
deleteZipStub = sandbox.stub();
deleteResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -355,7 +367,8 @@ describe("runs", () => {
setAccessKey: setAccessKeyStub,
setBuildName: setBuildNameStub,
setUsageReportingFlag: setUsageReportingFlagStub,
getConfigPath: getConfigPathStub
getConfigPath: getConfigPathStub,
deleteResults: deleteResultsStub
},
"../helpers/capabilityHelper": {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -398,6 +411,7 @@ describe("runs", () => {
sinon.assert.calledOnce(createBuildStub);

sinon.assert.calledOnce(sendUsageReportStub);
sinon.assert.calledOnce(deleteResultsStub);

sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
Expand Down Expand Up @@ -437,6 +451,7 @@ describe("runs", () => {
createBuildStub = sandbox.stub();
deleteZipStub = sandbox.stub();
exportResultsStub = sandbox.stub();
deleteResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -460,7 +475,8 @@ describe("runs", () => {
setUsageReportingFlag: setUsageReportingFlagStub,
setParallels: setParallelsStub,
getConfigPath: getConfigPathStub,
exportResults: exportResultsStub
exportResults: exportResultsStub,
deleteResults: deleteResultsStub
},
"../helpers/capabilityHelper": {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -505,7 +521,7 @@ describe("runs", () => {
sinon.assert.calledOnce(zipUploadStub);
sinon.assert.calledOnce(createBuildStub);
sinon.assert.calledOnce(exportResultsStub);

sinon.assert.calledOnce(deleteResultsStub);
sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
bsConfig,
Expand Down
10 changes: 10 additions & 0 deletions test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,14 @@ describe("utils", () => {
});

});

describe("deleteResults", () => {

it("should delete log/build_results.txt", () => {
sinon.stub(fs, 'unlink').returns(true);
utils.deleteResults();
fs.unlink.restore();
});

});
});

0 comments on commit e133c53

Please sign in to comment.