Skip to content

Commit 7dbd8c0

Browse files
committed
Merge branch 'master' into specs-option
2 parents 3500d6e + 356d9ce commit 7dbd8c0

File tree

5 files changed

+78
-10
lines changed

5 files changed

+78
-10
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ const archiveSpecs = (runSettings, filePath) => {
3636

3737
archive.pipe(output);
3838

39-
let allowedFileTypes = [ 'js', 'json', 'txt', 'ts', 'feature', 'features' ];
39+
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'] });
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,
@@ -166,6 +167,21 @@ exports.configCreated = (args) => {
166167
this.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
167168
}
168169

170+
exports.exportResults = (buildId, buildUrl) => {
171+
let data = "BUILD_ID=" + buildId + "\nBUILD_URL="+buildUrl;
172+
fs.writeFileSync("log/build_results.txt", data , function(err){
173+
if(err) {
174+
logger.warn(`Couldn't write BUILD_ID with value: ${buildId} to browserstack/build_results.txt`);
175+
logger.warn(`Couldn't write BUILD_URL with value: ${buildUrl} to browserstack/build_results.txt`);
176+
}
177+
});
178+
}
179+
180+
exports.deleteResults = () => {
181+
fs.unlink("log/build_results.txt", function (err){
182+
});
183+
}
184+
169185
exports.isCypressProjDirValid = (cypressDir, cypressProjDir) => {
170186
// Getting absolute path
171187
cypressDir = path.resolve(cypressDir);

test/unit/bin/commands/runs.js

Lines changed: 26 additions & 7 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
});
9295
getErrorCodeFromMsgStub = sandbox.stub().returns("random-error-code");
9396
capabilityValidatorStub = sandbox.stub();
97+
deleteResultsStub = sandbox.stub();
9498
});
9599

