browserstack-cypress-cli 1.15.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,93 +1,12 @@
1
1
  const fs = require('fs'),
2
2
  path = require('path'),
3
3
  request = require('request'),
4
+ unzipper = require('unzipper'),
4
5
  logger = require('./logger').winstonLogger,
5
6
  utils = require("./utils"),
6
7
  Constants = require('./constants'),
7
8
  config = require("./config");
8
9
 
9
- let templatesDir = path.join(__dirname, '../', 'templates');
10
-
11
- function loadInlineCss() {
12
- return loadFile(path.join(templatesDir, 'assets', 'browserstack-cypress-report.css'));
13
- }
14
-
15
- function loadFile(fileName) {
16
- return fs.readFileSync(fileName, 'utf8');
17
- }
18
-
19
- function createBodyBuildHeader(report_data){
20
- let projectNameSpan = `<span class='project-name'> ${report_data.project_name} </span>`;
21
- let buildNameSpan = `<span class='build-name'> ${report_data.build_name} </span>`;
22
- let buildMeta = `<div class='build-meta'> ${buildNameSpan} ${projectNameSpan} </div>`;
23
- let buildLink = `<div class='build-link'> <a href='${report_data.build_url}' rel='noreferrer noopener' target='_blank'> View on BrowserStack </a> </div>`;
24
- let buildHeader = `<div class='build-header'> ${buildMeta} ${buildLink} </div>`;
25
- return buildHeader;
26
- }
27
-
28
- function createBodyBuildTable(report_data) {
29
- let specs = Object.keys(report_data.rows),
30
- specRow = '',
31
- specSessions = '',
32
- sessionBlocks = '',
33
- specData,
34
- specNameSpan,
35
- specPathSpan,
36
- specStats,
37
- specStatsSpan,
38
- specMeta,
39
- sessionStatus,
40
- sessionClass,
41
- sessionStatusIcon,
42
- sessionLink;
43
-
44
- specs.forEach((specName) => {
45
- specData = report_data.rows[specName];
46
-
47
- specNameSpan = `<span class='spec-name'> ${specName} </span>`;
48
- specPathSpan = `<span class='spec-path'> ${specData.path} </span>`;
49
-
50
- specStats = buildSpecStats(specData.meta);
51
- specStatsSpan = `<span class='spec-stats ${specStats.cssClass}'> ${specStats.label} </span>`;
52
-
53
- specMeta = `<div class='spec-meta'> ${specNameSpan} ${specPathSpan} ${specStatsSpan} </div>`;
54
- sessionBlocks = '';
55
- specData.sessions.forEach((specSession) => {
56
-
57
- sessionStatus = specSession.status;
58
- sessionClass = sessionStatus === 'passed' ? 'session-passed' : 'session-failed';
59
- sessionStatusIcon = sessionStatus === 'passed' ? "&#10004; " : "&#x2717; ";
60
-
61
- sessionLink = `<a href="${specSession.link}" rel="noreferrer noopener" target="_blank"> ${sessionStatusIcon} ${specSession.name} </a>`;
62
-
63
- sessionDetail = `<div class="session-detail ${sessionClass}"> ${sessionLink} </div>`;
64
- sessionBlocks = `${sessionBlocks} ${sessionDetail}`;
65
- });
66
- specSessions = `<div class='spec-sessions'> ${sessionBlocks} </div>`;
67
- specRow = `${specRow} <div class='spec-row'> ${specMeta} ${specSessions} </div>`;
68
- });
69
-
70
-
71
- return `<div class='build-table'> ${specRow} </div>`;
72
- }
73
-
74
- function buildSpecStats(specMeta) {
75
- let failedSpecs = specMeta.failed,
76
- passedSpecs = specMeta.passed,
77
- totalSpecs = specMeta.total,
78
- specStats = {};
79
-
80
- if (failedSpecs) {
81
- specStats.label = `${failedSpecs}/${totalSpecs} FAILED`;
82
- specStats.cssClass = 'spec-stats-failed';
83
- } else {
84
- specStats.label = `${passedSpecs}/${totalSpecs} PASSED`;
85
- specStats.cssClass = 'spec-stats-passed';
86
- }
87
-
88
- return specStats;
89
- }
90
-
91
10
  let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) => {
92
11
  let options = {
93
12
  url: `${config.buildUrl}${buildId}/custom_report`,
@@ -100,6 +19,8 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
100
19
  },
101
20
  };
