Skip to content

Commit de2e718

Browse files
Merge branch 'master' of github.com:browserstack/browserstack-cypress-cli into Env_Var_Support
2 parents f5f057a + 356d9ce commit de2e718

File tree

5 files changed

+79
-11
lines changed

5 files changed

+79
-11
lines changed

bin/commands/runs.js

Lines changed: 3 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);
@@ -47,6 +49,7 @@ module.exports = function run(args) {
4749
return build.createBuild(bsConfig, zip).then(function (data) {
4850
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
4951
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
52+
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
5053
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.constants.DEFAULT_PARALLEL_MESSAGE)) {
5154
logger.warn(Constants.userMessages.NO_PARALLELS);
5255
}

bin/helpers/archiver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const archiveSpecs = (runSettings, filePath) => {
3838

3939
let allowedFileTypes = [ 'js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip' ];
4040
allowedFileTypes.forEach(fileType => {
41-
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ['node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip'] });
41+
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ['**/node_modules/**', './node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip'] });
4242
});
4343

4444
let packageJSON = {};

bin/helpers/utils.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const os = require("os");
33
const path = require("path");
4+
const fs = require("fs");
45

56
const usageReporting = require('./usageReporting'),
67
logger = require('./logger').winstonLogger,
@@ -142,6 +143,21 @@ exports.configCreated = (args) => {
142143
this.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
143144
}
144145

