browserstack-cypress-cli 1.25.3 → 1.26.1

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.
Files changed (42) hide show
  1. package/.nyc_output/4de31829-b694-4567-a64d-b9f2a39aad8f.json +1 -0
  2. package/.nyc_output/5bfb514c-7f4c-4d7d-a340-aea45b6df22a.json +1 -0
  3. package/.nyc_output/6560b7ed-7bb3-4356-8e02-8e3b87e338df.json +1 -0
  4. package/.nyc_output/7bd0aff0-4e4e-48e2-a4b4-5759ca2809a1.json +1 -0
  5. package/.nyc_output/9026361d-cf67-46f1-be8c-1cca46df290c.json +1 -0
  6. package/.nyc_output/96b48768-47a7-4ce2-a594-f8cce51372d0.json +1 -0
  7. package/.nyc_output/981ac816-df8a-44d0-a0c4-492f9866d7ae.json +1 -0
  8. package/.nyc_output/ad567238-328d-4698-917f-a91539e16070.json +1 -0
  9. package/.nyc_output/ad864605-6250-44da-a38d-e3fc5d9d3d7d.json +1 -0
  10. package/.nyc_output/c6e6f4da-56a6-437e-b5f0-82d29d9536e6.json +1 -0
  11. package/.nyc_output/cb28d15a-b052-44a2-89d1-184cdf7a4ffc.json +1 -0
  12. package/.nyc_output/dc944854-f4c9-49a2-a907-b8eacbe61ea2.json +1 -0
  13. package/.nyc_output/e93ac7d5-aca6-473c-b715-9b11594cd0ff.json +1 -0
  14. package/.nyc_output/e97f3f73-9ecb-4391-aa1a-8afe1fd3895b.json +1 -0
  15. package/.nyc_output/processinfo/4de31829-b694-4567-a64d-b9f2a39aad8f.json +1 -0
  16. package/.nyc_output/processinfo/5bfb514c-7f4c-4d7d-a340-aea45b6df22a.json +1 -0
  17. package/.nyc_output/processinfo/6560b7ed-7bb3-4356-8e02-8e3b87e338df.json +1 -0
  18. package/.nyc_output/processinfo/7bd0aff0-4e4e-48e2-a4b4-5759ca2809a1.json +1 -0
  19. package/.nyc_output/processinfo/9026361d-cf67-46f1-be8c-1cca46df290c.json +1 -0
  20. package/.nyc_output/processinfo/96b48768-47a7-4ce2-a594-f8cce51372d0.json +1 -0
  21. package/.nyc_output/processinfo/981ac816-df8a-44d0-a0c4-492f9866d7ae.json +1 -0
  22. package/.nyc_output/processinfo/ad567238-328d-4698-917f-a91539e16070.json +1 -0
  23. package/.nyc_output/processinfo/ad864605-6250-44da-a38d-e3fc5d9d3d7d.json +1 -0
  24. package/.nyc_output/processinfo/c6e6f4da-56a6-437e-b5f0-82d29d9536e6.json +1 -0
  25. package/.nyc_output/processinfo/cb28d15a-b052-44a2-89d1-184cdf7a4ffc.json +1 -0
  26. package/.nyc_output/processinfo/dc944854-f4c9-49a2-a907-b8eacbe61ea2.json +1 -0
  27. package/.nyc_output/processinfo/e93ac7d5-aca6-473c-b715-9b11594cd0ff.json +1 -0
  28. package/.nyc_output/processinfo/e97f3f73-9ecb-4391-aa1a-8afe1fd3895b.json +1 -0
  29. package/.nyc_output/processinfo/index.json +1 -0
  30. package/bin/accessibility-automation/constants.js +1 -0
  31. package/bin/accessibility-automation/cypress/index.js +140 -0
  32. package/bin/accessibility-automation/helper.js +218 -0
  33. package/bin/accessibility-automation/plugin/index.js +43 -0
  34. package/bin/commands/runs.js +16 -0
  35. package/bin/helpers/buildArtifacts.js +13 -3
  36. package/bin/helpers/capabilityHelper.js +17 -0
  37. package/bin/helpers/constants.js +3 -1
  38. package/bin/helpers/helper.js +305 -0
  39. package/bin/helpers/utils.js +35 -14
  40. package/bin/testObservability/helper/helper.js +7 -231
  41. package/log/usage.log +7 -0
  42. package/package.json +1 -1
