Skip to content

Commit e133c53

Browse files
Deleting build_results.txt on start of run command.
1 parent 4a4061e commit e133c53

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

bin/commands/runs.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const archiver = require("../helpers/archiver"),
1111

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

1517
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1618
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);

bin/helpers/utils.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,8 @@ exports.exportResults = (buildId, buildUrl) => {
131131
}
132132
});
133133
}
134+
135+
exports.deleteResults = () => {
136+
fs.unlink("log/build_results.txt", function (err){
137+
});
138+
}

test/unit/bin/commands/runs.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe("runs", () => {
2727
return "end";
2828
});
2929
getErrorCodeFromErrStub = sandbox.stub().returns("random-error-code");
30+
deleteResultsStub = sandbox.stub();
3031
});
3132

3233
afterEach(() => {
@@ -45,7 +46,8 @@ describe("runs", () => {
4546
getErrorCodeFromErr: getErrorCodeFromErrStub,
4647
sendUsageReport: sendUsageReportStub,
4748
setUsageReportingFlag: setUsageReportingFlagStub,
48-
getConfigPath: getConfigPathStub
49+
getConfigPath: getConfigPathStub,
50+
deleteResults: deleteResultsStub
4951
},
5052
});
5153

@@ -61,6 +63,7 @@ describe("runs", () => {
6163
sinon.assert.calledOnce(validateBstackJsonStub);
6264
sinon.assert.calledOnce(setUsageReportingFlagStub);
6365
sinon.assert.calledOnce(getErrorCodeFromErrStub);
66+
sinon.assert.calledOnce(deleteResultsStub);
6467
sinon.assert.calledOnceWithExactly(
6568
sendUsageReportStub,
6669
null,
@@ -89,6 +92,7 @@ describe("runs", () => {
8992
});
9093
getErrorCodeFromMsgStub = sandbox.stub().returns("random-error-code");
9194
capabilityValidatorStub = sandbox.stub();
95+
deleteResultsStub = sandbox.stub();
9296
});
9397

9498
afterEach(() => {
@@ -110,7 +114,8 @@ describe("runs", () => {
110114
setUsername: setUsernameStub,
111115
setAccessKey: setAccessKeyStub,
112116
setBuildName: setBuildNameStub,
113-
getConfigPath: getConfigPathStub
117+
getConfigPath: getConfigPathStub,
118+
deleteResults: deleteResultsStub
114119
},
115120
"../helpers/capabilityHelper": {
116121
validate: capabilityValidatorStub,
@@ -131,6 +136,7 @@ describe("runs", () => {
131136
sinon.assert.calledOnce(capabilityValidatorStub);
132137
sinon.assert.calledOnce(setUsageReportingFlagStub);
133138
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
139+
sinon.assert.calledOnce(deleteResultsStub);
134140
sinon.assert.calledOnceWithExactly(
135141
sendUsageReportStub,
136142
bsConfig,
@@ -161,6 +167,7 @@ describe("runs", () => {
161167
capabilityValidatorStub = sandbox.stub();
162168
archiverStub = sandbox.stub();
163169
deleteZipStub = sandbox.stub();
170+
deleteResultsStub = sandbox.stub();
164171
});
165172

166173
afterEach(() => {
@@ -182,7 +189,8 @@ describe("runs", () => {
182189
setAccessKey: setAccessKeyStub,
183190
setBuildName: setBuildNameStub,
184191
setUsageReportingFlag: setUsageReportingFlagStub,
185-
getConfigPath: getConfigPathStub
192+
getConfigPath: getConfigPathStub,
193+
deleteResults: deleteResultsStub
186194
},
187195
"../helpers/capabilityHelper": {
188196
validate: capabilityValidatorStub,
@@ -212,6 +220,7 @@ describe("runs", () => {
212220
sinon.assert.calledOnce(archiverStub);
213221
sinon.assert.calledOnce(setUsageReportingFlagStub);
214222
sinon.assert.calledOnce(deleteZipStub);
223+
sinon.assert.calledOnce(deleteResultsStub);
215224
sinon.assert.calledOnceWithExactly(
216225
sendUsageReportStub,
217226
bsConfig,
@@ -243,6 +252,7 @@ describe("runs", () => {
243252
archiverStub = sandbox.stub();
244253
zipUploadStub = sandbox.stub();
245254
deleteZipStub = sandbox.stub();
255+
deleteResultsStub = sandbox.stub();
246256
});
247257

248258
afterEach(() => {
@@ -264,7 +274,8 @@ describe("runs", () => {
264274
setAccessKey: setAccessKeyStub,
265275
setBuildName: setBuildNameStub,
266276
setUsageReportingFlag: setUsageReportingFlagStub,
267-
getConfigPath: getConfigPathStub
277+
getConfigPath: getConfigPathStub,
278+
deleteResults: deleteResultsStub
268279
},
269280
"../helpers/capabilityHelper": {
270281
validate: capabilityValidatorStub,
@@ -298,7 +309,7 @@ describe("runs", () => {
298309
sinon.assert.calledOnce(archiverStub);
299310
sinon.assert.calledOnce(setUsageReportingFlagStub);
300311
sinon.assert.calledOnce(zipUploadStub);
301-
312+
sinon.assert.calledOnce(deleteResultsStub);
302313
sinon.assert.calledOnceWithExactly(
303314
sendUsageReportStub,
304315
bsConfig,
@@ -334,6 +345,7 @@ describe("runs", () => {
334345
zipUploadStub = sandbox.stub();
335346
createBuildStub = sandbox.stub();
336347
deleteZipStub = sandbox.stub();
348+
deleteResultsStub = sandbox.stub();
337349
});
338350

339351
afterEach(() => {
@@ -355,7 +367,8 @@ describe("runs", () => {
355367
setAccessKey: setAccessKeyStub,
356368
setBuildName: setBuildNameStub,
357369
setUsageReportingFlag: setUsageReportingFlagStub,
358-
getConfigPath: getConfigPathStub
370+
getConfigPath: getConfigPathStub,
371+
deleteResults: deleteResultsStub
359372
},
360373
"../helpers/capabilityHelper": {
361374
validate: capabilityValidatorStub,
@@ -398,6 +411,7 @@ describe("runs", () => {
398411
sinon.assert.calledOnce(createBuildStub);
399412

400413
sinon.assert.calledOnce(sendUsageReportStub);
414+
sinon.assert.calledOnce(deleteResultsStub);
401415

402416
sinon.assert.calledOnceWithExactly(
403417
sendUsageReportStub,
@@ -437,6 +451,7 @@ describe("runs", () => {
437451
createBuildStub = sandbox.stub();
438452
deleteZipStub = sandbox.stub();
439453
exportResultsStub = sandbox.stub();
454+
deleteResultsStub = sandbox.stub();
440455
});
441456

442457
afterEach(() => {
@@ -460,7 +475,8 @@ describe("runs", () => {
460475
setUsageReportingFlag: setUsageReportingFlagStub,
461476
setParallels: setParallelsStub,
462477
getConfigPath: getConfigPathStub,
463-
exportResults: exportResultsStub
478+
exportResults: exportResultsStub,
479+
deleteResults: deleteResultsStub
464480
},
465481
"../helpers/capabilityHelper": {
466482
validate: capabilityValidatorStub,
@@ -505,7 +521,7 @@ describe("runs", () => {
505521
sinon.assert.calledOnce(zipUploadStub);
506522
sinon.assert.calledOnce(createBuildStub);
507523
sinon.assert.calledOnce(exportResultsStub);
508-
524+
sinon.assert.calledOnce(deleteResultsStub);
509525
sinon.assert.calledOnceWithExactly(
510526
sendUsageReportStub,
511527
bsConfig,

test/unit/bin/helpers/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,14 @@ describe("utils", () => {
257257
});
258258

259259
});
260+
261+
describe("deleteResults", () => {
262+
263+
it("should delete log/build_results.txt", () => {
264+
sinon.stub(fs, 'unlink').returns(true);
265+
utils.deleteResults();
266+
fs.unlink.restore();
267+
});
268+
269+
});
260270
});

0 commit comments

Comments
 (0)