102
21
 
22
+ logger.debug('Started fetching the build json and html reports.');
23
+
103
24
  return request.get(options, async function (err, resp, body) {
104
25
  let message = null;
105
26
  let messageType = null;
@@ -117,6 +38,7 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
117
38
  utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
118
39
  return;
119
40
  } else {
41
+ logger.debug('Received reports data from upstream.');
120
42
  try {
121
43
  build = JSON.parse(body);
122
44
  } catch (error) {
@@ -127,7 +49,6 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
127
49
  if (resp.statusCode == 299) {
128
50
  messageType = Constants.messageTypes.INFO;
129
51
  errorCode = 'api_deprecated';
130
-
131
52
  if (build) {
132
53
  message = build.message;
133
54
  logger.info(message);
@@ -163,9 +84,10 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
163
84
  } else {
164
85
  messageType = Constants.messageTypes.SUCCESS;
165
86
  message = `Report for build: ${buildId} was successfully created.`;
166
- await renderReportHTML(build);
87
+ await generateCypressBuildReport(build);
167
88
  logger.info(message);
168
89
  }
90
+ logger.debug('Finished fetching the build json and html reports.');
169
91
  utils.sendUsageReport(bsConfig, args, message, messageType, errorCode, buildReportData, rawArgs);
170
92
  if (cb){
171
93
  cb();
@@ -173,199 +95,70 @@ let reportGenerator = (bsConfig, buildId, args, rawArgs, buildReportData, cb) =>
173
95
  });
174
96
  }
175
97
 
176
- async function renderReportHTML(report_data) {
177
- let resultsDir = 'results';
178
- let metaCharSet = `<meta charset="utf-8">`;
179
- let metaViewPort = `<meta name="viewport" content="width=device-width, initial-scale=1"> `;
180
- let pageTitle = `<title> BrowserStack Cypress Report </title>`;
181
- let inlineCss = `<style type="text/css"> ${loadInlineCss()} </style>`;
182
- let head = `<head> ${metaCharSet} ${metaViewPort} ${pageTitle} ${inlineCss} </head>`;
183
- let htmlOpenTag = `<!DOCTYPE HTML><html>`;
184
- let htmlClosetag = `</html>`;
185
- let bodyBuildHeader = createBodyBuildHeader(report_data);
186
- let bodyBuildTable = createBodyBuildTable(report_data);
187
- let bodyReporterContainer = `<div class='report-container'> ${bodyBuildHeader} ${bodyBuildTable} </div>`;
188
- let body = `<body> ${bodyReporterContainer} </body>`;
189
- let html = `${htmlOpenTag} ${head} ${body} ${htmlClosetag}`;
190
-
98
+ async function generateCypressBuildReport(report_data) {
99
+ let resultsDir = path.join('./', 'results');
191
100
 
192
101
  if (!fs.existsSync(resultsDir)){
102
+ logger.debug("Results directory doesn't exists.");
103
+ logger.debug("Creating results directory.");
193
104
  fs.mkdirSync(resultsDir);
194
105
  }
195
-
196
- // Writing the JSON used in creating the HTML file.
197
- let reportData = await cypressReportData(report_data);
198
- fs.writeFileSync(
199
- `${resultsDir}/browserstack-cypress-report.json`,
200
- JSON.stringify(reportData),
201
- () => {
202
- if (err) {
203
- return logger.error(err);
204
- }
205
- logger.info("The JSON file is saved");
206
- }
207
- );
208
-
209
- // Writing the HTML file generated from the JSON data.
210
- fs.writeFileSync(`${resultsDir}/browserstack-cypress-report.html`, html, () => {
211
- if(err) {
212
- return logger.error(err);
213
- }
214
- logger.info("The HTML file was saved!");
215
- });
216
- }
217
-
218
- async function cypressReportData(report_data) {
219
- specFiles = Object.keys(report_data.rows);
220
- combinationPromises = [];
221
- for (let spec of specFiles) {
222
- let specSessions = report_data.rows[spec]["sessions"];
223
- if (specSessions.length > 0) {
224
- for (let combination of specSessions) {
225
- if(utils.isUndefined(report_data.cypress_version) || report_data.cypress_version < "6"){
226
- combinationPromises.push(generateCypressCombinationSpecReportDataWithoutConfigJson(combination));
227
- }else{
228
- combinationPromises.push(generateCypressCombinationSpecReportDataWithConfigJson(combination));
229
- }
230
- }
231
- }
232
- }
233
- await Promise.all(combinationPromises);
234
- return report_data;
106
+ await getReportResponse(resultsDir, 'report.zip', report_data.cypress_custom_report_url);
235
107
  }
236
108
 
237
- function getConfigJsonResponse(combination) {
109
+ function getReportResponse(filePath, fileName, reportJsonUrl) {
110
+ let tmpFilePath = path.join(filePath, fileName);
111
+ const writer = fs.createWriteStream(tmpFilePath);
112
+ logger.debug(`Fetching build reports zip.`)
238
113
  return new Promise(async (resolve, reject) => {
239
- configJsonResponse = null;
240
- configJsonError = false
241
- request.get(combination.tests.config_json , function(err, resp, body) {
242
- if(err) {
243
- configJsonError = true;
244
- reject([configJsonResponse, configJsonError]);
245
- } else {
246
- if(resp.statusCode != 200) {
247
- configJsonError = true;
248
- reject([configJsonResponse, configJsonError]);
249
- } else {
250
- try {
251
- configJsonResponse = JSON.parse(body);
252
- } catch (err) {
253
- configJsonError = true
254
- reject([configJsonResponse, configJsonError]);
255
- }
256
- }
257
- }
258
- resolve([configJsonResponse, configJsonError]);
259
- });
260
- });
261
- }
114
+ request.get(reportJsonUrl).on('response', function(response) {
262
115
 
263
- function getResultsJsonResponse(combination) {
264
- return new Promise(async (resolve, reject) => {
265
- resultsJsonResponse = null
266
- resultsJsonError = false;
267
- request.get(combination.tests.result_json , function(err, resp, body) {
268
- if(err) {
269
- resultsJsonError = true;
270
- reject([resultsJsonResponse, resultsJsonError]);
116
+ if(response.statusCode != 200) {
117
+ let message = `Received non 200 response while fetching reports, code: ${response.statusCode}`;
118
+ reject(message);
271
119
  } else {
272
- if(resp.statusCode != 200) {
273
- resultsJsonError = true;
274
- reject([resultsJsonResponse, resultsJsonError]);
275
- } else {
276
- try {
277
- resultsJsonResponse = JSON.parse(body);
278
- } catch (err) {
279
- resultsJsonError = true
280
- reject([resultsJsonResponse, resultsJsonError]);
281
- }
282
- }
283
- }
284
- resolve([resultsJsonResponse, resultsJsonError]);
285
- });
286
- });
287
- }
288
-
289
- function generateCypressCombinationSpecReportDataWithConfigJson(combination){
290
- return new Promise(async (resolve, reject) => {
291
- try {
292
- let configJsonError, resultsJsonError;
293
- let configJson, resultsJson;
294
-
295
- await Promise.all([getConfigJsonResponse(combination), getResultsJsonResponse(combination)]).then(function (successResult) {
296
- [[configJson, configJsonError], [resultsJson, resultsJsonError]] = successResult;
297
- }).catch(function (failureResult) {
298
- [[configJson, configJsonError], [resultsJson, resultsJsonError]] = failureResult;
299
- });
300
-
301
- if(resultsJsonError || configJsonError){
302
- resolve();
303
- }
304
- let tests = {};
305
- if(utils.isUndefined(configJson.tests) || utils.isUndefined(resultsJson.tests)){
306
- resolve();
307
- }
308
- configJson.tests.forEach((test) => {
309
- tests[test["clientId"]] = test;
120
+ //ensure that the user can call `then()` only when the file has
121
+ //been downloaded entirely.
122
+ response.pipe(writer);
123
+ let error = null;
124
+ writer.on('error', err => {
125
+ error = err;
126
+ writer.close();
127
+ reject(err);
128
+ process.exitCode = Constants.ERROR_EXIT_CODE;
310
129
  });
311
- resultsJson.tests.forEach((test) => {
312
- tests[test["clientId"]] = Object.assign(
313
- tests[test["clientId"]],
314
- test
315
- );
316
- });
317
- let sessionTests = [];
318
- Object.keys(tests).forEach((testId) => {
319
- sessionTests.push({
320
- name: tests[testId]["title"].pop(),
321
- status: tests[testId]["state"],
322
- duration: parseFloat(
323
- tests[testId]["attempts"].pop()["wallClockDuration"] / 1000
324
- ).toFixed(2),
325
- });
130
+ writer.on('close', async () => {
131
+ if (!error) {
132
+ logger.debug("Unzipping downloaded html and json reports.");
133
+ unzipFile(filePath, fileName).then((msg) => {
134
+ logger.debug(msg);
135
+ fs.unlinkSync(tmpFilePath);
136
+ logger.debug("Successfully prepared json and html reports.");
137
+ resolve(true);
138
+ }).catch((err) =>{
139
+ logger.debug(`Unzipping html and json report failed. Error: ${err}`)
140
+ reject(true);
141
+ });
142
+ }
143
+ //no need to call the reject here, as it will have been called in the
144
+ //'error' stream;
326
145
  });
327
- combination.tests = sessionTests;
328
- resolve(combination.tests);
329
- } catch (error) {
330
- process.exitCode = Constants.ERROR_EXIT_CODE;
331
- reject(error);
332
146
  }
333
- })
147
+ });
148
+ });
334
149
  }
335
150
 
336
- function generateCypressCombinationSpecReportDataWithoutConfigJson(combination){
337
- return new Promise(async (resolve, reject) => {
338
- try {
339
- let resultsJson ,resultsJsonError;
340
- await getResultsJsonResponse(combination).then(function (successResult) {
341
- [resultsJson, resultsJsonError] = successResult
342
- }).catch( function (failureResult) {
343
- [resultsJson, resultsJsonError] = failureResult
344
- })
345
- if(resultsJsonError || utils.isUndefined(resultsJsonResponse)){
346
- resolve();
347
- }
348
- let sessionTests = [];
349
- if(utils.isUndefined(resultsJson.tests)){
350
- resolve();
351
- }
352
- resultsJson.tests.forEach((test) => {
353
- durationKey = utils.isUndefined(test["attempts"]) ? test : test["attempts"].pop()
354
- sessionTests.push({
355
- name: test["title"].pop(),
356
- status: test["state"],
357
- duration: parseFloat(
358
- durationKey["wallClockDuration"] / 1000
359
- ).toFixed(2)
360
- })
361
- });
362
- combination.tests = sessionTests;
363
- resolve(combination.tests);
364
- } catch (error) {
151
+ const unzipFile = async (filePath, fileName) => {
152
+ return new Promise( async (resolve, reject) => {
153
+ await unzipper.Open.file(path.join(filePath, fileName))
154
+ .then(d => d.extract({path: filePath, concurrency: 5}))
155
+ .catch((err) => {
156
+ reject(err);
365
157
  process.exitCode = Constants.ERROR_EXIT_CODE;
366
- reject(error);
367
- }
368
- })
158
+ });
159
+ let message = "Unzipped the json and html successfully."
160
+ resolve(message);
161
+ });
369
162
  }
370
163
 
371
164
  exports.reportGenerator = reportGenerator;
@@ -61,9 +61,9 @@ function bstack_json_found_in_pwd() {
61
61
  }
62
62
  }
63
63
 
64
- function cypress_json_found_in_pwd() {
64
+ function cypress_config_file_found_in_pwd(cypress_config_filename) {
65
65
  try {
66
- if (fs.existsSync(path.join(process.cwd(), 'cypress.json'))) {
66
+ if (fs.existsSync(path.join(process.cwd(), cypress_config_filename))) {
67
67
  //file exists
68
68
  return true;
69
69
  }
@@ -244,7 +244,7 @@ function send(args) {
244
244
  os: _os(),
245
245
  os_version: os_version(),
246
246
  bstack_json_found_in_pwd: bstack_json_found_in_pwd(),
247
- cypress_json_found_in_pwd: cypress_json_found_in_pwd(),
247
+ cypress_config_file_found_in_pwd: cypress_config_file_found_in_pwd(runSettings.cypress_config_filename),
248
248
  cli_version: cli_details.version,
249
249
  cli_path: cli_details.path,
250
250
  npm_version: npm_version(),
@@ -57,6 +57,9 @@ exports.getErrorCodeFromMsg = (errMsg) => {
57
57
  case Constants.validationMessages.EMPTY_CYPRESS_PROJ_DIR:
58
58
  errorCode = 'bstack_json_invalid_no_cypress_proj_dir';
59
59
  break;
60
+ case Constants.validationMessages.EMPTY_CYPRESS_CONFIG_FILE:
61
+ errorCode = 'bstack_json_invalid_no_cypress_config_file';
62
+ break;
60
63
  case Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS:
61
64
  errorCode = 'bstack_json_default_auth_keys';
62
65
  break;
@@ -288,13 +291,43 @@ exports.setCypressConfigFilename = (bsConfig, args) => {
288
291
  bsConfig.run_settings.cypressConfigFilePath = bsConfig.run_settings.cypress_config_file;
289
292
  bsConfig.run_settings.cypressProjectDir = path.dirname(bsConfig.run_settings.cypress_config_file);
290
293
  } else {
291
- bsConfig.run_settings.cypressConfigFilePath = path.join(bsConfig.run_settings.cypress_proj_dir, 'cypress.json');
292
- bsConfig.run_settings.cypressProjectDir = bsConfig.run_settings.cypress_proj_dir;
294
+ logger.debug(`Looks like cypress config file was not provided. Looking for ${Constants.CYPRESS_CONFIG_FILE_NAMES.join(", ")} files at ${process.cwd()}`);
295
+ for (const possibleCypressFileName of Constants.CYPRESS_CONFIG_FILE_NAMES) {
296
+ let directoryPath = !this.isUndefined(bsConfig.run_settings.cypress_proj_dir) ? bsConfig.run_settings.cypress_proj_dir : process.cwd();
297
+ if (directoryPath.endsWith("/")) {
298
+ directoryPath = directoryPath.slice(0,-1);
299
+ }
300
+ if (fs.existsSync(path.join(directoryPath, possibleCypressFileName))) {
301
+ bsConfig.run_settings.cypressConfigFilePath = `${directoryPath}/${possibleCypressFileName}`;
302
+ bsConfig.run_settings.cypress_config_file = `${directoryPath}/${possibleCypressFileName}`;
303
+ bsConfig.run_settings.cypress_config_filename = path.basename(bsConfig.run_settings.cypress_config_file);
304
+ bsConfig.run_settings.cypressProjectDir = directoryPath;
305
+ break;
306
+ }
307
+ }
293
308
  }
309
+
294
310
  logger.debug(`Setting cypress config file path = ${bsConfig.run_settings.cypressConfigFilePath}`);
295
311
  logger.debug(`Setting cypress project dir = ${bsConfig.run_settings.cypressProjDir}`);
296
312
  }
297
313
 
314
+ exports.setCypressTestSuiteType = (bsConfig) => {
315
+ for (const possibleCypressFileName of Constants.CYPRESS_CONFIG_FILE_NAMES) {
316
+ if (bsConfig.run_settings.cypressConfigFilePath &&
317
+ typeof(bsConfig.run_settings.cypressConfigFilePath) === 'string' &&
318
+ bsConfig.run_settings.cypressConfigFilePath.endsWith(possibleCypressFileName)) {
319
+ bsConfig.run_settings.cypressTestSuiteType = Constants.CYPRESS_CONFIG_FILE_MAPPING[possibleCypressFileName].type;
320
+ break;
321
+ }
322
+ }
323
+
324
+ if (this.isUndefined(bsConfig.run_settings.cypressTestSuiteType)) {
325
+ bsConfig.run_settings.cypressTestSuiteType = Constants.CYPRESS_V9_AND_OLDER_TYPE;
326
+ }
327
+
328
+ logger.debug(`Setting cypress test suite type as ${bsConfig.run_settings.cypressTestSuiteType}`);
329
+ }
330
+
298
331
  exports.verifyGeolocationOption = () => {
299
332
  let glOptionsSet = (this.searchForOption('-gl') || this.searchForOption('--gl'));
300
333
  let geoHyphenLocationOptionsSet = (this.searchForOption('-geo-location') || this.searchForOption('--geo-location'));
@@ -360,8 +393,10 @@ exports.setProjectId = (bsConfig, args) => {
360
393
  } else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
361
394
  return bsConfig.run_settings["projectId"];
362
395
  } else {
363
- let cypressJson = this.getCypressJSON(bsConfig);
364
- if (!this.isUndefined(cypressJson) && !this.isUndefined(cypressJson["projectId"])) { return cypressJson["projectId"]; }
396
+ let cypressConfigFile = this.getCypressConfigFile(bsConfig);
397
+ if (!this.isUndefined(cypressConfigFile) && !this.isUndefined(cypressConfigFile["projectId"])) {
398
+ return cypressConfigFile["projectId"];
399
+ }
365
400
  }
366
401
  }
367
402
 
@@ -444,6 +479,20 @@ exports.setTestEnvs = (bsConfig, args) => {
444
479
  logger.debug(`Setting env vars = ${bsConfig.run_settings.env}`);
445
480
  }
446
481
 
482
+ exports.setBuildTags = (bsConfig, args) => {
483
+ let buildTag = undefined;
484
+ if(!this.isUndefined(args["build-tag"])) {
485
+ buildTag = args["build-tag"];
486
+ } else {
487
+ buildTag = bsConfig.run_settings.build_tag;
488
+ }
489
+ if(!this.isUndefined(buildTag)) {
490
+ buildTag = buildTag.toString();
491
+ }
492
+ bsConfig.run_settings.build_tag = buildTag;
493
+ logger.debug(`Setting the build tag = ${bsConfig.run_settings.build_tag}`);
494
+ };
495
+
447
496
  exports.setSystemEnvs = (bsConfig) => {
448
497
  let envKeys = {};
449
498
 
@@ -917,8 +966,8 @@ exports.getFilesToIgnore = (runSettings, excludeFiles, logging = true) => {
917
966
  return ignoreFiles;
918
967
  }
919
968
 
920
- exports.getNumberOfSpecFiles = (bsConfig, args, cypressJson) => {
921
- let testFolderPath = cypressJson.integrationFolder || Constants.DEFAULT_CYPRESS_SPEC_PATH;
969
+ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
970
+ let testFolderPath = cypressConfig.integrationFolder || Constants.DEFAULT_CYPRESS_SPEC_PATH;
922
971
  let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs) || `${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`;
923
972
  let ignoreFiles = args.exclude || bsConfig.run_settings.exclude;
924
973
  let files = glob.sync(globSearchPattern, {cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles});
@@ -1076,18 +1125,26 @@ exports.readBsConfigJSON = (bsConfigPath) => {
1076
1125
  }
1077
1126
  }
1078
1127
 
1079
- exports.getCypressJSON = (bsConfig) => {
1080
- let cypressJSON = undefined;
1081
- if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
1082
- cypressJSON = JSON.parse(
1083
- fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath)
1084
- );
1085
- } else if (bsConfig.run_settings.cypressProjectDir) {
1086
- cypressJSON = JSON.parse(
1087
- fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, 'cypress.json'))
1088
- );
1128
+ exports.getCypressConfigFile = (bsConfig) => {
1129
+ let cypressConfigFile = undefined;
1130
+ if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
1131
+ if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) {
1132
+ if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
1133
+ cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
1134
+ } else if (bsConfig.run_settings.cypressProjectDir) {
1135
+ cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename));
1136
+ }
1137
+ } else {
1138
+ cypressConfigFile = {};
1139
+ }
1140
+ } else {
1141
+ if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
1142
+ cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath))
1143
+ } else if (bsConfig.run_settings.cypressProjectDir) {
1144
+ cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)));
1145
+ }
1089
1146
  }
