browserstack-cypress-cli 1.36.3 → 1.36.5

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.
package/CODEOWNERS CHANGED
@@ -1 +1,18 @@
1
+ # Default ownership for all other files
1
2
  * @browserstack/automate-dev
3
+
4
+ # Ownership for the CODEOWNERS file
5
+ CODEOWNERS @browserstack/sdk-dev @browserstack/automate-dev
6
+
7
+ # Ownership for SDK-related files
8
+ bin/testhub/ @browserstack/sdk-dev
9
+ bin/accessibility-automation/ @browserstack/sdk-dev
10
+ bin/testObservability/ @browserstack/sdk-dev
11
+
12
+ # Shared ownership for certain files
13
+ /.gitignore @browserstack/sdk-dev @browserstack/automate-dev
14
+ /package.json @browserstack/sdk-dev @browserstack/automate-dev
15
+ bin/commands/runs.js @browserstack/sdk-dev @browserstack/automate-dev
16
+ bin/helpers/helper.js @browserstack/sdk-dev @browserstack/automate-dev
17
+ bin/helpers/logger.js @browserstack/sdk-dev @browserstack/automate-dev
18
+ bin/helpers/utils.js @browserstack/sdk-dev @browserstack/automate-dev
@@ -195,6 +195,7 @@ exports.getHostInfo = () => {
195
195
 
196
196
  exports.getCiInfo = () => {
197
197
  var env = process.env;
198
+
198
199
  // Jenkins
199
200
  if ((typeof env.JENKINS_URL === "string" && env.JENKINS_URL.length > 0) || (typeof env.JENKINS_HOME === "string" && env.JENKINS_HOME.length > 0)) {
200
201
  return {
@@ -202,7 +203,7 @@ exports.getCiInfo = () => {
202
203
  build_url: env.BUILD_URL,
203
204
  job_name: env.JOB_NAME,
204
205
  build_number: env.BUILD_NUMBER
205
- }
206
+ };
206
207
  }
207
208
  // CircleCI
208
209
  if (env.CI === "true" && env.CIRCLECI === "true") {
@@ -211,7 +212,7 @@ exports.getCiInfo = () => {
211
212
  build_url: env.CIRCLE_BUILD_URL,
212
213
  job_name: env.CIRCLE_JOB,
213
214
  build_number: env.CIRCLE_BUILD_NUM
214
- }
215
+ };
215
216
  }
216
217
  // Travis CI
217
218
  if (env.CI === "true" && env.TRAVIS === "true") {
@@ -220,7 +221,7 @@ exports.getCiInfo = () => {
220
221
  build_url: env.TRAVIS_BUILD_WEB_URL,
221
222
  job_name: env.TRAVIS_JOB_NAME,
222
223
  build_number: env.TRAVIS_BUILD_NUMBER
223
- }
224
+ };
224
225
  }
225
226
  // Codeship
226
227
  if (env.CI === "true" && env.CI_NAME === "codeship") {
@@ -229,7 +230,7 @@ exports.getCiInfo = () => {
229
230
  build_url: null,
230
231
  job_name: null,
231
232
  build_number: null
232
- }
233
+ };
233
234
  }
234
235
  // Bitbucket
235
236
  if (env.BITBUCKET_BRANCH && env.BITBUCKET_COMMIT) {
@@ -238,7 +239,7 @@ exports.getCiInfo = () => {
238
239
  build_url: env.BITBUCKET_GIT_HTTP_ORIGIN,
239
240
  job_name: null,
240
241
  build_number: env.BITBUCKET_BUILD_NUMBER
241
- }
242
+ };
242
243
  }
243
244
  // Drone
244
245
  if (env.CI === "true" && env.DRONE === "true") {
@@ -247,7 +248,7 @@ exports.getCiInfo = () => {
247
248
  build_url: env.DRONE_BUILD_LINK,
248
249
  job_name: null,
249
250
  build_number: env.DRONE_BUILD_NUMBER
250
- }
251
+ };
251
252
  }
252
253
  // Semaphore
253
254
  if (env.CI === "true" && env.SEMAPHORE === "true") {
@@ -256,7 +257,7 @@ exports.getCiInfo = () => {
256
257
  build_url: env.SEMAPHORE_ORGANIZATION_URL,
257
258
  job_name: env.SEMAPHORE_JOB_NAME,
258
259
  build_number: env.SEMAPHORE_JOB_ID
259
- }
260
+ };
260
261
  }
