browserstack-cypress-cli 1.31.10 → 1.32.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,8 +1,8 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
- const request = require('request');
4
- const http = require('http');
3
+ const axios = require('axios');
5
4
  const https = require('https');
5
+ const HttpsProxyAgent = require('https-proxy-agent');
6
6
 
7
7
  const logger = require("../../helpers/logger").winstonLogger;
8
8
  const utils = require('../../helpers/utils');
@@ -126,7 +126,7 @@ class CrashReporter {
126
126
  if (!this.credentialsForCrashReportUpload.username || !this.credentialsForCrashReportUpload.password) {
127
127
  return debug('[Crash_Report_Upload] Failed to parse user credentials while reporting crash')
128
128
  }
129
-
129
+
130
130
  const data = {
131
131
  hashed_id: process.env.BS_TESTOPS_BUILD_HASHED_ID,
132
132
  observability_version: {
@@ -140,7 +140,7 @@ class CrashReporter {
140
140
  },
141
141
  config: this.userConfigForReporting
142
142
  }
143
-
143
+
144
144
  const options = {
145
145
  auth: {
146
146
  ...this.credentialsForCrashReportUpload
@@ -151,20 +151,29 @@ class CrashReporter {
151
151
  },
152
152
  method: 'POST',
153
153
  url: `${API_URL}/api/v1/analytics`,
154
- body: data,
154
+ data: data,
155
155
  json: true,
156
156
  agent: httpsKeepAliveAgent
157
157
  };
158
+
159
+ if(process.env.HTTP_PROXY){
160
+ options.proxy = false
161
+ options.httpsAgent = new HttpsProxyAgent(process.env.HTTP_PROXY);
162
+ } else if (process.env.HTTPS_PROXY){
163
+ options.proxy = false
164
+ options.httpsAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
165
+ }
158
166
 
159
- request(options, function callback(error, response, body) {
160
- if(error) {
161
- debug(`[Crash_Report_Upload] Failed due to ${error}`);
162
- } else if(response.statusCode != 200) {
163
- debug(`[Crash_Report_Upload] Failed due to ${response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`}`);
164
- } else {
165
- debug(`[Crash_Report_Upload] Success response: ${JSON.stringify({status: response.status, body: response.body})}`)
166
- }
167
- });
167
+ axios(options)
168
+ .then(response => {
169
+
170
+ if(response.status != 200) {
171
+ debug(`[Crash_Report_Upload] Failed due to ${response && response.data ? response.data : `Received response from BrowserStack Server with status : ${response.status}`}`);
172
+ } else {
173
+ debug(`[Crash_Report_Upload] Success response: ${JSON.stringify({status: response.status, body: response.data})}`)
174
+ }
175
+ })
176
+ .catch(error => debug(`[Crash_Report_Upload] Failed due to ${error}`));
168
177
  } catch(e) {
169
178
  debug(`[Crash_Report_Upload] Processing failed due to ${e && e.stack}`);
170
179
  }
@@ -2,13 +2,13 @@
2
2
 
3
3
  /* Used to detect Gherkin steps */
4
4
  Cypress.on('log:added', (log) => {
5
- return () => {
6
- return cy.now('task', 'test_observability_step', {
7
- log
8
- }, {log: false})
9
- }
10
- });
11
-
5
+ return () => {
6
+ return cy.now('task', 'test_observability_step', {
7
+ log
8
+ }, {log: false})
9
+ }
10
+ });
11
+
12
12
  Cypress.on('command:start', (command) => {
13
13
  if(!command || !command.attributes) return;
14
14
  if(command.attributes.name == 'log' || (command.attributes.name == 'task' && (command.attributes.args.includes('test_observability_command') || command.attributes.args.includes('test_observability_log')))) {
@@ -1,8 +1,6 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
- const http = require('http');
4
3
  const https = require('https');
5
- const request = require('requestretry');
6
4
  const { v4: uuidv4 } = require('uuid');
7
5
  const os = require('os');
8
6
  const { promisify } = require('util');
@@ -10,6 +8,8 @@ const gitconfig = require('gitconfiglocal');
10
8
  const { spawn, execSync } = require('child_process');
11
9
  const glob = require('glob');
12
10
  const util = require('util');
11
+ const axios = require('axios');
12
+ const HttpsProxyAgent = require('https-proxy-agent');
13
13
 
14
14
  const { runOptions } = require('../../helpers/runnerArgs')
15
15
 
@@ -117,39 +117,55 @@ exports.printBuildLink = async (shouldStopSession, exitCode = null) => {
117
117
  }
118
118
 
119
119
  const nodeRequest = (type, url, data, config) => {
120
- return new Promise(async (resolve, reject) => {
121
- const options = {...config,...{
122
- method: type,
123
- url: `${API_URL}/${url}`,
124
- body: data,
125
- json: config.headers['Content-Type'] === 'application/json',
126
- agent: this.httpsKeepAliveAgent,
127
- maxAttempts: 2
128
- }};
129
-
130
- if(url === exports.requestQueueHandler.screenshotEventUrl) {
131
- options.agent = httpsScreenshotsKeepAliveAgent;
132
- }
120
+ return new Promise(async (resolve, reject) => {
121
+ const options = {
122
+ ...config,
123
+ method: type,
124
+ url: `${API_URL}/${url}`,
125
+ data: data,
126
+ httpsAgent: this.httpsKeepAliveAgent,
127
+ maxAttempts: 2,
128
+ headers: {
129
+ ...config.headers,
130
+ 'Content-Type': 'application/json;charset=utf-8',
131
+ "X-Forwarded-For": "127.0.0.1"
132
+ },
133
+ clientIp: "127.0.0.1"
134
+ };
133
135
 
134
- request(options, function callback(error, response, body) {
135
- if(error) {
136
- reject(error);
137
- } else if(response.statusCode != 200) {
138
- reject(response && response.body ? response.body : `Received response from BrowserStack Server with status : ${response.statusCode}`);
139
- } else {
140
- try {
141
- if(typeof(body) !== 'object') body = JSON.parse(body);
142
- } catch(e) {
143
- if(!url.includes('/stop')) {
144
- reject('Not a JSON response from BrowserStack Server');
136
+ if(process.env.HTTP_PROXY){
137
+ options.proxy = false
138
+ options.httpsAgent = new HttpsProxyAgent(process.env.HTTP_PROXY);
139
+ } else if (process.env.HTTPS_PROXY){
140
+ options.proxy = false
141
+ options.httpsAgent = new HttpsProxyAgent(process.env.HTTPS_PROXY);
142
+ }
143
+
144
+ if(url === exports.requestQueueHandler.screenshotEventUrl) {
145
+ options.agent = httpsScreenshotsKeepAliveAgent;
146
+ }
147
+ axios(options)
148
+ .then(response => {
149
+
150
+ if(response.status != 200) {
151
+ reject(response && response.data ? response.data : `Received response from BrowserStack Server with status : ${response.status}`);
152
+ } else {
153
+ try {
154
+ const responseBody = typeof response.data === 'object' ? response.data : JSON.parse(response.data);
155
+ resolve({ data: responseBody });
156
+ } catch (error) {
157
+ if (!url.includes('/stop')) {
158
+ reject('Not a JSON response from BrowserStack Server');
159
+ } else {
160
+ resolve({ data: response.data });
161
+ }
162
+ }
145
163
  }
146
- }
147
- resolve({
148
- data: body
164
+ })
165
+ .catch(error => {
166
+ reject(error)
149
167
  });
150
- }
151
168
  });
152
- });
153
169
  }
154
170
 
155
171
  exports.failureData = (errors,tag) => {
@@ -277,7 +293,7 @@ exports.setEventListeners = (bsConfig) => {
277
293
  try {
278
294
  if(!file.includes('commands.js')) {
279
295
  const defaultFileContent = fs.readFileSync(file, {encoding: 'utf-8'});
280
-
296
+
281
297
  let cypressCommandEventListener = getCypressCommandEventListener(file.includes('js'));
282
298
  if(!defaultFileContent.includes(cypressCommandEventListener)) {
283
299
  let newFileContent = defaultFileContent +
@@ -345,10 +361,10 @@ const setCrashReportingConfig = (bsConfig, bsConfigPath) => {
345
361
 
346
362
  exports.launchTestSession = async (user_config, bsConfigPath) => {
347
363
  setCrashReportingConfig(user_config, bsConfigPath);
348
-
364
+
349
365
  const obsUserName = user_config["auth"]["username"];
350
366
  const obsAccessKey = user_config["auth"]["access_key"];
351
-
367
+
352
368
  const BSTestOpsToken = `${obsUserName || ''}:${obsAccessKey || ''}`;
353
369
  if(BSTestOpsToken === '') {
354
370
  exports.debug('EXCEPTION IN BUILD START EVENT : Missing authentication token', true, null);
@@ -480,12 +496,12 @@ exports.batchAndPostEvents = async (eventUrl, kind, data) => {
480
496
  'Authorization': `Bearer ${process.env.BS_TESTOPS_JWT}`,
481
497
  'Content-Type': 'application/json',
482
498
  'X-BSTACK-TESTOPS': 'true'
483
- }
499
+ }
484
500
  };
485
501
 
486
502
  try {
487
503
  const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
488
- exports.debugOnConsole(`[Request Batch Send] for events:uuids ${eventsUuids}`);
504
+ exports.debugOnConsole(`[Request Batch Send] for events:uuids ${eventsUuids}`);
489
505
  const response = await nodeRequest('POST',eventUrl,data,config);
490
506
  exports.debugOnConsole(`[Request Batch Response] for events:uuids ${eventsUuids}`);
491
507
  if(response.data.error) {
@@ -522,7 +538,7 @@ exports.uploadEventData = async (eventData, run=0) => {
522
538
  }[eventData.event_type];
523
539
 
524
540
  if(run === 0 && process.env.BS_TESTOPS_JWT != "null") exports.pending_test_uploads.count += 1;
525
-
541
+
526
542
  if (process.env.BS_TESTOPS_BUILD_COMPLETED === "true") {
527
543
  if(process.env.BS_TESTOPS_JWT == "null") {
528
544
  exports.debug(`EXCEPTION IN ${log_tag} REQUEST TO TEST OBSERVABILITY : missing authentication token`);
@@ -533,7 +549,7 @@ exports.uploadEventData = async (eventData, run=0) => {
533
549
  };
534
550
  } else {
535
551
  let data = eventData, event_api_url = 'api/v1/event';
536
-
552
+
537
553
  exports.requestQueueHandler.start();
538
554
  const { shouldProceed, proceedWithData, proceedWithUrl } = exports.requestQueueHandler.add(eventData);
539
555
  exports.debugOnConsole(`[Request Queue] ${eventData.event_type} with uuid ${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)} is added`)
@@ -547,11 +563,11 @@ exports.uploadEventData = async (eventData, run=0) => {
547
563
  const config = {
548
564
  headers: {
549
565
  'Authorization': `Bearer ${process.env.BS_TESTOPS_JWT}`,
550
- 'Content-Type': 'application/json',
566
+ 'Content-Type': 'application/json;charset=utf-8',
551
567
  'X-BSTACK-TESTOPS': 'true'
552
568
  }
553
569
  };
554
-
570
+
555
571
  try {
556
572
  const eventsUuids = data.map(eventData => `${eventData.event_type}:${eventData.test_run ? eventData.test_run.uuid : (eventData.hook_run ? eventData.hook_run.uuid : null)}`).join(', ');
557
573
  exports.debugOnConsole(`[Request Send] for events:uuids ${eventsUuids}`);
@@ -613,7 +629,7 @@ exports.setTestObservabilityFlags = (bsConfig) => {
613
629
  isTestObservabilitySession = false;
614
630
  exports.debug(`EXCEPTION while parsing testObservability capability with error ${e}`, true, e);
615
631
  }
616
-
632
+
617
633
  /* browserstackAutomation */
618
634
  let isBrowserstackInfra = true;
619
635
  try {
@@ -624,7 +640,7 @@ exports.setTestObservabilityFlags = (bsConfig) => {
624
640
  isBrowserstackInfra = true;
625
641
  exports.debug(`EXCEPTION while parsing browserstackAutomation capability with error ${e}`, true, e);
626
642
  }
627
-
643
+
628
644
  if(isTestObservabilitySession) logger.warn("testObservability is set to true. Other test reporters you are using will be automatically disabled. Learn more at browserstack.com/docs/test-observability/overview/what-is-test-observability");
629
645
 
630
646
  process.env.BROWSERSTACK_TEST_OBSERVABILITY = isTestObservabilitySession;
@@ -664,7 +680,7 @@ exports.stopBuildUpstream = async () => {
664
680
  'X-BSTACK-TESTOPS': 'true'
665
681
  }
666
682
  };
667
-
683
+
668
684
  try {
669
685
  const response = await nodeRequest('PUT',`api/v1/builds/${process.env.BS_TESTOPS_BUILD_HASHED_ID}/stop`,data,config);
670
686
  if(response.data && response.data.error) {
@@ -39,7 +39,7 @@ class RequestQueueHandler {
39
39
  this.queue.splice(0,BATCH_SIZE);
40
40
  this.resetEventBatchPolling();
41
41
  }
42
-
42
+
43
43
  return {
44
44
  shouldProceed: shouldProceed,
45
45
  proceedWithData: data,
@@ -54,7 +54,7 @@ class RequestQueueHandler {
54
54
 
55
55
  shutdownSync = () => {
56
56
  this.removeEventBatchPolling('REMOVING');
57
-
57
+
58
58
  fs.writeFileSync(path.join(__dirname, PENDING_QUEUES_FILE), JSON.stringify(this.queue));
59
59
  this.queue = [];
60
60
  cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUES_FILE)], {stdio: 'inherit'});
@@ -13,17 +13,17 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
13
13
  ipc.config.silent = true;
14
14
 
15
15
  ipc.serve(() => {
16
-
16
+
17
17
  ipc.server.on('socket.disconnected', (socket, destroyedSocketID) => {
18
18
  ipc.log(`client ${destroyedSocketID} has disconnected!`);
19
19
  });
20
-
20
+
21
21
  ipc.server.on('destroy', () => {
22
22
  ipc.log('server destroyed');
23
23
  });
24
-
24
+
25
25
  subscribeServerEvents(ipc.server);
26
-
26
+
27
27
  process.on('exit', () => {
28
28
  unsubscribeServerEvents(ipc.server);
29
29
  ipc.server.stop();
@@ -31,8 +31,8 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
31
31
  // on exit handler will block the process
32
32
  requestQueueHandler.shutdownSync();
33
33
  });
34
-
34
+
35
35
  });
36
-
36
+
37
37
  ipc.server.start();
38
38
  };
@@ -169,7 +169,6 @@ class MyReporter {
169
169
  })
170
170
 
171
171
  .on(EVENT_TEST_BEGIN, async (test) => {
172
- debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN`);
173
172
  debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
174
173
  if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
175
174
  if(this.testObservability == true) {
@@ -178,7 +177,6 @@ class MyReporter {
178
177
  })
179
178
 
180
179
  .on(EVENT_TEST_END, async (test) => {
181
- debugOnConsole(`[MOCHA EVENT] EVENT_TEST_END`);
182
180
  debugOnConsole(`[MOCHA EVENT] EVENT_TEST_BEGIN for uuid: ${test.testAnalyticsId}`);
183
181
  if (this.runStatusMarkedHash[test.testAnalyticsId]) return;
184
182
  if(this.testObservability == true) {
@@ -188,7 +186,7 @@ class MyReporter {
188
186
  }
189
187
  }
190
188
  })
191
-
189
+
192
190
  .once(EVENT_RUN_END, async () => {
193
191
  try {
194
192
  debugOnConsole(`[MOCHA EVENT] EVENT_RUN_END`);
@@ -307,9 +305,9 @@ class MyReporter {
307
305
  let gitConfigPath = process.env.OBSERVABILITY_GIT_CONFIG_PATH ? process.env.OBSERVABILITY_GIT_CONFIG_PATH.toString() : (rootParentFile ? findGitConfig(rootParentFile) : null);
308
306
  if(!isBrowserstackInfra()) gitConfigPath = process.env.OBSERVABILITY_GIT_CONFIG_PATH_LOCAL ? process.env.OBSERVABILITY_GIT_CONFIG_PATH_LOCAL.toString() : null;
309
307
  const prefixedTestPath = rootParentFile ? this._paths.prefixTestPath(rootParentFile) : 'File path could not be found';
310
-
308
+
311
309
  const fileSeparator = getFileSeparatorData();
312
-
310
+
313
311
  let testData = {
314
312
  'framework': 'Cypress',
315
313
  'uuid': (eventType.includes("Test") ? test.testAnalyticsId : test.hookAnalyticsId) || uuidv4(),
@@ -417,14 +415,14 @@ class MyReporter {
417
415
  }
418
416
 
419
417
  if(eventType == "HookRunFinished") delete testData.started_at;
420
-
418
+
421
419
  if(eventType.match(/HookRun/)) {
422
420
  testData['hook_type'] = HOOK_TYPES_MAP[testData['hook_type']];
423
421
  uploadData['hook_run'] = testData;
424
422
  } else {
425
423
  uploadData['test_run'] = testData;
426
424
  }
427
-
425
+
428
426
  if(eventType == 'HookRunFinished' && testData['hook_type'] == 'BEFORE_ALL') {
429
427
  uploadData.cypressSteps = JSON.parse(JSON.stringify(this.currentTestSteps));
430
428
  this.beforeHooks.push(uploadData);
@@ -610,7 +608,7 @@ class MyReporter {
610
608
  if(isCommandPresent) {
611
609
  return;
612
610
  }
613
-
611
+
614
612
  const currentStepObj = {
615
613
  id: command.attributes.id,
616
614
  text: 'cy.' + command.attributes.name + '(' + this.getFormattedArgs(command.attributes.args) + ')',
@@ -660,7 +658,7 @@ class MyReporter {
660
658
  }
661
659
  } else if(type == 'COMMAND_RETRY') {
662
660
  if(!command.id) return;
663
-
661
+
664
662
  let isRetryStepFound = false;
665
663
  /* Parse steps array in reverse and update the last step with common chainerId */
666
664
  for(let idx=this.currentTestSteps.length-1; idx>=0; idx--) {
@@ -754,7 +752,7 @@ class MyReporter {
754
752
  });
755
753
  }
756
754
  }
757
-
755
+
758
756
  return null
759
757
  }
760
758
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.31.10",
3
+ "version": "1.32.0",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,9 +14,12 @@
14
14
  "dependencies": {
15
15
  "archiver": "5.3.0",
16
16
  "async": "3.2.3",
17
+ "axios": "^1.7.7",
18
+ "axios-retry": "^3.5.0",
17
19
  "browserstack-local": "1.5.4",
18
20
  "chalk": "4.1.2",
19
- "cli-progress": "3.10.0",
21
+ "cli-progress": "^3.10.0",
22
+ "form-data": "^4.0.0",
20
23
  "fs-extra": "8.1.0",
21
24
  "getmac": "5.20.0",
22
25
  "git-last-commit": "^1.0.1",
@@ -26,8 +29,6 @@
26
29
  "mocha": "^10.2.0",
27
30
  "mkdirp": "1.0.4",
28
31
  "node-ipc": "9.1.1",
29
- "request": "2.88.2",
30
- "requestretry": "7.1.0",
31
32
  "table": "5.4.6",
32
33
  "update-notifier": "7.0.0",
33
34
  "uuid": "8.3.2",