1090
- return cypressJSON;
1147
+ return cypressConfigFile;
1091
1148
  }
1092
1149
 
1093
1150
  exports.setCLIMode = (bsConfig, args) => {
@@ -1221,15 +1278,36 @@ exports.fetchZipSize = (fileName) => {
1221
1278
  }
1222
1279
  }
1223
1280
 
1224
- exports.getVideoConfig = (cypressJson) => {
1281
+ exports.getVideoConfig = (cypressConfig) => {
1225
1282
  let conf = {
1226
1283
  video: true,
1227
1284
  videoUploadOnPasses: true
1228
1285
  }
1229
- if (!this.isUndefined(cypressJson.video)) conf.video = cypressJson.video;
1230
- if (!this.isUndefined(cypressJson.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressJson.videoUploadOnPasses;
1286
+ if (!this.isUndefined(cypressConfig.video)) conf.video = cypressConfig.video;
1287
+ if (!this.isUndefined(cypressConfig.videoUploadOnPasses)) conf.videoUploadOnPasses = cypressConfig.videoUploadOnPasses;
1231
1288
 
1232
1289
  logger.debug(`Setting video = ${conf.video}`);
1233
1290
  logger.debug(`Setting videoUploadOnPasses = ${conf.videoUploadOnPasses}`);
1234
1291
  return conf;
1235
1292
  }
1293
+
1294
+ exports.getMajorVersion = (version) => {
1295
+ try {
1296
+ if (!version || !version.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/)) {
1297
+ return null;
1298
+ }
1299
+
1300
+ const matches = version.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/)
1301
+ if(matches && matches.length >= 2) {
1302
+ if (!matches[1]) {
1303
+ return matches[0];
1304
+ }
1305
+ return matches[1].replace('.','');
1306
+ } else {
1307
+ return null;
1308
+ }
1309
+ } catch(error) {
1310
+ logger.debug(`Some Error occurred while fetching major version of ${version}. Returning null. Error Details: ${error}`)
1311
+ return null;
1312
+ }
1313
+ }
package/bin/runner.js CHANGED
@@ -136,7 +136,7 @@ var argv = yargs
136
136
  'ccf': {
137
137
  alias: 'cypress-config-file',
138
138
  describe: Constants.cliMessages.RUN.CYPRESS_DESC,
139
- default: './cypress.json',
139
+ default: './cypress.config.js',
140
140
  type: 'string',
141
141
  nargs: 1,
142
142
  demand: true,
@@ -271,6 +271,11 @@ var argv = yargs
271
271
  default: undefined,
272
272
  describe: Constants.cliMessages.RUN.NODE_VERSION,
273
273
  type: "string"
274
+ },
275
+ 'build-tag': {
276
+ default: undefined,
277
+ describe: Constants.cliMessages.RUN.BUILD_TAG,
278
+ type: "string"
274
279
  }
275
280
  })