96100
afterEach(() => {
@@ -114,7 +118,8 @@ describe("runs", () => {
114118
setBuildName: setBuildNameStub,
115119
setUserSpecs: setUserSpecsStub,
116120
setTestEnvs: setTestEnvsStub,
117-
getConfigPath: getConfigPathStub
121+
getConfigPath: getConfigPathStub,
122+
deleteResults: deleteResultsStub
118123
},
119124
"../helpers/capabilityHelper": {
120125
validate: capabilityValidatorStub,
@@ -135,6 +140,7 @@ describe("runs", () => {
135140
sinon.assert.calledOnce(capabilityValidatorStub);
136141
sinon.assert.calledOnce(setUsageReportingFlagStub);
137142
sinon.assert.calledOnce(getErrorCodeFromMsgStub);
143+
sinon.assert.calledOnce(deleteResultsStub);
138144
sinon.assert.calledOnceWithExactly(
139145
sendUsageReportStub,
140146
bsConfig,
@@ -167,6 +173,7 @@ describe("runs", () => {
167173
capabilityValidatorStub = sandbox.stub();
168174
archiverStub = sandbox.stub();
169175
deleteZipStub = sandbox.stub();
176+
deleteResultsStub = sandbox.stub();
170177
});
171178

172179
afterEach(() => {
@@ -190,7 +197,8 @@ describe("runs", () => {
190197
setUserSpecs: setUserSpecsStub,
191198
setTestEnvs: setTestEnvsStub,
192199
setUsageReportingFlag: setUsageReportingFlagStub,
193-
getConfigPath: getConfigPathStub
200+
getConfigPath: getConfigPathStub,
201+
deleteResults: deleteResultsStub
194202
},
195203
"../helpers/capabilityHelper": {
196204
validate: capabilityValidatorStub,
@@ -220,6 +228,7 @@ describe("runs", () => {
220228
sinon.assert.calledOnce(archiverStub);
221229
sinon.assert.calledOnce(setUsageReportingFlagStub);
222230
sinon.assert.calledOnce(deleteZipStub);
231+
sinon.assert.calledOnce(deleteResultsStub);
223232
sinon.assert.calledOnceWithExactly(
224233
sendUsageReportStub,
225234
bsConfig,
@@ -253,6 +262,7 @@ describe("runs", () => {
253262
archiverStub = sandbox.stub();
254263
zipUploadStub = sandbox.stub();
255264
deleteZipStub = sandbox.stub();
265+
deleteResultsStub = sandbox.stub();
256266
});
257267

258268
afterEach(() => {
@@ -276,7 +286,8 @@ describe("runs", () => {
276286
setUserSpecs: setUserSpecsStub,
277287
setTestEnvs: setTestEnvsStub,
278288
setUsageReportingFlag: setUsageReportingFlagStub,
279-
getConfigPath: getConfigPathStub
289+
getConfigPath: getConfigPathStub,
290+
deleteResults: deleteResultsStub
280291
},
281292
"../helpers/capabilityHelper": {
282293
validate: capabilityValidatorStub,
@@ -310,7 +321,7 @@ describe("runs", () => {
310321
sinon.assert.calledOnce(archiverStub);
311322
sinon.assert.calledOnce(setUsageReportingFlagStub);
312323
sinon.assert.calledOnce(zipUploadStub);
313-
324+
sinon.assert.calledOnce(deleteResultsStub);
314325
sinon.assert.calledOnceWithExactly(
315326
sendUsageReportStub,
316327
bsConfig,
@@ -348,6 +359,7 @@ describe("runs", () => {
348359
zipUploadStub = sandbox.stub();
349360
createBuildStub = sandbox.stub();
350361
deleteZipStub = sandbox.stub();
362+
deleteResultsStub = sandbox.stub();
351363
});
352364

353365
afterEach(() => {
@@ -371,7 +383,8 @@ describe("runs", () => {
371383
setUserSpecs: setUserSpecsStub,
372384
setTestEnvs: setTestEnvsStub,
373385
setUsageReportingFlag: setUsageReportingFlagStub,
374-
getConfigPath: getConfigPathStub
386+
getConfigPath: getConfigPathStub,
387+
deleteResults: deleteResultsStub
375388
},
376389
"../helpers/capabilityHelper": {
377390
validate: capabilityValidatorStub,
@@ -414,6 +427,7 @@ describe("runs", () => {
414427
sinon.assert.calledOnce(createBuildStub);
415428

416429
sinon.assert.calledOnce(sendUsageReportStub);
430+
sinon.assert.calledOnce(deleteResultsStub);
417431

418432
sinon.assert.calledOnceWithExactly(
419433
sendUsageReportStub,
@@ -454,6 +468,8 @@ describe("runs", () => {
454468
zipUploadStub = sandbox.stub();
455469
createBuildStub = sandbox.stub();
456470
deleteZipStub = sandbox.stub();
471+
exportResultsStub = sandbox.stub();
472+
deleteResultsStub = sandbox.stub();
457473
isUndefinedStub = sandbox.stub();
458474
});
459475

@@ -480,6 +496,8 @@ describe("runs", () => {
480496
setUsageReportingFlag: setUsageReportingFlagStub,
481497
setParallels: setParallelsStub,
482498
getConfigPath: getConfigPathStub,
499+
exportResults: exportResultsStub,
500+
deleteResults: deleteResultsStub,
483501
isUndefined: isUndefinedStub
484502
},
485503
"../helpers/capabilityHelper": {
@@ -524,7 +542,8 @@ describe("runs", () => {
524542
sinon.assert.calledOnce(setUsageReportingFlagStub);
525543
sinon.assert.calledOnce(zipUploadStub);
526544
sinon.assert.calledOnce(createBuildStub);
527-
545+
sinon.assert.calledOnce(exportResultsStub);
546+
sinon.assert.calledOnce(deleteResultsStub);
528547
sinon.assert.calledOnceWithExactly(
529548
sendUsageReportStub,
530549
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'),
@@ -447,6 +448,35 @@ describe("utils", () => {
447448
});
448449
});
449450

451+
describe("exportResults", () => {
452+
453+
it("should export results to log/build_results.txt", () => {
454+
sinon.stub(fs, 'writeFileSync').returns(true);
455+
utils.exportResults("build_id", "build_url");
456+
fs.writeFileSync.restore();
457+
});
458+
459+
it("should log warning if write to log/build_results.txt fails", () => {
460+
let writeFileSyncStub = sinon.stub(fs, 'writeFileSync');
461+
let loggerWarnStub = sinon.stub(logger, "warn");
462+
writeFileSyncStub.yields(new Error("Write Failed"));
463+
utils.exportResults("build_id", "build_url");
464+
sinon.assert.calledOnce(writeFileSyncStub);
465+
sinon.assert.calledTwice(loggerWarnStub);
466+
fs.writeFileSync.restore();
467+
});
468+
469+
});
470+
471+
describe("deleteResults", () => {
472+
473+
it("should delete log/build_results.txt", () => {
474+
sinon.stub(fs, 'unlink').returns(true);
475+
utils.deleteResults();
476+
fs.unlink.restore();
477+
});
478+
});
479+
450480
describe("isCypressProjDirValid", () => {
451481
it("should return true when cypressDir and cypressProjDir is same", () =>{
452482
expect(utils.isCypressProjDirValid("/absolute/path","/absolute/path")).to.be.true;

0 commit comments

Comments
 (0)