Skip to content

Commit

Permalink
Bug fix browserstack-cypress run without browserstack.json
Browse files Browse the repository at this point in the history
- Validates the browserstack.json file for given path.
- Prints error message with instruction to create browserstack.json file.
  • Loading branch information
suryart committed May 11, 2020
1 parent 58e7269 commit 7c1e681
Showing 1 changed file with 35 additions and 28 deletions.
63 changes: 35 additions & 28 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var config = require('../helpers/config');
var capabilityHelper = require("../helpers/capabilityHelper");
var fs = require('fs');
const Constants = require('../helpers/constants');
const fileHelpers = require('../helpers/fileHelpers');

module.exports = function run(args) {
return runCypress(args);
Expand All @@ -18,45 +19,51 @@ function deleteZip() {
logger.log(Constants.userMessages.ZIP_DELETE_FAILED);
} else {
logger.log(Constants.userMessages.ZIP_DELETED);
}
}
});
}

function runCypress(args) {
let bsConfigPath = process.cwd() + args.cf;
logger.log(`Reading config from ${args.cf}`);
var bsConfig = require(bsConfigPath);
fileHelpers.fileExists(bsConfigPath, (configExists) => {
if (configExists) {
var bsConfig = require(bsConfigPath);

// Validate browserstack.json
capabilityHelper.validate(bsConfig).then(function (validated) {
logger.log(validated);
// Archive the spec files
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
// Uploaded zip file
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
// Create build
build.createBuild(bsConfig, zip).then(function (data) {
return;
// Validate browserstack.json
capabilityHelper.validate(bsConfig).then(function (validated) {
logger.log(validated);
// Archive the spec files
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
// Uploaded zip file
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
// Create build
build.createBuild(bsConfig, zip).then(function (data) {
return;
}).catch(function (err) {
// Build creation failed
logger.error(Constants.userMessages.BUILD_FAILED)
});
}).catch(function (err) {
// Zip Upload failed
logger.error(err)
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED)
}).finally(function () {
deleteZip();
});
}).catch(function (err) {
// Build creation failed
logger.error(Constants.userMessages.BUILD_FAILED)
// Zipping failed
logger.error(err)
logger.error(Constants.userMessages.FAILED_TO_ZIP)
deleteZip();
});
}).catch(function (err) {
// Zip Upload failed
// browerstack.json is not valid
logger.error(err)
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED)
}).finally(function () {
deleteZip();
logger.error(Constants.validationMessages.NOT_VALID)
});
}).catch(function (err) {
// Zipping failed
logger.error(err)
logger.error(Constants.userMessages.FAILED_TO_ZIP)
deleteZip();
});
}).catch(function (err) {
// browerstack.json is not valid
logger.error(err)
logger.error(Constants.validationMessages.NOT_VALID)
} else {
logger.error('Could not find browserstack.json, you can create it by running `browserstack-cypress init`');
}
});
}

0 comments on commit 7c1e681

Please sign in to comment.