276
281
  .help('help')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.15.0",
3
+ "version": "1.18.0",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,7 +22,7 @@
22
22
  "glob": "7.2.0",
23
23
  "mkdirp": "1.0.4",
24
24
  "request": "2.88.2",
25
- "requestretry": "4.1.2",
25
+ "requestretry": "7.1.0",
26
26
  "table": "5.4.6",
27
27
  "unzipper": "0.10.11",
28
28
  "update-notifier": "5.1.0",
package/log/usage.log DELETED
@@ -1,2 +0,0 @@
1
- {"level":"info","message":"Sending {\"event_type\":\"cypress_cli_stats\",\"data\":{\"bstack_json\":\"null\",\"run_settings\":\"\",\"os\":\"darwin\",\"os_version\":\"21.4.0\",\"bstack_json_found_in_pwd\":false,\"cypress_json_found_in_pwd\":false,\"cli_version\":\"1.13.0\",\"cli_path\":\"/Users/rahulnwn/.nvm/versions/node/v12.18.4/lib/node_modules\",\"npm_version\":\"6.14.6\",\"local_cypress_version\":null,\"ci_environment\":null,\"event_timestamp\":\"4/13/2022, 12:39:15 AM\",\"data\":null,\"raw_args\":[\"run\"],\"cli_args\":{\"_\":[\"run\"],\"cf\":\"browserstack.json\",\"config-file\":\"browserstack.json\",\"configFile\":\"browserstack.json\",\"ccf\":\"./cypress.json\",\"cypress-config-file\":\"./cypress.json\",\"cypressConfigFile\":\"./cypress.json\",\"disable-npm-warning\":false,\"disableNpmWarning\":false,\"sync\":true,\"async\":false,\"force-upload\":false,\"forceUpload\":false,\"headed\":false,\"no-wrap\":false,\"noWrap\":false,\"$0\":\"browserstack-cypress\"},\"message_type\":\"error\",\"error_code\":\"bstack_json_invalid_unknown\"}} to http://127.0.0.1:8000/send_event_cy_internal","timestamp":"2022-04-12T19:09:15.315Z"}
2
- {"level":"info","message":"{\"attempts\":1,\"statusCode\":404}","timestamp":"2022-04-12T19:09:15.365Z"}