browserstack-cypress-cli 1.27.0 → 1.28.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.
@@ -38,6 +38,11 @@ module.exports = function info(args, rawArgs) {
38
38
  'User-Agent': utils.getUserAgent(),
39
39
  },
40
40
  };
41
+
42
+ if (Constants.turboScaleObj.enabled) {
43
+ options.url = `${config.turboScaleBuildsUrl}/${buildId}`;
44
+ }
45
+
41
46
  request.get(options, function (err, resp, body) {
42
47
  let message = null;
43
48
  let messageType = null;
@@ -36,6 +36,7 @@ const {
36
36
  checkAccessibilityPlatform,
37
37
  supportFileCleanup
38
38
  } = require('../accessibility-automation/helper');
39
+ const { isTurboScaleSession, getTurboScaleGridDetails, patchCypressConfigFileContent, atsFileCleanup } = require('../helpers/atsHelper');
39
40
 
40
41
  module.exports = function run(args, rawArgs) {
41
42
 
@@ -66,6 +67,8 @@ module.exports = function run(args, rawArgs) {
66
67
  const [isTestObservabilitySession, isBrowserstackInfra] = setTestObservabilityFlags(bsConfig);
67
68
  const checkAccessibility = checkAccessibilityPlatform(bsConfig);
68
69
  const isAccessibilitySession = bsConfig.run_settings.accessibility || checkAccessibility;
70
+ const turboScaleSession = isTurboScaleSession(bsConfig);
71
+ Constants.turboScaleObj.enabled = turboScaleSession;
69
72
 
70
73
  utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
71
74
 
@@ -77,7 +80,7 @@ module.exports = function run(args, rawArgs) {
77
80
  // accept the access key from command line or env variable if provided
78
81
  utils.setAccessKey(bsConfig, args);
79
82
 
80
- let buildReportData = !isBrowserstackInfra ? null : await getInitialDetails(bsConfig, args, rawArgs);
83
+ let buildReportData = (turboScaleSession || !isBrowserstackInfra) ? null : await getInitialDetails(bsConfig, args, rawArgs);
81
84
 
82
85
  // accept the build name from command line if provided
83
86
  utils.setBuildName(bsConfig, args);
@@ -147,6 +150,29 @@ module.exports = function run(args, rawArgs) {
147
150
  if (isAccessibilitySession && isBrowserstackInfra) {
148
151
  await createAccessibilityTestRun(bsConfig);
149
152
  }
153
+
154
+ if (turboScaleSession) {
155
+ // Local is only required in case user is running on trial grid and wants to access private website.
156
+ // Even then, it will be spawned separately via browserstack-cli ats connect-grid command and not via browserstack-cypress-cli
157
+ // Hence whenever running on ATS, need to make local as false
158
+ bsConfig.connection_settings.local = false;
159
+
160
+ const gridDetails = await getTurboScaleGridDetails(bsConfig, args, rawArgs);
161
+
162
+ if (gridDetails && Object.keys(gridDetails).length > 0) {
163
+ Constants.turboScaleObj.gridDetails = gridDetails;
164
+ Constants.turboScaleObj.gridUrl = gridDetails.cypressUrl;
165
+ Constants.turboScaleObj.uploadUrl = gridDetails.cypressUrl + '/upload';
166
+ Constants.turboScaleObj.buildUrl = gridDetails.cypressUrl + '/build';
167
+
168
+ logger.debug(`Automate TurboScale Grid URL set to ${gridDetails.url}`);
169
+
170
+ patchCypressConfigFileContent(bsConfig);
171
+ } else {
172
+ process.exitCode = Constants.ERROR_EXIT_CODE;
173
+ return;
174
+ }
175
+ }
150
176
  }
151
177
 
152
178
  const { packagesInstalled } = !isBrowserstackInfra ? false : await packageInstaller.packageSetupAndInstaller(bsConfig, config.packageDirName, {markBlockStart, markBlockEnd});
@@ -186,7 +212,7 @@ module.exports = function run(args, rawArgs) {
186
212
 
187
213
  //get the number of spec files
188
214
  markBlockStart('getNumberOfSpecFiles');
189
- let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressConfigFile);
215
+ let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressConfigFile, turboScaleSession);
190
216
  markBlockEnd('getNumberOfSpecFiles');
191
217
 
192
218
  bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressConfigFile, bsConfig);
@@ -251,6 +277,11 @@ module.exports = function run(args, rawArgs) {
251
277
  if (process.env.BROWSERSTACK_TEST_ACCESSIBILITY === 'true') {
252
278
  supportFileCleanup();
253
279
  }
280
+
281
+ if (turboScaleSession) {
282
+ atsFileCleanup(bsConfig);
283
+ }
284
+
254
285
  // Set config args for enforce_settings
255
286
  if ( !utils.isUndefinedOrFalse(bsConfig.run_settings.enforce_settings) ) {
256
287
  markBlockStart('setEnforceSettingsConfig');
@@ -310,13 +341,13 @@ module.exports = function run(args, rawArgs) {
310
341
  logger.debug("Completed polling of build status");
311
342
 
312
343
  // stop the Local instance
313
- await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs, buildReportData);
344
+ if (!turboScaleSession) await utils.stopLocalBinary(bsConfig, bs_local, args, rawArgs, buildReportData);
314
345
 
315
346
  // waiting for 5 secs for upload to complete (as a safety measure)
316
347
  await new Promise(resolve => setTimeout(resolve, 5000));
317
348
 
318
349
  // download build artifacts
319
- if (exitCode != Constants.BUILD_FAILED_EXIT_CODE) {
350
+ if (exitCode != Constants.BUILD_FAILED_EXIT_CODE && !turboScaleSession) {
320
351
  if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
321
352
  logger.debug("Downloading build artifacts");
322
353
  await downloadBuildArtifacts(bsConfig, data.build_id, args, rawArgs, buildReportData);
@@ -328,7 +359,7 @@ module.exports = function run(args, rawArgs) {
328
359
  markBlockEnd('postBuild');
329
360
  utils.handleSyncExit(exitCode, data.dashboard_url);
330
361
  });
331
- } else {
362
+ } else if(!turboScaleSession){
332
363
  let stacktraceUrl = getStackTraceUrl();
333
364
  downloadBuildStacktrace(stacktraceUrl).then((message) => {
334
365
  utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null, buildReportData, rawArgs);
@@ -344,7 +375,7 @@ module.exports = function run(args, rawArgs) {
344
375
  });
345
376
  }
346
377
  });
347
- } else if (utils.nonEmptyArray(bsConfig.run_settings.downloads)) {
378
+ } else if (utils.nonEmptyArray(bsConfig.run_settings.downloads && !turboScaleSession)) {
348
379
  logger.info(Constants.userMessages.ASYNC_DOWNLOADS.replace('<build-id>', data.build_id));
349
380
  }
350
381
 
@@ -19,17 +19,19 @@ module.exports = function stop(args, rawArgs) {
19
19
  // accept the access key from command line if provided
20
20
  utils.setAccessKey(bsConfig, args);
21
21
 
22
- let buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
23
-
24
22
  utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
25
23
 
26
24
  // set cypress config filename
27
25
  utils.setCypressConfigFilename(bsConfig, args);
28
26
 
29
27
  let buildId = args._[1];
28
+ let buildReportData = null;
30
29
 
31
- await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs, buildReportData);
30
+ if (!Constants.turboScaleObj.enabled) {
31
+ buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
32
+ }
32
33
 
34
+ await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs, buildReportData);
33
35
  }).catch(function (err) {
34
36
  logger.error(err);
35
37
  utils.setUsageReportingFlag(null, args.disableUsageReporting);
@@ -0,0 +1,118 @@
1
+ const path = require('path');
2
+ const fs = require('fs')
3
+
4
+ const request = require('request'),
5
+ logger = require('./logger').winstonLogger,
6
+ utils = require('./utils'),
7
+ config = require('./config');
8
+ Constants = require('./constants');
9
+
10
+ exports.isTurboScaleSession = (bsConfig) => {
11
+ // env var will override config
12
+ if (process.env.BROWSERSTACK_TURBOSCALE && process.env.BROWSERSTACK_TURBOSCALE === 'true') {
13
+ return true;
14
+ }
15
+
16
+ if (bsConfig.run_settings && bsConfig.run_settings.turboScale) {
17
+ return true;
18
+ }
19
+
20
+ return false;
21
+ };
22
+
23
+ exports.getTurboScaleOptions = (bsConfig) => {
24
+ if (bsConfig.run_settings && bsConfig.run_settings.turboScaleOptions) {
25
+ return bsConfig.run_settings.turboScaleOptions;
26
+ }
27
+
28
+ return {};
29
+ };
30
+
31
+ exports.getTurboScaleGridName = (bsConfig) => {
32
+ // env var will override config
33
+ if (process.env.BROWSERSTACK_TURBOSCALE_GRID_NAME) {
34
+ return process.env.BROWSERSTACK_TURBOSCALE_GRID_NAME;
35
+ }
36
+
37
+ if (bsConfig.run_settings && bsConfig.run_settings.turboScaleOptions && bsConfig.run_settings.turboScaleOptions.gridName) {
38
+ return bsConfig.run_settings.turboScaleOptions.gridName;
39
+ }
40
+
41
+ return 'NO_GRID_NAME_PASSED';
42
+ };
43
+
44
+ exports.getTurboScaleGridDetails = async (bsConfig, args, rawArgs) => {
45
+ try {
46
+ const gridName = this.getTurboScaleGridName(bsConfig);
47
+
48
+ return new Promise((resolve, reject) => {
49
+ let options = {
50
+ url: `${config.turboScaleAPIUrl}/grids/${gridName}`,
51
+ auth: {
52
+ username: bsConfig.auth.username,
53
+ password: bsConfig.auth.access_key,
54
+ },
55
+ headers: {
56
+ 'User-Agent': utils.getUserAgent(),
57
+ }
58
+ };
59
+ let responseData = {};
60
+ request.get(options, function (err, resp, data) {
61
+ if(err) {
62
+ logger.warn(utils.formatRequest(err, resp, data));
63
+ utils.sendUsageReport(bsConfig, args, err, Constants.messageTypes.ERROR, 'get_ats_details_failed', null, rawArgs);
64
+ resolve({});
65
+ } else {
66
+ try {
67
+ responseData = JSON.parse(data);
68
+ } catch (e) {
69
+ responseData = {};
70
+ }
71
+ if(resp.statusCode != 200) {
72
+ logger.warn(`Warn: Get Automate TurboScale Details Request failed with status code ${resp.statusCode}`);
73
+ utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'get_ats_details_failed', null, rawArgs);
74
+ resolve({});
75
+ }
76
+ resolve(responseData);
77
+ }
78
+ });
79
+ });
80
+ } catch (err) {
81
+ logger.error(`Failed to find TurboScale Grid: ${err}: ${err.stack}`);
82
+ }
83
+ };
84
+
85
+ exports.patchCypressConfigFileContent = (bsConfig) => {
86
+ try {
87
+ let cypressConfigFileData = fs.readFileSync(path.resolve(bsConfig.run_settings.cypress_config_file)).toString();
88
+ const patchedConfigFileData = cypressConfigFileData + '\n\n' + `
89
+ let originalFunction = module.exports.e2e.setupNodeEvents;
90
+
91
+ module.exports.e2e.setupNodeEvents = (on, config) => {
92
+ const bstackOn = require("./cypressPatch.js")(on);
93
+ if (originalFunction !== null && originalFunction !== undefined) {
94
+ originalFunction(bstackOn, config);
95
+ }
96
+ }
97
+ `
98
+
99
+ let confPath = bsConfig.run_settings.cypress_config_file;
100
+ let patchedConfPathList = confPath.split(path.sep);
101
+ patchedConfPathList[patchedConfPathList.length - 1] = 'patched_ats_config_file.js'
102
+ const patchedConfPath = patchedConfPathList.join(path.sep);
103
+
104
+ bsConfig.run_settings.patched_cypress_config_file = patchedConfPath;
105
+
106
+ fs.writeFileSync(path.resolve(bsConfig.run_settings.patched_cypress_config_file), patchedConfigFileData);
107
+ } catch(e) {
108
+ logger.error(`Encountered an error when trying to patch ATS Cypress Config File ${e}`);
109
+ return {};
110
+ }
111
+ }
112
+
113
+ exports.atsFileCleanup = (bsConfig) => {
114
+ const filePath = path.resolve(bsConfig.run_settings.patched_cypress_config_file);
115
+ if(fs.existsSync(filePath)){
116
+ fs.unlinkSync(filePath);
117
+ }
118
+ }
@@ -23,6 +23,10 @@ const createBuild = (bsConfig, zip) => {
23
23
  body: data
24
24
  }
25
25
 
26
+ if (Constants.turboScaleObj.enabled) {
27
+ options.url = Constants.turboScaleObj.buildUrl;
28
+ }
29
+
26
30
  request.post(options, function (err, resp, body) {
27
31
  if (err) {
28
32
  logger.error(utils.formatRequest(err, resp, body));
@@ -121,6 +121,10 @@ const checkUploadedMd5 = (bsConfig, args, instrumentBlocks) => {
121
121
  body: JSON.stringify(data)
122
122
  };
123
123
 
124
+ if (Constants.turboScaleObj.enabled) {
125
+ options.url = config.turboScaleMd5Sum;
126
+ }
127
+
124
128
  instrumentBlocks.markBlockStart("checkAlreadyUploaded.railsCheck");
125
129
  request.post(options, function (err, resp, body) {
126
130
  if (err) {
@@ -24,7 +24,11 @@ config.packageFileName = "bstackPackages.tar.gz";
24
24
  config.packageDirName = "tmpBstackPackages";
25
25
  config.retries = 5;
26
26
  config.networkErrorExitCode = 2;
27
- config.compiledConfigJsDirName = 'tmpBstackCompiledJs'
28
- config.configJsonFileName = 'tmpCypressConfig.json'
27
+ config.compiledConfigJsDirName = 'tmpBstackCompiledJs';
28
+ config.configJsonFileName = 'tmpCypressConfig.json';
29
+
30
+ // turboScale
31
+ config.turboScaleMd5Sum = `${config.turboScaleUrl}/md5sumcheck`;
32
+ config.turboScaleBuildsUrl = `${config.turboScaleUrl}/builds`;
29
33
 
30
34
  module.exports = config;
@@ -3,5 +3,7 @@
3
3
  "rails_host": "https://api.browserstack.com",
4
4
  "dashboardUrl": "https://automate.browserstack.com/dashboard/v2/builds/",
5
5
  "usageReportingUrl": "https://eds.browserstack.com:443/send_event_cy_internal",
6
- "localTestingListUrl": "https://www.browserstack.com/local/v1/list"
6
+ "localTestingListUrl": "https://www.browserstack.com/local/v1/list",
7
+ "turboScaleUrl": "https://grid.browserstack.com/packages/cypress",
8
+ "turboScaleAPIUrl": "https://api.browserstack.com/automate-turboscale/v1"
7
9
  }
@@ -441,6 +441,8 @@ const CYPRESS_CONFIG_FILE_NAMES = Object.keys(CYPRESS_CONFIG_FILE_MAPPING);
441
441
 
442
442
  const CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs']
443
443
 
444
+ const turboScaleObj = {};
445
+
444
446
  module.exports = Object.freeze({
445
447
  syncCLI,
446
448
  userMessages,
@@ -453,6 +455,7 @@ module.exports = Object.freeze({
453
455
  hashingOptions,
454
456
  packageInstallerOptions,
455
457
  specFileTypes,
458
+ turboScaleObj,
456
459
  DEFAULT_CYPRESS_SPEC_PATH,
457
460
  DEFAULT_CYPRESS_10_SPEC_PATH,
458
461
  SPEC_TOTAL_CHAR_LIMIT,
@@ -24,8 +24,8 @@ let terminalWidth = (process.stdout.columns) * 0.9;
24
24
  let lineSeparator = Constants.syncCLI.DEFAULT_LINE_SEP;
25
25
  if (!isNaN(terminalWidth)) lineSeparator = "\n" + "-".repeat(terminalWidth);
26
26
 
27
- let getOptions = (auth, build_id) => {
28
- return {
27
+ let getOptions = (auth, build_id) => {
28
+ const options = {
29
29
  url: `${config.buildUrlV2}${build_id}`,
30
30
  auth: {
31
31
  user: auth.username,
@@ -37,6 +37,12 @@ let getOptions = (auth, build_id) => {
37
37
  "User-Agent": utils.getUserAgent()
38
38
  }
39
39
  };
40
+
41
+ if (Constants.turboScaleObj.enabled) {
42
+ options.url = `${config.turboScaleBuildsUrl}/${build_id}`;
43
+ }
44
+
45
+ return options;
40
46
  }
41
47
 
42
48
  let getTableConfig = (termWidth) => {
@@ -721,6 +721,11 @@ exports.generateUploadParams = (bsConfig, filePath, md5data, fileDetails) => {
721
721
  "User-Agent": exports.getUserAgent(),
722
722
  }
723
723
  }
724
+
725
+ if (Constants.turboScaleObj.enabled) {
726
+ options.url = Constants.turboScaleObj.uploadUrl;
727
+ }
728
+
724
729
  return options
725
730
  }
726
731
 
@@ -968,6 +973,7 @@ exports.setLocalArgs = (bsConfig, args) => {
968
973
  local_args['proxyPort'] = bsConfig["connection_settings"]["proxyPort"];
969
974
  if (bsConfig["connection_settings"]["useCaCertificate"])
970
975
  local_args['useCaCertificate'] = bsConfig["connection_settings"]["useCaCertificate"];
976
+
971
977
  local_args['daemon'] = true;
972
978
  local_args['enable-logging-for-api'] = true
973
979
  local_args['source'] = `cypress:${usageReporting.cli_version_and_path(bsConfig).version}`;
@@ -1070,7 +1076,7 @@ exports.getFilesToIgnore = (runSettings, excludeFiles, logging = true) => {
1070
1076
  return ignoreFiles;
1071
1077
  }
1072
1078
 
1073
- exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
1079
+ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig, turboScaleSession=false) => {
1074
1080
  let defaultSpecFolder
1075
1081
  let testFolderPath
1076
1082
  let globCypressConfigSpecPatterns = []
@@ -1145,6 +1151,13 @@ exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
1145
1151
  }
1146
1152
 
1147
1153
  logger.debug(`${files ? files.length : 0} spec files found`);
1154
+
1155
+ if (turboScaleSession) {
1156
+ // remove unwanted path prefix for turboscale
1157
+ files = files.map((x) => { return path.join(testFolderPath, x.split(testFolderPath)[1]) })
1158
+ // setting specs for turboScale as we don't have patched API for turboscale so we will rely on info from CLI
1159
+ bsConfig.run_settings.specs = files;
1160
+ }
1148
1161
  return files;
1149
1162
  };
1150
1163
 
@@ -1327,7 +1340,7 @@ exports.setEnforceSettingsConfig = (bsConfig) => {
1327
1340
  if(specConfigs && specConfigs.includes(',')) {
1328
1341
  specConfigs = JSON.stringify(specConfigs.split(','));
1329
1342
  }
1330
- let spec_pattern_args = 'specPattern="'+specConfigs+'"';
1343
+ let spec_pattern_args = `specPattern=${specConfigs}`;
1331
1344
  config_args = this.isUndefined(config_args) ? spec_pattern_args : config_args + ',' + spec_pattern_args;
1332
1345
  }
1333
1346
  if ( this.isNotUndefined(config_args) ) bsConfig["run_settings"]["config"] = config_args;
@@ -1430,6 +1443,11 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs, buildRe
1430
1443
  'User-Agent': that.getUserAgent(),
1431
1444
  },
1432
1445
  };
1446
+
1447
+ if (Constants.turboScaleObj.enabled) {
1448
+ options.url = `${config.turboScaleBuildsUrl}/${buildId}/stop`;
1449
+ }
1450
+
1433
1451
  let message = null;
1434
1452
  let messageType = null;
1435
1453
  let errorCode = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.27.0",
3
+ "version": "1.28.0",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {