Skip to content

Commit 4724130

Browse files
committed
Merge branch 'master' into deploy
2 parents 9303249 + 79fc46d commit 4724130

26 files changed

+1698
-237
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ package-lock.json
88
.env.*
99
log/*.log
1010
results/*
11+
coverage

bin/commands/runs.js

Lines changed: 125 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ const archiver = require("../helpers/archiver"),
99
utils = require("../helpers/utils"),
1010
fileHelpers = require("../helpers/fileHelpers"),
1111
syncRunner = require("../helpers/syncRunner"),
12-
reportGenerator = require('../helpers/reporterHTML').reportGenerator;
12+
checkUploaded = require("../helpers/checkUploaded"),
13+
reportGenerator = require('../helpers/reporterHTML').reportGenerator,
14+
{initTimeComponents, markBlockStart, markBlockEnd, getTimeComponents} = require('../helpers/timeComponents');
1315

1416
module.exports = function run(args) {
1517
let bsConfigPath = utils.getConfigPath(args.cf);
1618
//Delete build_results.txt from log folder if already present.
19+
initTimeComponents();
20+
markBlockStart('deleteOldResults');
1721
utils.deleteResults();
22+
markBlockEnd('deleteOldResults');
1823

24+
markBlockStart('validateBstackJson');
1925
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
26+
markBlockEnd('validateBstackJson');
27+
markBlockStart('setConfig');
2028
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
2129

2230
utils.setDefaults(bsConfig, args);
@@ -39,6 +47,9 @@ module.exports = function run(args) {
3947
// accept the env list from command line and set it
4048
utils.setTestEnvs(bsConfig, args);
4149

50+
// accept the system env list from bsconf and set it
51+
utils.setSystemEnvs(bsConfig);
52+
4253
//accept the local from env variable if provided
4354
utils.setLocal(bsConfig, args);
4455

@@ -54,91 +65,137 @@ module.exports = function run(args) {
5465
// run test in headed mode
5566
utils.setHeaded(bsConfig, args);
5667

68+
// set the no-wrap
69+
utils.setNoWrap(bsConfig, args);
70+
markBlockEnd('setConfig');
71+
5772
// Validate browserstack.json values and parallels specified via arguments
73+
markBlockStart('validateConfig');
5874
return capabilityHelper.validate(bsConfig, args).then(function (cypressJson) {
59-
75+
markBlockEnd('validateConfig');
76+
markBlockStart('preArchiveSteps');
6077
//get the number of spec files
6178
let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressJson);
6279

6380
// accept the number of parallels
6481
utils.setParallels(bsConfig, args, specFiles.length);
6582

66-
// Archive the spec files
67-
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude).then(function (data) {
68-
69-
// Uploaded zip file
70-
return zipUploader.zipUpload(bsConfig, config.fileName).then(async function (zip) {
71-
// Create build
72-
73-
//setup Local Testing
74-
let bs_local = await utils.setupLocalTesting(bsConfig, args);
75-
76-
return build.createBuild(bsConfig, zip).then(function (data) {
77-
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
78-
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
79-
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
80-
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) {
81-
logger.warn(Constants.userMessages.NO_PARALLELS);
82-
}
83-
84-
if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
85-
let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version)
86-
logger.warn(versionMessage);
87-
}
88-
89-
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
90-
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
91-
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
92-
}
93-
94-
if (args.sync) {
95-
syncRunner.pollBuildStatus(bsConfig, data).then(async (exitCode) => {
96-
97-
// stop the Local instance
98-
await utils.stopLocalBinary(bsConfig, bs_local, args);
99-
100-
// Generate custom report!
101-
reportGenerator(bsConfig, data.build_id, args, function(){
102-
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
103-
utils.handleSyncExit(exitCode, data.dashboard_url);
83+
// warn if specFiles cross our limit
84+
utils.warnSpecLimit(bsConfig, args, specFiles);
85+
markBlockEnd('preArchiveSteps');
86+
markBlockStart('checkAlreadyUploaded');
87+
return checkUploaded.checkUploadedMd5(bsConfig, args).then(function (md5data) {
88+
markBlockEnd('checkAlreadyUploaded');
89+
90+
// Archive the spec files
91+
markBlockStart('zip');
92+
markBlockStart('zip.archive');
93+
return archiver.archive(bsConfig.run_settings, config.fileName, args.exclude, md5data).then(function (data) {
94+
markBlockEnd('zip.archive');
95+
96+
// Uploaded zip file
97+
markBlockStart('zip.zipUpload');
98+
return zipUploader.zipUpload(bsConfig, config.fileName, md5data).then(async function (zip) {
99+
markBlockEnd('zip.zipUpload');
100+
markBlockEnd('zip');
101+
// Create build
102+
103+
//setup Local Testing
104+
markBlockStart('localSetup');
105+
let bs_local = await utils.setupLocalTesting(bsConfig, args);
106+
markBlockEnd('localSetup');
107+
markBlockStart('createBuild');
108+
return build.createBuild(bsConfig, zip).then(function (data) {
109+
markBlockEnd('createBuild');
110+
markBlockEnd('total');
111+
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
112+
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${data.dashboard_url}`;
113+
utils.exportResults(data.build_id, `${config.dashboardUrl}${data.build_id}`);
114+
if ((utils.isUndefined(bsConfig.run_settings.parallels) && utils.isUndefined(args.parallels)) || (!utils.isUndefined(bsConfig.run_settings.parallels) && bsConfig.run_settings.parallels == Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE)) {
115+
logger.warn(Constants.userMessages.NO_PARALLELS);
116+
}
117+
118+
if (bsConfig.run_settings.cypress_version && bsConfig.run_settings.cypress_version !== data.cypress_version) {
119+
if (bsConfig.run_settings.cypress_version.toString().match(Constants.LATEST_VERSION_SYNTAX_REGEX)) {
120+
let versionMessage = utils.latestSyntaxToActualVersionMessage(bsConfig.run_settings.cypress_version, data.cypress_version);
121+
logger.info(versionMessage);
122+
} else {
123+
let versionMessage = utils.versionChangedMessage(bsConfig.run_settings.cypress_version, data.cypress_version);
124+
logger.warn(versionMessage);
125+
}
126+
}
127+
128+
if (!args.disableNpmWarning && bsConfig.run_settings.npm_dependencies && Object.keys(bsConfig.run_settings.npm_dependencies).length <= 0) {
129+
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES);
130+
logger.warn(Constants.userMessages.NO_NPM_DEPENDENCIES_READ_MORE);
131+
}
132+
133+
if (args.sync) {
134+
syncRunner.pollBuildStatus(bsConfig, data).then(async (exitCode) => {
135+
136+
// stop the Local instance
137+
await utils.stopLocalBinary(bsConfig, bs_local, args);
138+
139+
// Generate custom report!
140+
reportGenerator(bsConfig, data.build_id, args, function(){
141+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
142+
utils.handleSyncExit(exitCode, data.dashboard_url);
143+
});
104144
});
105-
});
106-
}
107-
108-
logger.info(message);
109-
logger.info(dashboardLink);
110-
if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
111-
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
112-
return;
113-
}).catch(async function (err) {
114-
// Build creation failed
145+
}
146+
147+
logger.info(message);
148+
logger.info(dashboardLink);
149+
if(!args.sync) logger.info(Constants.userMessages.EXIT_SYNC_CLI_MESSAGE.replace("<build-id>",data.build_id));
150+
let dataToSend = {
151+
time_components: getTimeComponents(),
152+
build_id: data.build_id,
153+
};
154+
if (bsConfig && bsConfig.connection_settings) {
155+
if (bsConfig.connection_settings.local_mode) {
156+
dataToSend.local_mode = bsConfig.connection_settings.local_mode;
157+
}
158+
if (bsConfig.connection_settings.usedAutoLocal) {
159+
dataToSend.used_auto_local = bsConfig.connection_settings.usedAutoLocal;
160+
}
161+
}
162+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null, dataToSend);
163+
return;
164+
}).catch(async function (err) {
165+
// Build creation failed
166+
logger.error(err);
167+
// stop the Local instance
168+
await utils.stopLocalBinary(bsConfig, bs_local, args);
169+
170+
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
171+
});
172+
}).catch(function (err) {
173+
// Zip Upload failed | Local Start failed
115174
logger.error(err);
116-
// stop the Local instance
117-
await utils.stopLocalBinary(bsConfig, bs_local, args);
118-
119-
utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'build_failed');
175+
if(err === Constants.userMessages.LOCAL_START_FAILED){
176+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');
177+
} else {
178+
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
179+
fileHelpers.deleteZip();
180+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
181+
}
120182
});
121183
}).catch(function (err) {
122-
// Zip Upload failed | Local Start failed
184+
// Zipping failed
123185
logger.error(err);
124-
if(err === Constants.userMessages.LOCAL_START_FAILED){
125-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.LOCAL_START_FAILED}`, Constants.messageTypes.ERROR, 'local_start_failed');
126-
} else {
127-
logger.error(Constants.userMessages.ZIP_UPLOAD_FAILED);
186+
logger.error(Constants.userMessages.FAILED_TO_ZIP);
187+
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
188+
try {
128189
fileHelpers.deleteZip();
129-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.ZIP_UPLOAD_FAILED}`, Constants.messageTypes.ERROR, 'zip_upload_failed');
190+
} catch (err) {
191+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
130192
}
131193
});
132194
}).catch(function (err) {
133-
// Zipping failed
195+
// md5 check failed
134196
logger.error(err);
135-
logger.error(Constants.userMessages.FAILED_TO_ZIP);
136-
utils.sendUsageReport(bsConfig, args, `${err}\n${Constants.userMessages.FAILED_TO_ZIP}`, Constants.messageTypes.ERROR, 'zip_creation_failed');
137-
try {
138-
fileHelpers.deleteZip();
139-
} catch (err) {
140-
utils.sendUsageReport(bsConfig, args, Constants.userMessages.ZIP_DELETE_FAILED, Constants.messageTypes.ERROR, 'zip_deletion_failed');
141-
}
197+
logger.error(Constants.userMessages.FAILED_MD5_CHECK);
198+
utils.sendUsageReport(bsConfig, args, Constants.userMessages.MD5_CHECK_FAILED, Constants.messageTypes.ERROR, 'zip_already_uploaded_failed');
142199
});
143200
}).catch(function (err) {
144201
// browerstack.json is not valid

bin/helpers/archiver.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ const archiver = require("archiver"),
77
utils = require('../helpers/utils'),
88
path = require('path');
99

10-
const archiveSpecs = (runSettings, filePath, excludeFiles) => {
10+
const archiveSpecs = (runSettings, filePath, excludeFiles, md5data) => {
1111
return new Promise(function (resolve, reject) {
12+
if (md5data.zipUrlPresent) {
13+
return resolve('Zipping not required');
14+
}
1215
var output = fs.createWriteStream(filePath);
1316

1417
var cypressFolderPath = path.dirname(runSettings.cypressConfigFilePath);
@@ -41,8 +44,7 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
4144

4245
archive.pipe(output);
4346

44-
let ignoreFiles = getFilesToIgnore(runSettings, excludeFiles);
45-
47+
let ignoreFiles = utils.getFilesToIgnore(runSettings, excludeFiles);
4648
archive.glob(`**/*.+(${Constants.allowedFileTypes.join("|")})`, { cwd: cypressFolderPath, matchBase: true, ignore: ignoreFiles, dot:true });
4749

4850
let packageJSON = {};
@@ -78,21 +80,4 @@ const archiveSpecs = (runSettings, filePath, excludeFiles) => {
7880
});
7981
}
8082

81-
const getFilesToIgnore = (runSettings, excludeFiles) => {
82-
let ignoreFiles = Constants.filesToIgnoreWhileUploading;
83-
84-
// exclude files asked by the user
85-
// args will take precedence over config file
86-
if (!utils.isUndefined(excludeFiles)) {
87-
let excludePatterns = utils.fixCommaSeparatedString(excludeFiles).split(',');
88-
ignoreFiles = ignoreFiles.concat(excludePatterns);
89-
logger.info(`Excluding files matching: ${JSON.stringify(excludePatterns)}`);
90-
} else if (!utils.isUndefined(runSettings.exclude) && runSettings.exclude.length) {
91-
ignoreFiles = ignoreFiles.concat(runSettings.exclude);
92-
logger.info(`Excluding files matching: ${JSON.stringify(runSettings.exclude)}`);
93-
}
94-
95-
return ignoreFiles;
96-
}
97-
9883
exports.archive = archiveSpecs

bin/helpers/capabilityHelper.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,18 @@ const caps = (bsConfig, zip) => {
9393
obj.projectNotifyURL = null;
9494

9595
if (bsConfig.run_settings) {
96-
obj.project = bsConfig.run_settings.project || bsConfig.run_settings.project_name;
97-
obj.customBuildName = bsConfig.run_settings.build_name || bsConfig.run_settings.customBuildName;
96+
obj.project = bsConfig.run_settings.project || bsConfig.run_settings.project_name || obj.project;
97+
obj.customBuildName = bsConfig.run_settings.build_name || bsConfig.run_settings.customBuildName || obj.customBuildName;
9898
obj.callbackURL = bsConfig.run_settings.callback_url;
9999
obj.projectNotifyURL = bsConfig.run_settings.project_notify_URL;
100100
obj.parallels = bsConfig.run_settings.parallels;
101101

102-
if (!Utils.isUndefined(bsConfig.run_settings.cypress_config_filename)) {
103-
obj.cypress_config_filename = bsConfig.run_settings.cypress_config_filename;
104-
}
105-
106-
if (!Utils.isUndefined(bsConfig.run_settings.specs)){
107-
obj.specs = bsConfig.run_settings.specs;
108-
}
109-
110-
if (!Utils.isUndefined(bsConfig.run_settings.env)){
111-
obj.env = bsConfig.run_settings.env;
112-
}
113-
if (!Utils.isUndefined(bsConfig.run_settings.cypress_version)){
114-
obj.cypress_version = bsConfig.run_settings.cypress_version;
115-
}
116-
117-
if (!Utils.isUndefined(bsConfig.run_settings.headless) && String(bsConfig.run_settings.headless) === "false"){
118-
obj.headless = bsConfig.run_settings.headless;
119-
} else {
102+
if (!(!Utils.isUndefined(bsConfig.run_settings.headless) && String(bsConfig.run_settings.headless) === "false")) {
120103
logger.info(`Running your tests in headless mode. Use --headed arg to run in headful mode.`);
121104
}
105+
106+
// send run_settings as is for other capabilities
107+
obj.run_settings = JSON.stringify(bsConfig.run_settings);
122108
}
123109

124110
if(obj.parallels === Constants.cliMessages.RUN.DEFAULT_PARALLEL_MESSAGE) obj.parallels = undefined

0 commit comments

Comments
 (0)