261
262
  // GitLab
262
263
  if (env.CI === "true" && env.GITLAB_CI === "true") {
@@ -265,7 +266,16 @@ exports.getCiInfo = () => {
265
266
  build_url: env.CI_JOB_URL,
266
267
  job_name: env.CI_JOB_NAME,
267
268
  build_number: env.CI_JOB_ID
268
- }
269
+ };
270
+ }
271
+ // GitHub Actions
272
+ if (env.GITHUB_ACTIONS === "true" || env.CI === "true" && env.GITHUB_RUN_ID) {
273
+ return {
274
+ name: "GitHub Actions",
275
+ build_url: `${env.GITHUB_SERVER_URL || 'https://github.com'}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}`,
276
+ job_name: env.GITHUB_WORKFLOW || env.GITHUB_JOB,
277
+ build_number: env.GITHUB_RUN_NUMBER
278
+ };
269
279
  }
270
280
  // Buildkite
271
281
  if (env.CI === "true" && env.BUILDKITE === "true") {
@@ -274,7 +284,7 @@ exports.getCiInfo = () => {
274
284
  build_url: env.BUILDKITE_BUILD_URL,
275
285
  job_name: env.BUILDKITE_LABEL || env.BUILDKITE_PIPELINE_NAME,
276
286
  build_number: env.BUILDKITE_BUILD_NUMBER
277
- }
287
+ };
278
288
  }
279
289
  // Visual Studio Team Services
280
290
  if (env.TF_BUILD === "True") {
@@ -283,7 +293,7 @@ exports.getCiInfo = () => {
283
293
  build_url: `${env.SYSTEM_TEAMFOUNDATIONSERVERURI}${env.SYSTEM_TEAMPROJECTID}`,
284
294
  job_name: env.SYSTEM_DEFINITIONID,
285
295
  build_number: env.BUILD_BUILDID
286
- }
296
+ };
287
297
  }
288
298
  // if no matches, return null
289
299
  return null;