@@ -0,0 +1,305 @@
1
+ /* Helper methods used by Accessibility and Observability */
2
+
3
+ const logger = require("../helpers/logger").winstonLogger;
4
+ const utils = require('../helpers/utils');
5
+ const fs = require('fs');
6
+ const path = require('path');
7
+ const http = require('http');
8
+ const https = require('https');
9
+ const request = require('request');
10
+ const gitLastCommit = require('git-last-commit');
11
+ const { v4: uuidv4 } = require('uuid');
12
+ const os = require('os');
13
+ const { promisify } = require('util');
14
+ const getRepoInfo = require('git-repo-info');
15
+ const gitconfig = require('gitconfiglocal');
16
+ const { spawn, execSync } = require('child_process');
17
+ const glob = require('glob');
18
+ const pGitconfig = promisify(gitconfig);
19
+ const CrashReporter = require('../testObservability/crashReporter');
20
+
21
+ exports.debug = (text, shouldReport = false, throwable = null) => {
22
+ if (process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "true" || process.env.BROWSERSTACK_OBSERVABILITY_DEBUG === "1") {
23
+ logger.info(`[ OBSERVABILITY ] ${text}`);
24
+ }
25
+ if(shouldReport) {
26
+ CrashReporter.getInstance().uploadCrashReport(text, throwable ? throwable && throwable.stack : null);
27
+ }
28
+ }
29
+
30
+ exports.getFileSeparatorData = () => {
31
+ return /^win/.test(process.platform) ? "\\" : "/";
32
+ }
33
+
34
+ exports.findGitConfig = (filePath) => {
35
+ const fileSeparator = exports.getFileSeparatorData();
36
+ if(filePath == null || filePath == '' || filePath == fileSeparator) {
37
+ return null;
38
+ }
39
+ try {
40
+ fs.statSync(filePath + fileSeparator + '.git' + fileSeparator + 'config');
41
+ return filePath;
42
+ } catch(e) {
43
+ let parentFilePath = filePath.split(fileSeparator);
44
+ parentFilePath.pop();
45
+ return exports.findGitConfig(parentFilePath.join(fileSeparator));
46
+ }
47
+ }
48
+
49
+ let packages = {};
50
+ exports.getPackageVersion = (package_, bsConfig = null) => {
51
+ if(packages[package_]) return packages[package_];
52
+ let packageVersion;
53
+ /* Try to find version from module path */
54
+ try {
55
+ packages[package_] = this.requireModule(`${package_}/package.json`).version;
56
+ logger.info(`Getting ${package_} package version from module path = ${packages[package_]}`);
57
+ packageVersion = packages[package_];
58
+ } catch(e) {
59
+ exports.debug(`Unable to find package ${package_} at module path with error ${e}`);
60
+ }
61
+
62
+ /* Read package version from npm_dependencies in browserstack.json file if present */
63
+ if(utils.isUndefined(packageVersion) && bsConfig && (process.env.BROWSERSTACK_AUTOMATION == "true" || process.env.BROWSERSTACK_AUTOMATION == "1")) {
64
+ const runSettings = bsConfig.run_settings;
65
+ if (runSettings && runSettings.npm_dependencies !== undefined &&
66
+ Object.keys(runSettings.npm_dependencies).length !== 0 &&
67
+ typeof runSettings.npm_dependencies === 'object') {
68
+ if (package_ in runSettings.npm_dependencies) {
69
+ packages[package_] = runSettings.npm_dependencies[package_];
70
+ logger.info(`Getting ${package_} package version from browserstack.json = ${packages[package_]}`);
71
+ packageVersion = packages[package_];
72
+ }
73
+ }
74
+ }
75
+
76
+ /* Read package version from project's package.json if present */
77
+ const packageJSONPath = path.join(process.cwd(), 'package.json');
78
+ if(utils.isUndefined(packageVersion) && fs.existsSync(packageJSONPath)) {
79
+ const packageJSONContents = require(packageJSONPath);
80
+ if(packageJSONContents.devDependencies && !utils.isUndefined(packageJSONContents.devDependencies[package_])) packages[package_] = packageJSONContents.devDependencies[package_];
81
+ if(packageJSONContents.dependencies && !utils.isUndefined(packageJSONContents.dependencies[package_])) packages[package_] = packageJSONContents.dependencies[package_];
82
+ logger.info(`Getting ${package_} package version from package.json = ${packages[package_]}`);
83
+ packageVersion = packages[package_];
84
+ }
85
+
86
+ return packageVersion;
87
+ }
88
+
89
+ exports.getAgentVersion = () => {
90
+ let _path = path.join(__dirname, '../../package.json');
91
+ if(fs.existsSync(_path))
92
+ return require(_path).version;
93
+ }
94
+
95
+ exports.getGitMetaData = () => {
96
+ return new Promise(async (resolve, reject) => {
97
+ try {
98
+ var info = getRepoInfo();
99
+ if(!info.commonGitDir) {
100
+ logger.debug(`Unable to find a Git directory`);
101
+ exports.debug(`Unable to find a Git directory`);
102
+ resolve({});
103
+ }
104
+ if(!info.author && exports.findGitConfig(process.cwd())) {
105
+ /* commit objects are packed */
106
+ gitLastCommit.getLastCommit(async (err, commit) => {
107
+ if(err) {
108
+ logger.debug(`Exception in populating Git Metadata with error : ${err}`, true, err);
109
+ exports.debug(`Exception in populating Git Metadata with error : ${err}`, true, err);
110
+ return resolve({});
111
+ }
112
+ try {
113
+ info["author"] = info["author"] || `${commit["author"]["name"].replace(/[“]+/g, '')} <${commit["author"]["email"].replace(/[“]+/g, '')}>`;
114
+ info["authorDate"] = info["authorDate"] || commit["authoredOn"];
115
+ info["committer"] = info["committer"] || `${commit["committer"]["name"].replace(/[“]+/g, '')} <${commit["committer"]["email"].replace(/[“]+/g, '')}>`;
116
+ info["committerDate"] = info["committerDate"] || commit["committedOn"];
117
+ info["commitMessage"] = info["commitMessage"] || commit["subject"];
118
+
119
+ const { remote } = await pGitconfig(info.commonGitDir);
120
+ const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
121
+ resolve({
122
+ "name": "git",
123
+ "sha": info["sha"],
124
+ "short_sha": info["abbreviatedSha"],
125
+ "branch": info["branch"],
126
+ "tag": info["tag"],
127
+ "committer": info["committer"],
128
+ "committer_date": info["committerDate"],
129
+ "author": info["author"],
130
+ "author_date": info["authorDate"],
131
+ "commit_message": info["commitMessage"],
132
+ "root": info["root"],
133
+ "common_git_dir": info["commonGitDir"],
134
+ "worktree_git_dir": info["worktreeGitDir"],
135
+ "last_tag": info["lastTag"],
136
+ "commits_since_last_tag": info["commitsSinceLastTag"],
137
+ "remotes": remotes
138
+ });
139
+ } catch(e) {
140
+ exports.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
141
+ logger.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
142
+ return resolve({});
143
+ }
144
+ }, {dst: exports.findGitConfig(process.cwd())});
145
+ } else {
146
+ const { remote } = await pGitconfig(info.commonGitDir);
147
+ const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
148
+ resolve({
149
+ "name": "git",
150
+ "sha": info["sha"],
151
+ "short_sha": info["abbreviatedSha"],
152
+ "branch": info["branch"],
153
+ "tag": info["tag"],
154
+ "committer": info["committer"],
155
+ "committer_date": info["committerDate"],
156
+ "author": info["author"],
157
+ "author_date": info["authorDate"],
158
+ "commit_message": info["commitMessage"],
159
+ "root": info["root"],
160
+ "common_git_dir": info["commonGitDir"],
161
+ "worktree_git_dir": info["worktreeGitDir"],
162
+ "last_tag": info["lastTag"],
163
+ "commits_since_last_tag": info["commitsSinceLastTag"],
164
+ "remotes": remotes
165
+ });
166
+ }
167
+ } catch(err) {
168
+ exports.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
169
+ logger.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
170
+ resolve({});
171
+ }
172
+ })
173
+ }
174
+ exports.getCiInfo = () => {
175
+ var env = process.env;
176
+ // Jenkins
177
+ if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
178
+ return {
179
+ name: "Jenkins",
180
+ build_url: env.BUILD_URL,
181
+ job_name: env.JOB_NAME,
182
+ build_number: env.BUILD_NUMBER
183
+ }
184
+ }
185
+ // CircleCI
186
+ if (env.CI === "true" && env.CIRCLECI === "true") {
187
+ return {
188
+ name: "CircleCI",
189
+ build_url: env.CIRCLE_BUILD_URL,
190
+ job_name: env.CIRCLE_JOB,
191
+ build_number: env.CIRCLE_BUILD_NUM
192
+ }
193
+ }
194
+ // Travis CI
195
+ if (env.CI === "true" && env.TRAVIS === "true") {
196
+ return {
197
+ name: "Travis CI",
198
+ build_url: env.TRAVIS_BUILD_WEB_URL,
199
+ job_name: env.TRAVIS_JOB_NAME,
200
+ build_number: env.TRAVIS_BUILD_NUMBER
201
+ }
202
+ }
203
+ // Codeship
204
+ if (env.CI === "true" && env.CI_NAME === "codeship") {
205
+ return {
206
+ name: "Codeship",
207
+ build_url: null,
208
+ job_name: null,
209
+ build_number: null
210
+ }
211
+ }
212
+ // Bitbucket
213
+ if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
214
+ return {
215
+ name: "Bitbucket",
216
+ build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
217
+ job_name: null,
218
+ build_number: env.BITBUCKET_BUILD_NUMBER
219
+ }
220
+ }
221
+ // Drone
222
+ if (env.CI === "true" && env.DRONE === "true") {
223
+ return {
224
+ name: "Drone",
225
+ build_url: env.DRONE_BUILD_LINK,
226
+ job_name: null,
227
+ build_number: env.DRONE_BUILD_NUMBER
228
+ }
229
+ }
230
+ // Semaphore
231
+ if (env.CI === "true" && env.SEMAPHORE === "true") {
232
+ return {
233
+ name: "Semaphore",
234
+ build_url: env.SEMAPHORE_ORGANIZATION_URL,
235
+ job_name: env.SEMAPHORE_JOB_NAME,
236
+ build_number: env.SEMAPHORE_JOB_ID
237
+ }
238
+ }
239
+ // GitLab
240
+ if (env.CI === "true" && env.GITLAB_CI === "true") {
241
+ return {
242
+ name: "GitLab",
243
+ build_url: env.CI_JOB_URL,
244
+ job_name: env.CI_JOB_NAME,
245
+ build_number: env.CI_JOB_ID
246
+ }
247
+ }
248
+ // Buildkite
249
+ if (env.CI === "true" && env.BUILDKITE === "true") {
250
+ return {
251
+ name: "Buildkite",
252
+ build_url: env.BUILDKITE_BUILD_URL,
253
+ job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
254
+ build_number: env.BUILDKITE_BUILD_NUMBER
255
+ }
256
+ }
257
+ // Visual Studio Team Services
258
+ if (env.TF_BUILD === "True") {
259
+ return {
260
+ name: "Visual Studio Team Services",
261
+ build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
262
+ job_name: env.SYSTEM_DEFINITIONID,
263
+ build_number: env.BUILD_BUILDID
264
+ }
265
+ }
266
+ // if no matches, return null
267
+ return null;
268
+ }
269
+
270
+ exports.getBuildDetails = (bsConfig) => {
271
+ let buildName = '',
272
+ projectName = '',
273
+ buildDescription = '',
274
+ buildTags = [];
275
+
276
+ /* Pick from environment variables */
277
+ buildName = process.env.BROWSERSTACK_BUILD_NAME || buildName;
278
+ projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName;
279
+
280
+ /* Pick from run settings */
281
+ buildName = buildName || bsConfig["run_settings"]["build_name"];
282
+ projectName = projectName || bsConfig["run_settings"]["project_name"];
283
+ if(!utils.isUndefined(bsConfig["run_settings"]["build_tag"])) buildTags = [...buildTags, bsConfig["run_settings"]["build_tag"]];
284
+
285
+ buildName = buildName || path.basename(path.resolve(process.cwd()));
286
+
287
+ return {
288
+ buildName,
289
+ projectName,
290
+ buildDescription,
291
+ buildTags
292
+ };
293
+ }
294
+
295
+ exports.setBrowserstackCypressCliDependency = (bsConfig) => {
296
+ const runSettings = bsConfig.run_settings;
297
+ if (runSettings.npm_dependencies !== undefined &&
298
+ typeof runSettings.npm_dependencies === 'object') {
299
+ if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) {
300
+ logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies");
301
+ runSettings.npm_dependencies['browserstack-cypress-cli'] = this.getAgentVersion() || "latest";
302
+ logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`);
303
+ }
304
+ }
305
+ }
@@ -558,6 +558,23 @@ exports.setSystemEnvs = (bsConfig) => {
558
558
  });
559
559
  }
560
560
 
561
+ try {
562
+ const accessibilityOptions = bsConfig.run_settings.accessibilityOptions;
563
+ if (accessibilityOptions) {
564
+ Object.keys(accessibilityOptions).forEach(key => {
565
+ const a11y_env_key = `ACCESSIBILITY_${key.toUpperCase()}`
566
+ if (["includeTagsInTestingScope", "excludeTagsInTestingScope"].includes(key))
567
+ envKeys[a11y_env_key] = accessibilityOptions[key].join(";")
568
+ else if (key === "includeIssueType")
569
+ envKeys[a11y_env_key] = JSON.stringify(accessibilityOptions.includeIssueType).replaceAll('"', "")
570
+ else
571
+ envKeys[a11y_env_key] = accessibilityOptions[key];
572
+ })
573
+ }
574
+ } catch (error) {
575
+ logger.error(`Error in adding accessibility configs ${error}`)
576
+ }
577
+
561
578
  try {
562
579
  OBSERVABILITY_ENV_VARS.forEach(key => {
563
580
  envKeys[key] = process.env[key];
@@ -1297,25 +1314,29 @@ exports.readBsConfigJSON = (bsConfigPath) => {
1297
1314
  }
1298
1315
 
1299
1316
  exports.getCypressConfigFile = (bsConfig) => {
1300
- let cypressConfigFile = undefined;
1301
- if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
1302
- if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) {
1317
+ try {
1318
+ let cypressConfigFile = undefined;
1319
+ if (bsConfig.run_settings.cypressTestSuiteType === Constants.CYPRESS_V10_AND_ABOVE_TYPE) {
1320
+ if (bsConfig.run_settings.cypress_config_filename.endsWith("cypress.config.js")) {
1321
+ if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
1322
+ cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
1323
+ } else if (bsConfig.run_settings.cypressProjectDir) {
1324
+ cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename));
1325
+ }
1326
+ } else {
1327
+ cypressConfigFile = {};
1328
+ }
1329
+ } else {
1303
1330
  if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
1304
- cypressConfigFile = require(path.resolve(bsConfig.run_settings.cypressConfigFilePath));
1331
+ cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath))
1305
1332
  } else if (bsConfig.run_settings.cypressProjectDir) {
1306
- cypressConfigFile = require(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename));
1333
+ cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)));
1307
1334
  }
1308
- } else {
1309
- cypressConfigFile = {};
1310
- }
1311
- } else {
1312
- if (bsConfig.run_settings.cypress_config_file && bsConfig.run_settings.cypress_config_filename !== 'false') {
1313
- cypressConfigFile = JSON.parse(fs.readFileSync(bsConfig.run_settings.cypressConfigFilePath))
1314
- } else if (bsConfig.run_settings.cypressProjectDir) {
1315
- cypressConfigFile = JSON.parse(fs.readFileSync(path.join(bsConfig.run_settings.cypressProjectDir, bsConfig.run_settings.cypress_config_filename)));
1316
1335
  }
1336
+ return cypressConfigFile;
1337
+ } catch (err) {
1338
+ return {}
1317
1339
  }
1318
- return cypressConfigFile;
1319
1340
  }
1320
1341
 
1321
1342
  exports.setCLIMode = (bsConfig, args) => {
@@ -3,11 +3,9 @@ const path = require('path');
3
3
  const http = require('http');
4
4
  const https = require('https');
5
5
  const request = require('request');
6
- var gitLastCommit = require('git-last-commit');
7
6
  const { v4: uuidv4 } = require('uuid');
8
7
  const os = require('os');
9
8
  const { promisify } = require('util');
10
- const getRepoInfo = require('git-repo-info');
11
9
  const gitconfig = require('gitconfiglocal');
12
10
  const { spawn, execSync } = require('child_process');
13
11
  const glob = require('glob');
@@ -16,6 +14,8 @@ const pGitconfig = promisify(gitconfig);
16
14
 
17
15
  const logger = require("../../helpers/logger").winstonLogger;
18
16
  const utils = require('../../helpers/utils');
17
+ const helper = require('../../helpers/helper');
18
+
19
19
  const CrashReporter = require('../crashReporter');
20
20
 
21
21
  // Getting global packages path
@@ -181,178 +181,6 @@ exports.findGitConfig = (filePath) => {
181
181
  }
182
182
  }
183
183
 
184
- const getGitMetaData = () => {
185
- return new Promise(async (resolve, reject) => {
186
- try {
187
- var info = getRepoInfo();
188
- if(!info.commonGitDir) {
189
- exports.debug(`Unable to find a Git directory`);
190
- resolve({});
191
- }
192
- if(!info.author && exports.findGitConfig(process.cwd())) {
193
- /* commit objects are packed */
194
- gitLastCommit.getLastCommit(async (err, commit) => {
195
- if(err) {
196
- exports.debug(`Exception in populating Git Metadata with error : ${err}`, true, err);
197
- return resolve({});
198
- }
199
- try {
200
- info["author"] = info["author"] || `${commit["author"]["name"].replace(/[“]+/g, '')} <${commit["author"]["email"].replace(/[“]+/g, '')}>`;
201
- info["authorDate"] = info["authorDate"] || commit["authoredOn"];
202
- info["committer"] = info["committer"] || `${commit["committer"]["name"].replace(/[“]+/g, '')} <${commit["committer"]["email"].replace(/[“]+/g, '')}>`;
203
- info["committerDate"] = info["committerDate"] || commit["committedOn"];
204
- info["commitMessage"] = info["commitMessage"] || commit["subject"];
205
-
206
- const { remote } = await pGitconfig(info.commonGitDir);
207
- const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
208
- resolve({
209
- "name": "git",
210
- "sha": info["sha"],
211
- "short_sha": info["abbreviatedSha"],
212
- "branch": info["branch"],
213
- "tag": info["tag"],
214
- "committer": info["committer"],
215
- "committer_date": info["committerDate"],
216
- "author": info["author"],
217
- "author_date": info["authorDate"],
218
- "commit_message": info["commitMessage"],
219
- "root": info["root"],
220
- "common_git_dir": info["commonGitDir"],
221
- "worktree_git_dir": info["worktreeGitDir"],
222
- "last_tag": info["lastTag"],
223
- "commits_since_last_tag": info["commitsSinceLastTag"],
224
- "remotes": remotes
225
- });
226
- } catch(e) {
227
- exports.debug(`Exception in populating Git Metadata with error : ${e}`, true, e);
228
- return resolve({});
229
- }
230
- }, {dst: exports.findGitConfig(process.cwd())});
231
- } else {
232
- const { remote } = await pGitconfig(info.commonGitDir);
233
- const remotes = Object.keys(remote).map(remoteName => ({name: remoteName, url: remote[remoteName]['url']}));
234
- resolve({
235
- "name": "git",
236
- "sha": info["sha"],
237
- "short_sha": info["abbreviatedSha"],
238
- "branch": info["branch"],
239
- "tag": info["tag"],
240
- "committer": info["committer"],
241
- "committer_date": info["committerDate"],
242
- "author": info["author"],
243
- "author_date": info["authorDate"],
244
- "commit_message": info["commitMessage"],
245
- "root": info["root"],
246
- "common_git_dir": info["commonGitDir"],
247
- "worktree_git_dir": info["worktreeGitDir"],
248
- "last_tag": info["lastTag"],
249
- "commits_since_last_tag": info["commitsSinceLastTag"],
250
- "remotes": remotes
251
- });
252
- }
253
- } catch(err) {
254
- exports.debug(`Exception in populating Git metadata with error : ${err}`, true, err);
255
- resolve({});
256
- }
257
- })
258
- }
259
-
260
- const getCiInfo = () => {
261
- var env = process.env;
262
- // Jenkins
263
- if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
264
- return {
265
- name: "Jenkins",
266
- build_url: env.BUILD_URL,
267
- job_name: env.JOB_NAME,
268
- build_number: env.BUILD_NUMBER
269
- }
270
- }
271
- // CircleCI
272
- if (env.CI === "true" && env.CIRCLECI === "true") {
273
- return {
274
- name: "CircleCI",
275
- build_url: env.CIRCLE_BUILD_URL,
276
- job_name: env.CIRCLE_JOB,
277
- build_number: env.CIRCLE_BUILD_NUM
278
- }
279
- }
280
- // Travis CI
281
- if (env.CI === "true" && env.TRAVIS === "true") {
282
- return {
283
- name: "Travis CI",
284
- build_url: env.TRAVIS_BUILD_WEB_URL,
285
- job_name: env.TRAVIS_JOB_NAME,
286
- build_number: env.TRAVIS_BUILD_NUMBER
287
- }
288
- }
289
- // Codeship
290
- if (env.CI === "true" && env.CI_NAME === "codeship") {
291
- return {
292
- name: "Codeship",
293
- build_url: null,
294
- job_name: null,
295
- build_number: null
296
- }
297
- }
298
- // Bitbucket
299
- if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
300
- return {
301
- name: "Bitbucket",
302
- build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
303
- job_name: null,
304
- build_number: env.BITBUCKET_BUILD_NUMBER
305
- }
306
- }
307
- // Drone
308
- if (env.CI === "true" && env.DRONE === "true") {
309
- return {
310
- name: "Drone",
311
- build_url: env.DRONE_BUILD_LINK,
312
- job_name: null,
313
- build_number: env.DRONE_BUILD_NUMBER
314
- }
315
- }
316
- // Semaphore
317
- if (env.CI === "true" && env.SEMAPHORE === "true") {
318
- return {
319
- name: "Semaphore",
320
- build_url: env.SEMAPHORE_ORGANIZATION_URL,
321
- job_name: env.SEMAPHORE_JOB_NAME,
322
- build_number: env.SEMAPHORE_JOB_ID
323
- }
324
- }
325
- // GitLab
326
- if (env.CI === "true" && env.GITLAB_CI === "true") {
327
- return {
328
- name: "GitLab",
329
- build_url: env.CI_JOB_URL,
330
- job_name: env.CI_JOB_NAME,
331
- build_number: env.CI_JOB_ID
332
- }
333
- }
334
- // Buildkite
335
- if (env.CI === "true" && env.BUILDKITE === "true") {
336
- return {
337
- name: "Buildkite",
338
- build_url: env.BUILDKITE_BUILD_URL,
339
- job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
340
- build_number: env.BUILDKITE_BUILD_NUMBER
341
- }
342
- }
343
- // Visual Studio Team Services
344
- if (env.TF_BUILD === "True") {
345
- return {
346
- name: "Visual Studio Team Services",
347
- build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
348
- job_name: env.SYSTEM_DEFINITIONID,
349
- build_number: env.BUILD_BUILDID
350
- }
351
- }
352
- // if no matches, return null
353
- return null;
354
- }
355
-
356
184
  let packages = {};
357
185
 
358
186
  exports.getPackageVersion = (package_, bsConfig = null) => {
@@ -394,12 +222,6 @@ exports.getPackageVersion = (package_, bsConfig = null) => {
394
222
  return packageVersion;
395
223
  }
396
224
 
397
- exports.getAgentVersion = () => {
398
- let _path = path.join(__dirname, '../../../package.json');
399
- if(fs.existsSync(_path))
400
- return require(_path).version;
401
- }
402
-
403
225
  const setEnvironmentVariablesForRemoteReporter = (BS_TESTOPS_JWT, BS_TESTOPS_BUILD_HASHED_ID, BS_TESTOPS_ALLOW_SCREENSHOTS, OBSERVABILITY_LAUNCH_SDK_VERSION) => {
404
226
  process.env.BS_TESTOPS_JWT = BS_TESTOPS_JWT;
405
227
  process.env.BS_TESTOPS_BUILD_HASHED_ID = BS_TESTOPS_BUILD_HASHED_ID;
@@ -442,52 +264,6 @@ const setEventListeners = () => {
442
264
  }
443
265
  }
444
266
 
445
- const getBuildDetails = (bsConfig) => {
446
- const isTestObservabilityOptionsPresent = !utils.isUndefined(bsConfig["testObservabilityOptions"]);
447
- let buildName = '',
448
- projectName = '',
449
- buildDescription = '',
450
- buildTags = [];
451
-
452
- /* Pick from environment variables */
453
- buildName = process.env.BROWSERSTACK_BUILD_NAME || buildName;
454
- projectName = process.env.BROWSERSTACK_PROJECT_NAME || projectName;
455
-
456
- /* Pick from testObservabilityOptions */
457
- if(isTestObservabilityOptionsPresent) {
458
- buildName = buildName || bsConfig["testObservabilityOptions"]["buildName"];
459
- projectName = projectName || bsConfig["testObservabilityOptions"]["projectName"];
460
- if(!utils.isUndefined(bsConfig["testObservabilityOptions"]["buildTag"])) buildTags = [...buildTags, ...bsConfig["testObservabilityOptions"]["buildTag"]];
461
- buildDescription = buildDescription || bsConfig["testObservabilityOptions"]["buildDescription"];
462
- }
463
-
464
- /* Pick from run settings */
465
- buildName = buildName || bsConfig["run_settings"]["build_name"];
466
- projectName = projectName || bsConfig["run_settings"]["project_name"];
467
- if(!utils.isUndefined(bsConfig["run_settings"]["build_tag"])) buildTags = [...buildTags, bsConfig["run_settings"]["build_tag"]];
468
-
469
- buildName = buildName || path.basename(path.resolve(process.cwd()));
470
-
471
- return {
472
- buildName,
473
- projectName,
474
- buildDescription,
475
- buildTags
476
- };
477
- }
478
-
479
- const setBrowserstackCypressCliDependency = (bsConfig) => {
480
- const runSettings = bsConfig.run_settings;
481
- if (runSettings.npm_dependencies !== undefined &&
482
- typeof runSettings.npm_dependencies === 'object') {
483
- if (!("browserstack-cypress-cli" in runSettings.npm_dependencies)) {
484
- logger.warn("Missing browserstack-cypress-cli not found in npm_dependencies");
485
- runSettings.npm_dependencies['browserstack-cypress-cli'] = exports.getAgentVersion() || "latest";
486
- logger.warn(`Adding browserstack-cypress-cli version ${runSettings.npm_dependencies['browserstack-cypress-cli']} in npm_dependencies`);
487
- }
488
- }
489
- }
490
-
491
267
  const getCypressConfigFileContent = (bsConfig, cypressConfigPath) => {
492
268
  try {
493
269
  const cypressConfigFile = require(path.resolve(bsConfig ? bsConfig.run_settings.cypress_config_file : cypressConfigPath));
@@ -551,7 +327,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
551
327
  projectName,
552
328
  buildDescription,
553
329
  buildTags
554
- } = getBuildDetails(user_config);
330
+ } = helper.getBuildDetails(user_config);
555
331
  const data = {
556
332
  'format': 'json',
557
333
  'project_name': projectName,
@@ -566,14 +342,14 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
566
342
  version: os.version(),
567
343
  arch: os.arch()
568
344
  },
569
- 'ci_info': getCiInfo(),
345
+ 'ci_info': helper.getCiInfo(),
570
346
  'build_run_identifier': process.env.BROWSERSTACK_BUILD_RUN_IDENTIFIER,
571
347
  'failed_tests_rerun': process.env.BROWSERSTACK_RERUN || false,
572
- 'version_control': await getGitMetaData(),
348
+ 'version_control': await helper.getGitMetaData(),
573
349
  'observability_version': {
574
350
  frameworkName: "Cypress",
575
351
  frameworkVersion: exports.getPackageVersion('cypress', user_config),
576
- sdkVersion: exports.getAgentVersion()
352
+ sdkVersion: helper.getAgentVersion()
577
353
  }
578
354
  };
579
355
  const config = {
@@ -592,7 +368,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
592
368
  process.env.BS_TESTOPS_BUILD_COMPLETED = true;
593
369
  setEnvironmentVariablesForRemoteReporter(response.data.jwt, response.data.build_hashed_id, response.data.allow_screenshots, data.observability_version.sdkVersion);
594
370
  // setEventListeners();
595
- if(this.isBrowserstackInfra()) setBrowserstackCypressCliDependency(user_config);
371
+ if(this.isBrowserstackInfra()) helper.setBrowserstackCypressCliDependency(user_config);
596
372
  } catch(error) {
597
373
  if(!error.errorType) {
598
374
  if (error.response) {