146+
exports.exportResults = (buildId, buildUrl) => {
147+
let data = "BUILD_ID=" + buildId + "\nBUILD_URL="+buildUrl;
148+
fs.writeFileSync("log/build_results.txt", data , function(err){
149+
if(err) {
150+
logger.warn(`Couldn't write BUILD_ID with value: ${buildId} to browserstack/build_results.txt`);
151+
logger.warn(`Couldn't write BUILD_URL with value: ${buildUrl} to browserstack/build_results.txt`);
152+
}
153+
});
154+
}
155+
156+
exports.deleteResults = () => {
157+
fs.unlink("log/build_results.txt", function (err){
158+
});
159+
}
160+
145161
exports.isCypressProjDirValid = (cypressDir, cypressProjDir) => {
146162
// Getting absolute path
147163
cypressDir = path.resolve(cypressDir);

test/unit/bin/commands/runs.js

Lines changed: 28 additions & 9 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,
@@ -91,6 +94,7 @@ describe("runs", () => {
9194
capabilityValidatorStub = sandbox.stub();
9295
setLocalStub = sandbox.stub();
9396
setLocalIdentifierStub = sandbox.stub();
97+
deleteResultsStub = sandbox.stub();
9498
});
9599

96100
afterEach(() => {
@@ -114,7 +118,8 @@ describe("runs", () => {
114118
setBuildName: setBuildNameStub,
115119
getConfigPath: getConfigPathStub,
116120
setLocal: setLocalStub,
117-
setLocalIdentifier: setLocalIdentifierStub
121+
setLocalIdentifier: setLocalIdentifierStub,
122+
deleteResults: deleteResultsStub
118123
},
119124
"../helpers/capabilityHelper": {
120125
validate: capabilityValidatorStub,
@@ -137,6 +142,7 @@ describe("runs", () => {
137142
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
138143
sinon.assert.calledOnce(setLocalStub);
139144
sinon.assert.calledOnce(setLocalIdentifierStub);
145+
sinon.assert.calledOnce(deleteResultsStub);
140146
sinon.assert.calledOnceWithExactly(
141147
sendUsageReportStub,
142148
bsConfig,
@@ -169,6 +175,7 @@ describe("runs", () => {
169175
deleteZipStub = sandbox.stub();
170176
setLocalStub = sandbox.stub();
171177
setLocalIdentifierStub = sandbox.stub();
178+
deleteResultsStub = sandbox.stub();
172179
});
173180

174181
afterEach(() => {
@@ -192,7 +199,8 @@ describe("runs", () => {
192199
setUsageReportingFlag: setUsageReportingFlagStub,
193200
getConfigPath: getConfigPathStub,
194201
setLocal: setLocalStub,
195-
setLocalIdentifier: setLocalIdentifierStub
202+
setLocalIdentifier: setLocalIdentifierStub,
203+
deleteResults: deleteResultsStub
196204
},
197205
"../helpers/capabilityHelper": {
198206
validate: capabilityValidatorStub,
@@ -224,6 +232,7 @@ describe("runs", () => {
224232
sinon.assert.calledOnce(archiverStub);
225233
sinon.assert.calledOnce(setUsageReportingFlagStub);
226234
sinon.assert.calledOnce(deleteZipStub);
235+
sinon.assert.calledOnce(deleteResultsStub);
227236
sinon.assert.calledOnceWithExactly(
228237
sendUsageReportStub,
229238
bsConfig,
@@ -257,6 +266,7 @@ describe("runs", () => {
257266
deleteZipStub = sandbox.stub();
258267
setLocalStub = sandbox.stub();
259268
setLocalIdentifierStub = sandbox.stub();
269+
deleteResultsStub = sandbox.stub();
260270
});
261271

262272
afterEach(() => {
@@ -280,7 +290,8 @@ describe("runs", () => {
280290
setUsageReportingFlag: setUsageReportingFlagStub,
281291
getConfigPath: getConfigPathStub,
282292
setLocal: setLocalStub,
283-
setLocalIdentifier: setLocalIdentifierStub
293+
setLocalIdentifier: setLocalIdentifierStub,
294+
deleteResults: deleteResultsStub
284295
},
285296
"../helpers/capabilityHelper": {
286297
validate: capabilityValidatorStub,
@@ -316,7 +327,7 @@ describe("runs", () => {
316327
sinon.assert.calledOnce(archiverStub);
317328
sinon.assert.calledOnce(setUsageReportingFlagStub);
318329
sinon.assert.calledOnce(zipUploadStub);
319-
330+
sinon.assert.calledOnce(deleteResultsStub);
320331
sinon.assert.calledOnceWithExactly(
321332
sendUsageReportStub,
322333
bsConfig,
@@ -354,6 +365,7 @@ describe("runs", () => {
354365
deleteZipStub = sandbox.stub();
355366
setLocalStub = sandbox.stub();
356367
setLocalIdentifierStub = sandbox.stub();
368+
deleteResultsStub = sandbox.stub();
357369
});
358370

359371
afterEach(() => {
@@ -377,7 +389,8 @@ describe("runs", () => {
377389
setUsageReportingFlag: setUsageReportingFlagStub,
378390
getConfigPath: getConfigPathStub,
379391
setLocal: setLocalStub,
380-
setLocalIdentifier: setLocalIdentifierStub
392+
setLocalIdentifier: setLocalIdentifierStub,
393+
deleteResults: deleteResultsStub
381394
},
382395
"../helpers/capabilityHelper": {
383396
validate: capabilityValidatorStub,
@@ -422,6 +435,7 @@ describe("runs", () => {
422435
sinon.assert.calledOnce(createBuildStub);
423436

424437
sinon.assert.calledOnce(sendUsageReportStub);
438+
sinon.assert.calledOnce(deleteResultsStub);
425439

426440
sinon.assert.calledOnceWithExactly(
427441
sendUsageReportStub,
@@ -460,6 +474,8 @@ describe("runs", () => {
460474
zipUploadStub = sandbox.stub();
461475
createBuildStub = sandbox.stub();
462476
deleteZipStub = sandbox.stub();
477+
exportResultsStub = sandbox.stub();
478+
deleteResultsStub = sandbox.stub();
463479
isUndefinedStub = sandbox.stub();
464480
setLocalStub = sandbox.stub();
465481
setLocalIdentifierStub = sandbox.stub();
@@ -486,9 +502,11 @@ describe("runs", () => {
486502
setUsageReportingFlag: setUsageReportingFlagStub,
487503
setParallels: setParallelsStub,
488504
getConfigPath: getConfigPathStub,
489-
isUndefined: isUndefinedStub,
490505
setLocal: setLocalStub,
491-
setLocalIdentifier: setLocalIdentifierStub
506+
setLocalIdentifier: setLocalIdentifierStub,
507+
exportResults: exportResultsStub,
508+
deleteResults: deleteResultsStub,
509+
isUndefined: isUndefinedStub
492510
},
493511
"../helpers/capabilityHelper": {
494512
validate: capabilityValidatorStub,
@@ -534,7 +552,8 @@ describe("runs", () => {
534552
sinon.assert.calledOnce(setUsageReportingFlagStub);
535553
sinon.assert.calledOnce(zipUploadStub);
536554
sinon.assert.calledOnce(createBuildStub);
537-
555+
sinon.assert.calledOnce(exportResultsStub);
556+
sinon.assert.calledOnce(deleteResultsStub);
538557
sinon.assert.calledOnceWithExactly(
539558
sendUsageReportStub,
540559
bsConfig,

test/unit/bin/helpers/utils.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const path = require('path');
44
const chai = require("chai"),
55
expect = chai.expect,
66
sinon = require('sinon'),
7-
chaiAsPromised = require("chai-as-promised");
7+
chaiAsPromised = require("chai-as-promised"),
8+
fs = require('fs');
89

910
const utils = require('../../../../bin/helpers/utils'),
1011
constant = require('../../../../bin/helpers/constants'),
@@ -242,6 +243,35 @@ describe("utils", () => {
242243
});
243244
});
244245

246+
describe("exportResults", () => {
247+
248+
it("should export results to log/build_results.txt", () => {
249+
sinon.stub(fs, 'writeFileSync').returns(true);
250+
utils.exportResults("build_id", "build_url");
251+
fs.writeFileSync.restore();
252+
});
253+
254+
it("should log warning if write to log/build_results.txt fails", () => {
255+
let writeFileSyncStub = sinon.stub(fs, 'writeFileSync');
256+
let loggerWarnStub = sinon.stub(logger, "warn");
257+
writeFileSyncStub.yields(new Error("Write Failed"));
258+
utils.exportResults("build_id", "build_url");
259+
sinon.assert.calledOnce(writeFileSyncStub);
260+
sinon.assert.calledTwice(loggerWarnStub);
261+
fs.writeFileSync.restore();
262+
});
263+
264+
});
265+
266+
describe("deleteResults", () => {
267+
268+
it("should delete log/build_results.txt", () => {
269+
sinon.stub(fs, 'unlink').returns(true);
270+
utils.deleteResults();
271+
fs.unlink.restore();
272+
});
273+
});
274+
245275
describe("isCypressProjDirValid", () => {
246276
it("should return true when cypressDir and cypressProjDir is same", () =>{
247277
expect(utils.isCypressProjDirValid("/absolute/path","/absolute/path")).to.be.true;

0 commit comments

Comments
 (0)