@@ -160,6 +160,10 @@ function ci_environment() {
160
160
  if (env.CI === "true" && env.GITLAB_CI === "true") {
161
161
  return "GitLab";
162
162
  }
163
+ // GitHub Actions
164
+ if (env.GITHUB_ACTIONS === "true" || (env.CI === "true" && env.GITHUB_RUN_ID)) {
165
+ return "GitHub Actions";
166
+ }
163
167
  // Buildkite
164
168
  if (env.CI === "true" && env.BUILDKITE === "true") {
165
169
  return "Buildkite";
@@ -27,6 +27,7 @@ Cypress.on('log:changed', (attrs) => {
27
27
 
28
28
  if (attrs.name === 'assert') {
29
29
  const assertMessage = (attrs.message || '')
30
+ const actualLocation = (attrs.testId === attrs.hookId) ? 'test' : 'hook';
30
31
 
31
32
  eventsQueue.push({
32
33
  task: 'test_observability_command',
@@ -36,11 +37,13 @@ Cypress.on('log:changed', (attrs) => {
36
37
  attributes: {
37
38
  id: attrs.id,
38
39
  name: 'assert',
40
+ testId: attrs.testId,
41
+ hookId: attrs.hookId,
39
42
  args: [assertMessage]
40
43
  },
41
44
  state: 'pending',
42
45
  started_at: new Date(attrs.createdAtTimestamp).toISOString(),
43
- location: testRunStarted ? 'test' : 'hook'
46
+ location: actualLocation
44
47
  }
45
48
  },
46
49
  options: { log: false }
@@ -54,11 +57,13 @@ Cypress.on('log:changed', (attrs) => {
54
57
  attributes: {
55
58
  id: attrs.id,
56
59
  name: 'assert',
60
+ testId: attrs.testId,
61
+ hookId: attrs.hookId,
57
62
  args: [assertMessage]
58
63
  },
59
64
  state: attrs.state,
60
65
  finished_at: new Date(attrs.updatedAtTimestamp).toISOString(),
61
- location: testRunStarted ? 'test' : 'hook'
66
+ location: actualLocation
62
67
  }
63
68
  },
64
69
  options: { log: false }
@@ -407,6 +407,7 @@ exports.launchTestSession = async (user_config, bsConfigPath) => {
407
407
  sdkVersion: helper.getAgentVersion()
408
408
  }
409
409
  };
410
+
410
411
  const config = {
411
412
  auth: {
412
413
  username: obsUserName,
@@ -77,6 +77,7 @@ class MyReporter {
77
77
  this.hooksStarted = {};
78
78
  this.beforeHooks = [];
79
79
  this.testIdMap = {};
80
+ this.internalIdMap = {};
80
81
  this.platformDetailsMap = {};
81
82
  this.runStatusMarkedHash = {};
82
83
  this.haveSentBuildUpdate = false;
@@ -101,6 +102,8 @@ class MyReporter {
101
102
  delete this.runStatusMarkedHash[hook.hookAnalyticsId];
102
103
  hook.hookAnalyticsId = uuidv4();
103
104
  }
105
+
106
+ if (hook.id) this.internalIdMap[hook.id] = hook.hookAnalyticsId;
104
107
  debugOnConsole(`[MOCHA EVENT] EVENT_HOOK_BEGIN for uuid: ${hook.hookAnalyticsId}`);
105
108
  hook.hook_started_at = (new Date()).toISOString();
106
109
  hook.started_at = (new Date()).toISOString();
@@ -132,7 +135,11 @@ class MyReporter {
132
135
  }
133
136
  })
134
137
 
135
- .on(EVENT_SUITE_END, (suite) => {
138
+ .on(EVENT_SUITE_END, (suite) => {
139
+ if (suite.root) {
140
+ debugOnConsole(`[MOCHA EVENT] EVENT_SUITE_END for root suite`);
141
+ this.internalIdMap = {};
142
+ }
136
143
  })
137
144
 
138
145
  .on(EVENT_TEST_PASS, async (test) => {
@@ -213,12 +220,29 @@ class MyReporter {
213
220
  }
214
221
 
215
222
  isInternalHook(hook) {
216
- if (hook && hook.body && hook.body.includes('/* browserstack internal helper hook */')) {
217
- return true;
218
- }
219
- return false;
223
+ if (!hook || !hook.body) return false;
224
+
225
+ const body = hook.body.toString();
226
+
227
+ // Keep your existing check for BrowserStack internal helpers
228
+ if (body.includes('/* browserstack internal helper hook */')) {
229
+ return true;
220
230
  }
221
231
 
232
+ // Filter duplicate hooks caused by @badeball
233
+ const isBadeballInternal =
234
+ body.includes('beforeEachHandler.call(this, context)') ||
235
+ body.includes('afterEachHandler.call(this, context)') ||
236
+ body.includes('beforeHandler.call(this, context)') ||
237
+ body.includes('afterHandler.call(this, context)');
238
+
239
+ if (isBadeballInternal) {
240
+ return true;
241
+ }
242
+
243
+ return false;
244
+ }
245
+
222
246
  async startHttpServer() {
223
247
  if(this.httpServer !== null) return;
224
248
 
@@ -313,6 +337,8 @@ class MyReporter {
313
337
  this.current_test = test;
314
338
  test.retryOf = null;
315
339
  test.testAnalyticsId = uuidv4();
340
+ if (test.id) this.internalIdMap[test.id] = test.testAnalyticsId;
341
+ debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
316
342
  test.started_at = (new Date()).toISOString();
317
343
  test.test_started_at = test.started_at;
318
344
  if(test._currentRetry > 0 && lastTest && lastTest.title == test.title) {
@@ -332,6 +358,14 @@ class MyReporter {
332
358
 
333
359
  uploadTestSteps = async (shouldClearCurrentSteps = true, cypressSteps = null) => {
334
360
  const currentTestSteps = cypressSteps ? cypressSteps : JSON.parse(JSON.stringify(this.currentTestSteps));
361
+
362
+ if(shouldClearCurrentSteps && !cypressSteps) {
363
+ this.currentTestSteps = [];
364
+ }
365
+
366
+ if (!currentTestSteps || currentTestSteps.length === 0) {
367
+ return;
368
+ }
335
369
  /* TODO - Send as test logs */
336
370
  const allStepsAsLogs = [];
337
371
  currentTestSteps.forEach(step => {
@@ -354,7 +388,6 @@ class MyReporter {
354
388
  event_type: 'LogCreated',
355
389
  logs: allStepsAsLogs
356
390
  });
357
- if(shouldClearCurrentSteps) this.currentTestSteps = [];
358
391
  }
359
392
 
360
393
  sendTestRunEvent = async (test, err = undefined, customFinished=false, eventType = "TestRunFinished") => {
@@ -704,6 +737,9 @@ class MyReporter {
704
737
  return;
705
738
  }
706
739
 
740
+ const cypressTestId = command.testId || command.attributes?.testId;
741
+ const cypressHookId = command.hookId || command.attributes?.hookId;
742
+
707
743
  const currentStepObj = {
708
744
  id: command.attributes.id,
709
745
  text: 'cy.' + command.attributes.name + '(' + this.getFormattedArgs(command.attributes.args) + ')',
@@ -711,8 +747,11 @@ class MyReporter {
711
747
  finished_at: null,
712
748
  duration: null,
713
749
  result: 'pending',
714
- test_run_uuid: command.location === 'test' ? this.current_test?.testAnalyticsId : null,
715
- hook_run_uuid : command.location === 'hook' ? this.current_hook?.hookAnalyticsId : null
750
+ test_run_uuid: command.location === 'test'
751
+ ? (this.internalIdMap[cypressTestId] || this.current_test?.testAnalyticsId) : null,
752
+
753
+ hook_run_uuid : command.location === 'hook'
754
+ ? (this.internalIdMap[cypressHookId] || this.current_hook?.hookAnalyticsId) : null
716
755
  };
717
756
  if(currentStepObj.hook_run_uuid && currentStepObj.test_run_uuid) delete currentStepObj.test_run_uuid;
718
757
  this.currentTestSteps = [
@@ -735,6 +774,10 @@ class MyReporter {
735
774
 
736
775
  if(!stepUpdated) {
737
776
  /* COMMAND_END reported before COMMAND_START */
777
+
778
+ const cypressTestId = command.testId || command.attributes?.testId;
779
+ const cypressHookId = command.hookId || command.attributes?.hookId;
780
+
738
781
  const currentStepObj = {
739
782
  id: command.attributes.id,
740
783
  text: 'cy.' + command.attributes.name + '(' + this.getFormattedArgs(command.attributes.args) + ')',
@@ -742,8 +785,11 @@ class MyReporter {
742
785
  finished_at: new Date().toISOString(),
743
786
  duration: 0,
744
787
  result: command.state,
745
- test_run_uuid: command.location === 'test' ? this.current_test?.testAnalyticsId : null,
746
- hook_run_uuid : command.location === 'hook' ? this.current_hook?.hookAnalyticsId : null
788
+ test_run_uuid: command.location === 'test'
789
+ ? (this.internalIdMap[cypressTestId] || this.current_test?.testAnalyticsId) : null,
790
+
791
+ hook_run_uuid : command.location === 'hook'
792
+ ? (this.internalIdMap[cypressHookId] || this.current_hook?.hookAnalyticsId) : null
747
793
  };
748
794
  if(currentStepObj.hook_run_uuid && currentStepObj.test_run_uuid) delete currentStepObj.test_run_uuid;
749
795
  this.currentTestSteps = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.36.3",
3
+ "version": "1.36.5",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,10 +14,9 @@
14
14
  "dependencies": {
15
15
  "archiver": "5.3.0",
16
16
  "async": "3.2.3",
17
- "axios": "^1.7.7",
17
+ "axios": "^1.15.0",
18
18
  "axios-retry": "^3.5.0",
19
- "browserstack-local": "1.5.4",
20
- "https-proxy-agent": "^5.0.1",
19
+ "browserstack-local": "^1.5.12",
21
20
  "chalk": "4.1.2",
22
21
  "cli-progress": "^3.10.0",
23
22
  "decompress": "4.2.1",
@@ -29,6 +28,7 @@
29
28
  "git-repo-info": "^2.1.1",
30
29
  "gitconfiglocal": "^2.1.0",
31
30
  "glob": "^7.2.0",
31
+ "https-proxy-agent": "^5.0.1",
32
32
  "mkdirp": "1.0.4",
33
33
  "mocha": "^10.2.0",
34
34
  "node-ipc": "9.1.1",
@@ -56,7 +56,7 @@
56
56
  "mocha": "^10.2.0",
57
57
  "nyc": "15.1.0",
58
58
  "proxyquire": "2.1.3",
59
- "rewire": "5.0.0",
59
+ "rewire": "^9.0.1",
60
60
  "sinon": "9.2.4"
61
61
  }
62
62
  }