browserstack-cypress-cli 1.21.0 → 1.22.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.
@@ -69,7 +69,7 @@ module.exports = function run(args, rawArgs) {
69
69
  // set cypress geo location
70
70
  utils.setGeolocation(bsConfig, args);
71
71
 
72
- // set spec timeout
72
+ // set spec timeout
73
73
  utils.setSpecTimeout(bsConfig, args);
74
74
 
75
75
  // accept the specs list from command line if provided
@@ -84,6 +84,9 @@ module.exports = function run(args, rawArgs) {
84
84
  //accept the local from env variable if provided
85
85
  utils.setLocal(bsConfig, args);
86
86
 
87
+ //set network logs
88
+ utils.setNetworkLogs(bsConfig);
89
+
87
90
  // set Local Mode (on-demand/ always-on)
88
91
  utils.setLocalMode(bsConfig, args);
89
92
 
@@ -99,8 +102,7 @@ module.exports = function run(args, rawArgs) {
99
102
  // set the no-wrap
100
103
  utils.setNoWrap(bsConfig, args);
101
104
 
102
- // set record feature caps
103
- utils.setRecordCaps(bsConfig, args);
105
+ const { packagesInstalled } = await packageInstaller.packageSetupAndInstaller(bsConfig, config.packageDirName, {markBlockStart, markBlockEnd});
104
106
 
105
107
  // set build tag caps
106
108
  utils.setBuildTags(bsConfig, args);
@@ -129,8 +131,11 @@ module.exports = function run(args, rawArgs) {
129
131
  logger.debug("Completed configs validation");
130
132
  markBlockStart('preArchiveSteps');
131
133
  logger.debug("Started pre-archive steps");
134
+
132
135
  //get the number of spec files
136
+ markBlockStart('getNumberOfSpecFiles');
133
137
  let specFiles = utils.getNumberOfSpecFiles(bsConfig, args, cypressConfigFile);
138
+ markBlockEnd('getNumberOfSpecFiles');
134
139
 
135
140
  bsConfig['run_settings']['video_config'] = utils.getVideoConfig(cypressConfigFile);
136
141
 
@@ -140,6 +145,9 @@ module.exports = function run(args, rawArgs) {
140
145
  // accept the number of parallels
141
146
  utils.setParallels(bsConfig, args, specFiles.length);
142
147
 
148
+ // set record feature caps
149
+ utils.setRecordCaps(bsConfig, args, cypressConfigFile);
150
+
143
151
  // warn if specFiles cross our limit
144
152
  utils.warnSpecLimit(bsConfig, args, specFiles, rawArgs, buildReportData);
145
153
  markBlockEnd('preArchiveSteps');
@@ -153,7 +161,7 @@ module.exports = function run(args, rawArgs) {
153
161
 
154
162
  logger.debug("Started caching npm dependencies.");
155
163
  markBlockStart('zip.packageInstaller');
156
- return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}).then(function (packageData) {
164
+ return packageInstaller.packageWrapper(bsConfig, config.packageDirName, config.packageFileName, md5data, {markBlockStart, markBlockEnd}, packagesInstalled).then(function (packageData) {
157
165
  logger.debug("Completed caching npm dependencies.")
158
166
  markBlockEnd('zip.packageInstaller');
159
167
 
@@ -409,8 +417,8 @@ module.exports = function run(args, rawArgs) {
409
417
  updateCheckInterval: 1000 * 60 * 60 * 24 * 7,
410
418
  });
411
419
 
412
- // Checks for update on first run.
413
- // Set lastUpdateCheck to 0 to spawn the check update process as notifier sets this to Date.now() for preventing
420
+ // Checks for update on first run.
421
+ // Set lastUpdateCheck to 0 to spawn the check update process as notifier sets this to Date.now() for preventing
414
422
  // the check untill one interval period. It runs once.
415
423
  if (!notifier.disabled && Date.now() - notifier.config.get('lastUpdateCheck') < 50) {
416
424
  notifier.config.set('lastUpdateCheck', 0);
@@ -1,5 +1,6 @@
1
1
  const fs = require('fs'),
2
2
  path = require('path');
3
+ const { readCypressConfigFile } = require('./readCypressConfigUtil');
3
4
 
4
5
  const logger = require("./logger").winstonLogger,
5
6
  Constants = require("./constants"),
@@ -194,34 +195,30 @@ const validate = (bsConfig, args) => {
194
195
  logger.debug(`Checking for cypress config file at ${cypressConfigFilePath}`);
195
196
  if (!fs.existsSync(cypressConfigFilePath) && bsConfig.run_settings.cypress_config_filename !== 'false') reject(Constants.validationMessages.INVALID_CYPRESS_CONFIG_FILE);
196
197
 
197
- if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
198
- logger.debug(`Validating ${bsConfig.run_settings.cypress_config_filename}`);
199
- // TODO: add validations for cypress_config_filename
200
- } else {
201
- logger.debug("Validating cypress.json");
202
- try {
203
- if (bsConfig.run_settings.cypress_config_filename !== 'false') {
204
-
205
- if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
206
- if (cypressConfigFilePath.endsWith("cypress.config.js")) {
207
- cypressConfigFile = require(cypressConfigFilePath);
208
- } else {
209
- cypressConfigFile = {};
210
- }
211
- } else {
212
- let cypressJsonContent = fs.readFileSync(cypressConfigFilePath);
213
- cypressConfigFile = JSON.parse(cypressJsonContent);
198
+ logger.debug(`Validating ${bsConfig.run_settings.cypress_config_filename}`);
199
+ try {
200
+ if (bsConfig.run_settings.cypress_config_filename !== 'false') {
201
+ if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
202
+ const completeCypressConfigFile = readCypressConfigFile(bsConfig)
203
+ if (!Utils.isUndefined(completeCypressConfigFile)) {
204
+ // check if cypress config was exported using export default
205
+ cypressConfigFile = !Utils.isUndefined(completeCypressConfigFile.default) ? completeCypressConfigFile.default : completeCypressConfigFile
214
206
  }
215
207
 
216
- // Cypress Json Base Url & Local true check
217
- if (!Utils.isUndefined(cypressConfigFile.baseUrl) && cypressConfigFile.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", cypressConfigFile.baseUrl));
218
-
219
- // Detect if the user is not using the right directory structure, and throw an error
220
- if (!Utils.isUndefined(cypressConfigFile.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,cypressConfigFile.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
208
+ // TODO: add validations for cypress_config_filename
209
+ } else {
210
+ let cypressJsonContent = fs.readFileSync(cypressConfigFilePath);
211
+ cypressConfigFile = JSON.parse(cypressJsonContent);
221
212
  }
222
- } catch(error){
223
- reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
213
+
214
+ // Cypress Json Base Url & Local true check
215
+ if (!Utils.isUndefined(cypressConfigFile.baseUrl) && cypressConfigFile.baseUrl.includes("localhost") && !Utils.getLocalFlag(bsConfig.connection_settings)) reject(Constants.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", cypressConfigFile.baseUrl));
216
+
217
+ // Detect if the user is not using the right directory structure, and throw an error
218
+ if (!Utils.isUndefined(cypressConfigFile.integrationFolder) && !Utils.isCypressProjDirValid(bsConfig.run_settings.cypressProjectDir,cypressConfigFile.integrationFolder)) reject(Constants.validationMessages.INCORRECT_DIRECTORY_STRUCTURE);
224
219
  }
220
+ } catch(error){
221
+ reject(Constants.validationMessages.INVALID_CYPRESS_JSON)
225
222
  }
226
223
 
227
224
  //check if home_directory is present or not in user run_settings
@@ -289,6 +286,9 @@ const validate = (bsConfig, args) => {
289
286
  if (!Utils.isUndefined(bsConfig.run_settings.nodeVersion) && typeof(bsConfig.run_settings.nodeVersion) === 'string' && !bsConfig.run_settings.nodeVersion.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/))
290
287
  logger.warn(Constants.validationMessages.NODE_VERSION_PARSING_ERROR);
291
288
 
289
+ if(!Utils.isUndefined(cypressConfigFile.port)) {
290
+ logger.warn(Constants.userMessages.CYPRESS_PORT_WARNING.replace("<x>", cypressConfigFile.port));
291
+ }
292
292
  resolve(cypressConfigFile);
293
293
  });
294
294
  }
@@ -24,5 +24,7 @@ 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
29
 
28
30
  module.exports = config;
@@ -43,8 +43,10 @@ const userMessages = {
43
43
  "There was some issue while checking if zip is already uploaded.",
44
44
  ZIP_DELETE_FAILED: "Could not delete tests.zip successfully.",
45
45
  ZIP_DELETED: "Deleted tests.zip successfully.",
46
- NPM_INSTALL_AND_UPLOAD:
47
- "Installing required dependencies and building the package to upload to BrowserStack",
46
+ NPM_INSTALL:
47
+ "Installing required dependencies",
48
+ NPM_UPLOAD:
49
+ "Building the package to upload to BrowserStack",
48
50
  NPM_DELETE_FAILED: "Could not delete the dependency packages.",
49
51
  NPM_DELETED: "Deleted dependency packages successfully.",
50
52
  API_DEPRECATED:
@@ -111,7 +113,9 @@ const userMessages = {
111
113
  SPEC_LIMIT_SUCCESS_MESSAGE:
112
114
  "Spec timeout specified as <x> minutes. If any of your specs exceed the specified time limit, it would be forcibly killed by BrowserStack",
113
115
  NO_CONNECTION_WHILE_UPDATING_UPLOAD_PROGRESS_BAR:
114
- "Unable to determine zip upload progress due to undefined/null connection request"
116
+ "Unable to determine zip upload progress due to undefined/null connection request",
117
+ CYPRESS_PORT_WARNING:
118
+ "The requested port number <x> is ignored. The default BrowserStack port will be used for this execution"
115
119
  };
116
120
 
117
121
  const validationMessages = {
@@ -313,6 +317,7 @@ const allowedFileTypes = [
313
317
  "tsx",
314
318
  "pfx",
315
319
  "cfr",
320
+ "ico"
316
321
  ];
317
322
 
318
323
  const filesToIgnoreWhileUploading = [
@@ -367,6 +372,7 @@ const packageInstallerOptions = {
367
372
  const specFileTypes = ["js", "ts", "feature", "jsx", "coffee", "cjsx"];
368
373
 
369
374
  const DEFAULT_CYPRESS_SPEC_PATH = "cypress/integration";
375
+ const DEFAULT_CYPRESS_10_SPEC_PATH = "cypress/e2e";
370
376
 
371
377
  const SPEC_TOTAL_CHAR_LIMIT = 32243;
372
378
  const METADATA_CHAR_BUFFER_PER_SPEC = 175;
@@ -419,6 +425,8 @@ const CYPRESS_CONFIG_FILE_MAPPING = {
419
425
 
420
426
  const CYPRESS_CONFIG_FILE_NAMES = Object.keys(CYPRESS_CONFIG_FILE_MAPPING);
421
427
 
428
+ const CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS = ['js', 'ts', 'cjs', 'mjs']
429
+
422
430
  module.exports = Object.freeze({
423
431
  syncCLI,
424
432
  userMessages,
@@ -432,6 +440,7 @@ module.exports = Object.freeze({
432
440
  packageInstallerOptions,
433
441
  specFileTypes,
434
442
  DEFAULT_CYPRESS_SPEC_PATH,
443
+ DEFAULT_CYPRESS_10_SPEC_PATH,
435
444
  SPEC_TOTAL_CHAR_LIMIT,
436
445
  METADATA_CHAR_BUFFER_PER_SPEC,
437
446
  usageReportingConstants,
@@ -448,5 +457,6 @@ module.exports = Object.freeze({
448
457
  CYPRESS_V9_AND_OLDER_TYPE,
449
458
  CYPRESS_V10_AND_ABOVE_TYPE,
450
459
  CYPRESS_CONFIG_FILE_MAPPING,
451
- CYPRESS_CONFIG_FILE_NAMES
460
+ CYPRESS_CONFIG_FILE_NAMES,
461
+ CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS
452
462
  });
@@ -33,6 +33,9 @@ exports.getInitialDetails = (bsConfig, args, rawArgs) => {
33
33
  utils.sendUsageReport(bsConfig, args, responseData["error"], Constants.messageTypes.ERROR, 'get_initial_details_failed', null, rawArgs);
34
34
  resolve({});
35
35
  } else {
36
+ if (!utils.isUndefined(responseData.grr) && responseData.grr.enabled && !utils.isUndefined(responseData.grr.urls)) {
37
+ config.uploadUrl = responseData.grr.urls.upload_url;
38
+ }
36
39
  resolve(responseData);
37
40
  }
38
41
  }
@@ -128,16 +128,13 @@ const packageArchiver = (packageDir, packageFile) => {
128
128
  })
129
129
  }
130
130
 
131
- const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBlocks) => {
131
+ const packageSetupAndInstaller = (bsConfig, packageDir, instrumentBlocks) => {
132
132
  return new Promise(function (resolve) {
133
133
  let obj = {
134
- packageArchieveCreated: false
134
+ packagesInstalled: false
135
135
  };
136
- if (md5data.packageUrlPresent || !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
137
- logger.debug("Skipping the caching of npm packages since BrowserStack has already cached your npm dependencies that have not changed since the last run.")
138
- return resolve(obj);
139
- }
140
- logger.info(Constants.userMessages.NPM_INSTALL_AND_UPLOAD);
136
+
137
+ logger.info(Constants.userMessages.NPM_INSTALL);
141
138
  instrumentBlocks.markBlockStart("packageInstaller.folderSetup");
142
139
  logger.debug("Started setting up package folder");
143
140
  return setupPackageFolder(bsConfig.run_settings, packageDir).then((_result) => {
@@ -150,10 +147,34 @@ const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBl
150
147
  }).then((_result) => {
151
148
  logger.debug("Completed installing dependencies");
152
149
  instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");
153
- instrumentBlocks.markBlockStart("packageInstaller.packageArchive");
154
- logger.debug("Started archiving node_modules")
155
- return packageArchiver(packageDir, packageFile);
156
- }).then((_result) => {
150
+ Object.assign(obj, { packagesInstalled: true });
151
+ return resolve(obj);
152
+ }).catch((err) => {
153
+ logger.warn(`Error occured while installing npm dependencies. Dependencies will be installed in runtime. This will have a negative impact on performance. Reach out to browserstack.com/contact, if you persistantly face this issue.`);
154
+ obj.error = err.stack ? err.stack.toString().substring(0,100) : err.toString().substring(0,100);
155
+ return resolve(obj);
156
+ })
157
+ })
158
+ }
159
+
160
+ const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBlocks, packagesInstalled) => {
161
+ return new Promise(function (resolve) {
162
+ let obj = {
163
+ packageArchieveCreated: false
164
+ };
165
+ if (!packagesInstalled) {
166
+ logger.debug("Skipping the caching of npm packages since package installed failed")
167
+ return resolve(obj);
168
+ }
169
+ if (md5data.packageUrlPresent || !utils.isTrueString(bsConfig.run_settings.cache_dependencies)) {
170
+ logger.debug("Skipping the caching of npm packages since BrowserStack has already cached your npm dependencies that have not changed since the last run.")
171
+ return resolve(obj);
172
+ }
173
+ logger.info(Constants.userMessages.NPM_UPLOAD);
174
+ instrumentBlocks.markBlockStart("packageInstaller.packageArchive");
175
+ logger.debug("Started archiving node_modules")
176
+ return packageArchiver(packageDir, packageFile)
177
+ .then((_result) => {
157
178
  logger.debug("Archiving of node_modules completed");
158
179
  instrumentBlocks.markBlockEnd("packageInstaller.packageArchive");
159
180
  Object.assign(obj, { packageArchieveCreated: true });
@@ -167,3 +188,4 @@ const packageWrapper = (bsConfig, packageDir, packageFile, md5data, instrumentBl
167
188
  }
168
189
 
169
190
  exports.packageWrapper = packageWrapper;
191
+ exports.packageSetupAndInstaller = packageSetupAndInstaller;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+ const cp = require('child_process');
5
+
6
+ const config = require('./config');
7
+ const constants = require("./constants");
8
+ const utils = require("./utils");
9
+ const logger = require('./logger').winstonLogger;
10
+
11
+ exports.detectLanguage = (cypress_config_filename) => {
12
+ const extension = cypress_config_filename.split('.').pop()
13
+ return constants.CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS.includes(extension) ? extension : 'js'
14
+ }
15
+
16
+ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_modules_path) => {
17
+ const cypress_config_filename = bsConfig.run_settings.cypress_config_filename
18
+ const working_dir = path.dirname(cypress_config_filepath);
19
+ const complied_js_dir = path.join(working_dir, config.compiledConfigJsDirName)
20
+ cp.execSync(`rm -rf ${config.compiledConfigJsDirName}`, { cwd: working_dir })
21
+ cp.execSync(`mkdir ${config.compiledConfigJsDirName}`, { cwd: working_dir })
22
+
23
+ let tsc_command = `NODE_PATH=${bstack_node_modules_path} ${bstack_node_modules_path}/typescript/bin/tsc --outDir ${complied_js_dir} --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false ${cypress_config_filepath}`
24
+ let tsc_output
25
+ try {
26
+ logger.debug(`Running: ${tsc_command}`)
27
+ tsc_output = cp.execSync(tsc_command, { cwd: working_dir })
28
+ } catch (err) {
29
+ // error while compiling ts files
30
+ logger.debug(err.message);
31
+ logger.debug(err.output.toString());
32
+ tsc_output = err.output // if there is an error, tsc adds output of complilation to err.output key
33
+ } finally {
34
+ logger.debug(`Saved compiled js output at: ${complied_js_dir}`);
35
+ logger.debug(`Finding compiled cypress config file in: ${complied_js_dir}`);
36
+
37
+ const lines = tsc_output.toString().split('\n');
38
+ let foundLine = null;
39
+ for (let i = 0; i < lines.length; i++) {
40
+ if (lines[i].indexOf(`${path.parse(cypress_config_filename).name}.js`) > -1) {
41
+ foundLine = lines[i]
42
+ break;
43
+ }
44
+ }
45
+ if (foundLine === null) {
46
+ logger.error(`No compiled cypress config found. There might some error running ${tsc_command} command`)
47
+ return null
48
+ } else {
49
+ const compiled_cypress_config_filepath = foundLine.split('TSFILE: ').pop()
50
+ logger.debug(`Found compiled cypress config file: ${compiled_cypress_config_filepath}`);
51
+ return compiled_cypress_config_filepath
52
+ }
53
+ }
54
+ }
55
+
56
+ exports.loadJsFile = (cypress_config_filepath, bstack_node_modules_path) => {
57
+ const require_module_helper_path = `${__dirname}/requireModule.js`
58
+ cp.execSync(`NODE_PATH=${bstack_node_modules_path} node ${require_module_helper_path} ${cypress_config_filepath}`)
59
+ const cypress_config = JSON.parse(fs.readFileSync(config.configJsonFileName).toString())
60
+ if (fs.existsSync(config.configJsonFileName)) {
61
+ fs.unlinkSync(config.configJsonFileName)
62
+ }
63
+ return cypress_config
64
+ }
65
+
66
+ exports.readCypressConfigFile = (bsConfig) => {
67
+ const cypress_config_filepath = path.resolve(bsConfig.run_settings.cypressConfigFilePath)
68
+ try {
69
+ const cypress_config_filename = bsConfig.run_settings.cypress_config_filename
70
+ const bstack_node_modules_path = `${path.resolve(config.packageDirName)}/node_modules`
71
+ const conf_lang = this.detectLanguage(cypress_config_filename)
72
+
73
+ logger.debug(`cypress config path: ${cypress_config_filepath}`);
74
+
75
+ if (conf_lang == 'js' || conf_lang == 'cjs') {
76
+ return this.loadJsFile(cypress_config_filepath, bstack_node_modules_path)
77
+ } else if (conf_lang === 'ts') {
78
+ const compiled_cypress_config_filepath = this.convertTsConfig(bsConfig, cypress_config_filepath, bstack_node_modules_path)
79
+ return this.loadJsFile(compiled_cypress_config_filepath, bstack_node_modules_path)
80
+ }
81
+ } catch (error) {
82
+ const errorMessage = `Error while reading cypress config: ${error.message}`
83
+ const errorCode = 'cypress_config_file_read_failed'
84
+ logger.error(errorMessage)
85
+ utils.sendUsageReport(
86
+ bsConfig,
87
+ null,
88
+ errorMessage,
89
+ constants.messageTypes.WARNING,
90
+ errorCode,
91
+ null,
92
+ null
93
+ )
94
+ } finally {
95
+ const working_dir = path.dirname(cypress_config_filepath);
96
+ cp.execSync(`rm -rf ${config.compiledConfigJsDirName}`, { cwd: working_dir })
97
+ }
98
+ }
@@ -0,0 +1,14 @@
1
+ // NOTE: DO NOT change the name or location of file, the execution of this file is invoked using fixed path
2
+ // helper file to load and read js modules
3
+ const fs = require('fs');
4
+ const config = require('./config');
5
+ const moduleName = process.argv[2];
6
+
7
+ const mod = require(moduleName)
8
+
9
+ if (fs.existsSync(config.configJsonFileName)) {
10
+ fs.unlinkSync(config.configJsonFileName)
11
+ }
12
+
13
+ // write module in temporary json file
14
+ fs.writeFileSync(config.configJsonFileName, JSON.stringify(mod))
@@ -405,7 +405,7 @@ exports.setRecordKeyFlag = (bsConfig, args) => {
405
405
  return bsConfig.run_settings["record-key"];
406
406
  }
407
407
 
408
- exports.setProjectId = (bsConfig, args) => {
408
+ exports.setProjectId = (bsConfig, args, cypressConfigFile) => {
409
409
  if(!this.isUndefined(args["projectId"])) {
410
410
  return args["projectId"];
411
411
  } else if(!this.isUndefined(process.env.CYPRESS_PROJECT_ID)) {
@@ -413,17 +413,16 @@ exports.setProjectId = (bsConfig, args) => {
413
413
  } else if(!this.isUndefined(bsConfig.run_settings["projectId"])) {
414
414
  return bsConfig.run_settings["projectId"];
415
415
  } else {
416
- let cypressConfigFile = this.getCypressConfigFile(bsConfig);
417
416
  if (!this.isUndefined(cypressConfigFile) && !this.isUndefined(cypressConfigFile["projectId"])) {
418
417
  return cypressConfigFile["projectId"];
419
418
  }
420
419
  }
421
420
  }
422
421
 
423
- exports.setRecordCaps = (bsConfig, args) => {
422
+ exports.setRecordCaps = (bsConfig, args, cypressConfigFile) => {
424
423
  bsConfig.run_settings["record"] = this.setRecordFlag(bsConfig, args);
425
424
  bsConfig.run_settings["record-key"] = this.setRecordKeyFlag(bsConfig, args);
426
- bsConfig.run_settings["projectId"] = this.setProjectId(bsConfig, args);
425
+ bsConfig.run_settings["projectId"] = this.setProjectId(bsConfig, args, cypressConfigFile);
427
426
  }
428
427
 
429
428
  exports.verifyNodeVersionOption = () => {
@@ -987,11 +986,79 @@ exports.getFilesToIgnore = (runSettings, excludeFiles, logging = true) => {
987
986
  }
988
987
 
989
988
  exports.getNumberOfSpecFiles = (bsConfig, args, cypressConfig) => {
990
- let testFolderPath = cypressConfig.integrationFolder || Constants.DEFAULT_CYPRESS_SPEC_PATH;
991
- let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs) || `${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`;
992
- let ignoreFiles = args.exclude || bsConfig.run_settings.exclude;
993
- let files = glob.sync(globSearchPattern, {cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles});
994
- logger.debug(`${files ? files.length : 0} spec files found at ${testFolderPath}`);
989
+ let defaultSpecFolder
990
+ let testFolderPath
991
+ let globCypressConfigSpecPatterns = []
992
+ let globSearchPattern = this.sanitizeSpecsPattern(bsConfig.run_settings.specs);
993
+ let ignoreFiles = args.exclude || bsConfig.run_settings.exclude
994
+
995
+ if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
996
+ defaultSpecFolder = Constants.DEFAULT_CYPRESS_10_SPEC_PATH
997
+ testFolderPath = defaultSpecFolder
998
+ if(!this.isUndefined(cypressConfig) && !this.isUndefined(cypressConfig.e2e)) {
999
+ if(!this.isUndefined(cypressConfig.e2e.specPattern)) {
1000
+ globCypressConfigSpecPatterns = Array.isArray(cypressConfig.e2e.specPattern) ?
1001
+ cypressConfig.e2e.specPattern : [cypressConfig.e2e.specPattern];
1002
+ } else {
1003
+ globCypressConfigSpecPatterns = [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`]
1004
+ }
1005
+ } else {
1006
+ // if not able read cypress config
1007
+ // use bstack specs arg(existing logic, which is not correct) if bstack specs arg not provided check for cypress/e2e folder
1008
+ globCypressConfigSpecPatterns = globSearchPattern ? [globSearchPattern] : [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`]
1009
+ const filesMatched = [];
1010
+ globCypressConfigSpecPatterns.forEach(specPattern => {
1011
+ filesMatched.push(
1012
+ ...glob.sync(specPattern, {
1013
+ cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles
1014
+ })
1015
+ );
1016
+ });
1017
+ if (!filesMatched.length) {
1018
+ // if no files found under cypress/e2e check for cypress/integration
1019
+ globCypressConfigSpecPatterns = [`${Constants.DEFAULT_CYPRESS_SPEC_PATH}/**/*.+(${Constants.specFileTypes.join("|")})`]
1020
+ }
1021
+ }
1022
+ } else {
1023
+ defaultSpecFolder = Constants.DEFAULT_CYPRESS_SPEC_PATH
1024
+ let testFolderPath = cypressConfig.integrationFolder && cypressConfig.integrationFolder !== '.' ?
1025
+ cypressConfig.integrationFolder : defaultSpecFolder;
1026
+ if(!this.isUndefined(cypressConfig.testFiles)) {
1027
+ if (Array.isArray(cypressConfig.testFiles)) {
1028
+ cypressConfig.testFiles.forEach(specPattern => {
1029
+ globCypressConfigSpecPatterns.push(`${testFolderPath}/${specPattern}`)
1030
+ });
1031
+ } else {
1032
+ globCypressConfigSpecPatterns = [`${testFolderPath}/${cypressConfig.testFiles}`]
1033
+ }
1034
+ } else {
1035
+ globCypressConfigSpecPatterns = [`${testFolderPath}/**/*.+(${Constants.specFileTypes.join("|")})`]
1036
+ }
1037
+ }
1038
+
1039
+ let fileMatchedWithConfigSpecPattern = []
1040
+ globCypressConfigSpecPatterns.forEach(specPattern => {
1041
+ fileMatchedWithConfigSpecPattern.push(
1042
+ ...glob.sync(specPattern, {
1043
+ cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles
1044
+ })
1045
+ );
1046
+ });
1047
+ fileMatchedWithConfigSpecPattern = fileMatchedWithConfigSpecPattern.map((file) => path.resolve(bsConfig.run_settings.cypressProjectDir, file))
1048
+
1049
+ let files
1050
+ if (globSearchPattern) {
1051
+ let fileMatchedWithBstackSpecPattern = glob.sync(globSearchPattern, {
1052
+ cwd: bsConfig.run_settings.cypressProjectDir, matchBase: true, ignore: ignoreFiles
1053
+ });
1054
+ fileMatchedWithBstackSpecPattern = fileMatchedWithBstackSpecPattern.map((file) => path.resolve(bsConfig.run_settings.cypressProjectDir, file))
1055
+
1056
+ files = fileMatchedWithBstackSpecPattern.filter(file => fileMatchedWithConfigSpecPattern.includes(file))
1057
+ } else {
1058
+ files = fileMatchedWithConfigSpecPattern;
1059
+ }
1060
+
1061
+ logger.debug(`${files ? files.length : 0} spec files found`);
995
1062
  return files;
996
1063
  };
997
1064
 
@@ -1045,6 +1112,15 @@ exports.getNetworkErrorMessage = (dashboard_url) => {
1045
1112
  return chalk.red(message)
1046
1113
  }
1047
1114
 
1115
+ exports.setNetworkLogs = (bsConfig) => {
1116
+ if(bsConfig.run_settings.networkLogs == 'true' || bsConfig.run_settings.networkLogs == true) {
1117
+ bsConfig.run_settings.networkLogs = 'true'
1118
+ } else {
1119
+ bsConfig.run_settings.networkLogs = 'false'
1120
+ }
1121
+ logger.debug(`Networks logs value: ${bsConfig.run_settings.networkLogs}`);
1122
+ }
1123
+
1048
1124
  exports.versionChangedMessage = (preferredVersion, actualVersion, frameworkUpgradeMessage = '') => {
1049
1125
  let message = Constants.userMessages.CYPRESS_VERSION_CHANGED.replace("<preferredVersion>", preferredVersion);
1050
1126
  message = message.replace("<actualVersion>", actualVersion);
@@ -28,6 +28,7 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
28
28
  obj.startTime = Date.now();
29
29
 
30
30
  if (opts.urlPresent) {
31
+ opts.cleanupMethod();
31
32
  return resolve({ [opts.md5ReturnKey]: opts.url });
32
33
  }
33
34
  if (!opts.archivePresent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.21.0",
3
+ "version": "1.22.0",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {