Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cyp 372 env var #48

Merged
merged 4 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module.exports = function run(args) {
return build.createBuild(bsConfig, zip).then(function (data) {
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
logger.info(message);
logger.info(dashboardLink);
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
Expand Down
11 changes: 11 additions & 0 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const os = require("os");
const path = require("path");
const fs = require("fs");

const usageReporting = require('./usageReporting'),
logger = require('./logger').winstonLogger,
Expand Down Expand Up @@ -120,3 +121,13 @@ exports.configCreated = (args) => {
logger.info(message);
this.sendUsageReport(null, args, message, Constants.messageTypes.SUCCESS, null);
}

exports.exportResults = (buildId, buildUrl) => {
let data = "BUILD_ID=" + buildId + "\nBUILD_URL="+buildUrl;
fs.writeFileSync("log/build_results.txt", data , function(err){
if(err) {
logger.warn(`Couldn't write BUILD_ID with value: ${buildId} to browserstack/build_results.txt`);
logger.warn(`Couldn't write BUILD_URL with value: ${buildUrl} to browserstack/build_results.txt`);
}
});
}
5 changes: 4 additions & 1 deletion test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ describe("runs", () => {
zipUploadStub = sandbox.stub();
createBuildStub = sandbox.stub();
deleteZipStub = sandbox.stub();
exportResultsStub = sandbox.stub();
});

afterEach(() => {
Expand All @@ -458,7 +459,8 @@ describe("runs", () => {
setBuildName: setBuildNameStub,
setUsageReportingFlag: setUsageReportingFlagStub,
setParallels: setParallelsStub,
getConfigPath: getConfigPathStub
getConfigPath: getConfigPathStub,
exportResults: exportResultsStub
},
"../helpers/capabilityHelper": {
validate: capabilityValidatorStub,
Expand Down Expand Up @@ -502,6 +504,7 @@ describe("runs", () => {
sinon.assert.calledOnce(setUsageReportingFlagStub);
sinon.assert.calledOnce(zipUploadStub);
sinon.assert.calledOnce(createBuildStub);
sinon.assert.calledOnce(exportResultsStub);

sinon.assert.calledOnceWithExactly(
sendUsageReportStub,
Expand Down
23 changes: 22 additions & 1 deletion test/unit/bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ const path = require('path');
const chai = require("chai"),
expect = chai.expect,
sinon = require('sinon'),
chaiAsPromised = require("chai-as-promised");
chaiAsPromised = require("chai-as-promised"),
fs = require('fs');

const utils = require('../../../../bin/helpers/utils'),
constant = require('../../../../bin/helpers/constants'),
Expand Down Expand Up @@ -236,4 +237,24 @@ describe("utils", () => {
sinon.assert.calledOnce(sendUsageReportStub);
});
});

describe("exportResults", () => {

it("should export results to log/build_results.txt", () => {
sinon.stub(fs, 'writeFileSync').returns(true);
utils.exportResults("build_id", "build_url");
fs.writeFileSync.restore();
});

it("should log warning if write to log/build_results.txt fails", () => {
let writeFileSyncStub = sinon.stub(fs, 'writeFileSync');
let loggerWarnStub = sinon.stub(logger, "warn");
writeFileSyncStub.yields(new Error("Write Failed"));
utils.exportResults("build_id", "build_url");
sinon.assert.calledOnce(writeFileSyncStub);
sinon.assert.calledTwice(loggerWarnStub);
fs.writeFileSync.restore();
});

});
});