Skip to content

Commit

Permalink
log -> resolve/reject while build creation
Browse files Browse the repository at this point in the history
  • Loading branch information
nagpalkaran95 committed May 7, 2020
1 parent 3f61f91 commit 4d37104
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
8 changes: 5 additions & 3 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ function runCypress(args) {
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {

// Create build
build.createBuild(bsConfig, zip).then(function (data) {
build.createBuild(bsConfig, zip).then(function (message) {
logger.info(message);
util.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null);
return;
}).catch(function (err) {
// Build creation failed
logger.error(Constants.userMessages.BUILD_FAILED)
util.sendUsageReport(bsConfig, args, Constants.userMessages.BUILD_FAILED, Constants.messageTypes.ERROR, 'build_failed');
logger.error(err);
util.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
});
}).catch(function (err) {
// Zip Upload failed
Expand Down
6 changes: 3 additions & 3 deletions bin/helpers/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ const archiveSpecs = (runSettings, filePath) => {

archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
logger.info(err)
logger.info(err);
} else {
reject(err)
reject(err);
}
});

output.on('close', function () {
resolve("Zipping completed")
resolve("Zipping completed");
});

output.on('end', function () {
Expand Down
26 changes: 10 additions & 16 deletions bin/helpers/build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';
const request = require('request');

const logger = require("./logger").winstonLogger,
config = require('./config'),
const config = require('./config'),
capabilityHelper = require("../helpers/capabilityHelper"),
Constants = require('../helpers/constants');

Expand All @@ -23,34 +22,29 @@ const createBuild = (bsConfig, zip) => {

request.post(options, function (err, resp, body) {
if (err) {
reject(err)
reject(err);
} else {
let build = null
let build = null;
try {
build = JSON.parse(body)
build = JSON.parse(body);
} catch (error) {
build = null
build = null;
}

if (resp.statusCode == 299) {
if (build) {
logger.info(build.message);
resolve(build.message);
} else {
logger.info(Constants.userMessages.API_DEPRECATED);
reject(Constants.userMessages.API_DEPRECATED);
}
} else if (resp.statusCode != 201) {
if (build) {
logger.error(
`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`
);
reject(`${Constants.userMessages.BUILD_FAILED} Error: ${build.message}`);
} else {
logger.error(Constants.userMessages.BUILD_FAILED);
reject(Constants.userMessages.BUILD_FAILED);
}
} else {
logger.info(build.message);
logger.info(
`${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`
);
resolve(`${build.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
}
resolve(build);
}
Expand Down
2 changes: 1 addition & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const userMessages = {
CONFIG_FILE_CREATED: "BrowserStack Config File created, you can now run browserstack-cypress --config-file run",
CONFIG_FILE_EXISTS: "File already exists, delete the browserstack.json file manually. skipping...",
ZIP_DELETE_FAILED: "Could not delete local file.",
ZIP_DELETED: "File deleted successfully.",
ZIP_DELETED: "Zip file deleted successfully.",
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
FAILED_TO_ZIP: "Failed to zip files."
};
Expand Down

0 comments on commit 4d37104

Please sign in to comment.