Skip to content

Commit

Permalink
Merge branch 'master' into deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
suryart committed Nov 9, 2020
2 parents de131c2 + 16ec8a2 commit c337d44
Show file tree
Hide file tree
Showing 11 changed files with 643 additions and 419 deletions.
12 changes: 7 additions & 5 deletions bin/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = function info(args) {
let bsConfigPath = utils.getConfigPath(args.cf);

return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
utils.setDefaults(bsConfig, args);

// accept the username from command line if provided
utils.setUsername(bsConfig, args);

Expand All @@ -30,7 +32,7 @@ module.exports = function info(args) {
password: bsConfig.auth.access_key,
},
headers: {
"User-Agent": utils.getUserAgent(),
'User-Agent': utils.getUserAgent(),
},
};

Expand All @@ -55,7 +57,7 @@ module.exports = function info(args) {

if (resp.statusCode == 299) {
messageType = Constants.messageTypes.INFO;
errorCode = "api_deprecated";
errorCode = 'api_deprecated';

if (build) {
message = build.message;
Expand All @@ -66,14 +68,14 @@ module.exports = function info(args) {
}
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = "api_failed_build_info";
errorCode = 'api_failed_build_info';

if (build) {
message = `${
Constants.userMessages.BUILD_INFO_FAILED
} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
} else {
message = Constants.userMessages.BUILD_INFO_FAILED;
logger.error(message);
Expand All @@ -89,7 +91,7 @@ module.exports = function info(args) {
}
}
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
})
});
}).catch(function (err) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
Expand Down
2 changes: 2 additions & 0 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ module.exports = function run(args) {
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);

utils.setDefaults(bsConfig, args);

// accept the username from command line or env variable if provided
utils.setUsername(bsConfig, args);

Expand Down
18 changes: 10 additions & 8 deletions bin/commands/stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ module.exports = function stop(args) {
let bsConfigPath = utils.getConfigPath(args.cf);

return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
utils.setDefaults(bsConfig, args);

// accept the username from command line if provided
utils.setUsername(bsConfig, args);

Expand All @@ -30,7 +32,7 @@ module.exports = function stop(args) {
password: bsConfig.auth.access_key,
},
headers: {
"User-Agent": utils.getUserAgent(),
'User-Agent': utils.getUserAgent(),
},
};

Expand All @@ -46,16 +48,16 @@ module.exports = function stop(args) {

logger.info(message);
} 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) {
messageType = Constants.messageTypes.INFO;
errorCode = "api_deprecated";
errorCode = 'api_deprecated';

if (build) {
message = build.message;
Expand All @@ -66,14 +68,14 @@ module.exports = function stop(args) {
}
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = "api_failed_build_stop";
errorCode = 'api_failed_build_stop';

if (build) {
message = `${
Constants.userMessages.BUILD_STOP_FAILED
} with error: \n${JSON.stringify(build, null, 2)}`;
logger.error(message);
if (build.message === "Unauthorized") errorCode = "api_auth_failed";
if (build.message === 'Unauthorized') errorCode = 'api_auth_failed';
} else {
message = Constants.userMessages.BUILD_STOP_FAILED;
logger.error(message);
Expand All @@ -85,7 +87,7 @@ module.exports = function stop(args) {
}
}
utils.sendUsageReport(bsConfig, args, message, messageType, errorCode);
})
});
}).catch(function (err) {
logger.error(err);
utils.setUsageReportingFlag(null, args.disableUsageReporting);
Expand Down
2 changes: 1 addition & 1 deletion bin/helpers/archiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
let ignoreFiles = getFilesToIgnore(runSettings, excludeFiles);

Constants.allowedFileTypes.forEach(fileType => {
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles });
archive.glob(`**/*.${fileType}`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles, dot:true });
});

let packageJSON = {};
Expand Down
4 changes: 2 additions & 2 deletions bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ const messageTypes = {
NULL: null
}

const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip'];
const allowedFileTypes = ['js', 'json', 'txt', 'ts', 'feature', 'features', 'pdf', 'jpg', 'jpeg', 'png', 'zip', 'npmrc'];

const filesToIgnoreWhileUploading = ['node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip', 'cypress.json']
const filesToIgnoreWhileUploading = ['**/node_modules/**', 'node_modules/**', 'package-lock.json', 'package.json', 'browserstack-package.json', 'tests.zip', 'cypress.json']

module.exports = Object.freeze({
userMessages,
Expand Down
16 changes: 14 additions & 2 deletions bin/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ exports.setParallels = (bsConfig, args) => {
}
};

exports.setDefaults = (bsConfig, args) => {
// setting setDefaultAuthHash to {} if not present and set via env variables or via args.
if (this.isUndefined(bsConfig['auth']) && (!this.isUndefined(args.username) || !this.isUndefined(process.env.BROWSERSTACK_USERNAME))) {
bsConfig['auth'] = {};
}

// setting npm_dependencies to {} if not present
if (bsConfig.run_settings && this.isUndefined(bsConfig.run_settings.npm_dependencies)) {
bsConfig.run_settings.npm_dependencies = {}
}
}

exports.setUsername = (bsConfig, args) => {
if (!this.isUndefined(args.username)) {
bsConfig["auth"]["username"] = args.username;
Expand Down Expand Up @@ -270,8 +282,8 @@ exports.isCypressProjDirValid = (cypressProjDir, integrationFoldDir) => {
integrationFolderDir = path.resolve(path.join(cypressProjDir, integrationFoldDir));
}
if (integrationFolderDir === cypressDir) return true;
let parentTokens = cypressDir.split("/").filter((i) => i.length);
let childTokens = integrationFolderDir.split("/").filter((i) => i.length);
let parentTokens = cypressDir.split(path.sep).filter((i) => i.length);
let childTokens = integrationFolderDir.split(path.sep).filter((i) => i.length);
return parentTokens.every((t, i) => childTokens[i] === t);
};

Expand Down
Loading

0 comments on commit c337d44

Please sign in to comment.