browserstack-cypress-cli 1.31.2 → 1.31.4

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.
@@ -9,6 +9,7 @@
9
9
  { get_version } = require('./usageReporting'),
10
10
  process = require('process'),
11
11
  { spawn } = require('child_process'),
12
+ cliUtils = require("./utils"),
12
13
  util = require('util');
13
14
 
14
15
  let nodeProcess;
@@ -58,7 +59,7 @@ const setupPackageFolder = (runSettings, directoryPath) => {
58
59
  })
59
60
  };
60
61
 
61
- const packageInstall = (packageDir) => {
62
+ const packageInstall = (packageDir, bsConfig) => {
62
63
  return new Promise(function (resolve, reject) {
63
64
  const nodeProcessCloseCallback = (code) => {
64
65
  if(code == 0) {
@@ -74,6 +75,16 @@ const packageInstall = (packageDir) => {
74
75
  reject(`Packages were not installed successfully. Error Description ${util.format('%j', error)}`);
75
76
  };
76
77
 
78
+ // Moving .npmrc to tmpBstackPackages
79
+ try {
80
+ logger.debug(`Copying .npmrc file to temporary package directory`);
81
+ const npmrcRootPath = path.join(cliUtils.isNotUndefined(bsConfig.run_settings.home_directory) ? path.resolve(bsConfig.run_settings.home_directory) : './', '.npmrc');
82
+ const npmrcTmpPath = path.join(path.resolve(packageDir), '.npmrc');
83
+ fs.copyFileSync(npmrcRootPath, npmrcTmpPath);
84
+ } catch (error) {
85
+ logger.debug(`Failed copying .npmrc to ${packageDir}: ${error}`)
86
+ }
87
+
77
88
  let nodeProcess;
78
89
  logger.debug(`Fetching npm version and its major version`);
79
90
  const npm_version = get_version('npm')
@@ -147,7 +158,7 @@ const packageSetupAndInstaller = (bsConfig, packageDir, instrumentBlocks) => {
147
158
  instrumentBlocks.markBlockEnd("packageInstaller.folderSetup");
148
159
  instrumentBlocks.markBlockStart("packageInstaller.packageInstall");
149
160
  logger.debug("Started installing dependencies specified in browserstack.json");
150
- return packageInstall(packageDir);
161
+ return packageInstall(packageDir, bsConfig);
151
162
  }).then((_result) => {
152
163
  logger.debug("Completed installing dependencies");
153
164
  instrumentBlocks.markBlockEnd("packageInstaller.packageInstall");
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Sending all the remaining queues for synchronous manner
3
+ */
4
+
5
+ const RequestQueueHandler = require('./requestQueueHandler');
6
+
7
+ const shutdown = async () => {
8
+ const requestHandler = new RequestQueueHandler();
9
+ requestHandler.queue = require(process.argv[2].trim());
10
+ await requestHandler.shutdown();
11
+ }
12
+
13
+ shutdown();
@@ -32,3 +32,5 @@ exports.OBSERVABILITY_ENV_VARS = [
32
32
  exports.TEST_OBSERVABILITY_REPORTER = 'browserstack-cypress-cli/bin/testObservability/reporter';
33
33
 
34
34
  exports.TEST_OBSERVABILITY_REPORTER_LOCAL = path.join(__dirname, '..', 'reporter');
35
+
36
+ exports.PENDING_QUEUES_FILE = `pending_queues_${process.pid}.json`;
@@ -2,7 +2,7 @@ const fs = require('fs');
2
2
  const path = require('path');
3
3
  const http = require('http');
4
4
  const https = require('https');
5
- const request = require('request');
5
+ const request = require('requestretry');
6
6
  const { v4: uuidv4 } = require('uuid');
7
7
  const os = require('os');
8
8
  const { promisify } = require('util');
@@ -114,7 +114,8 @@ const nodeRequest = (type, url, data, config) => {
114
114
  url: `${API_URL}/${url}`,
115
115
  body: data,
116
116
  json: config.headers['Content-Type'] === 'application/json',
117
- agent: this.httpsKeepAliveAgent
117
+ agent: this.httpsKeepAliveAgent,
118
+ maxAttempts: 2
118
119
  }};
119
120
 
120
121
  if(url === exports.requestQueueHandler.screenshotEventUrl) {
@@ -1,5 +1,9 @@
1
- const { BATCH_SIZE, BATCH_INTERVAL, consoleHolder } = require('./constants');
2
- const { debug, batchAndPostEvents } = require('./helper');
1
+ const fs = require('fs');
2
+ const cp = require('child_process');
3
+ const path = require('path');
4
+
5
+ const { BATCH_SIZE, BATCH_INTERVAL, PENDING_QUEUES_FILE } = require('./constants');
6
+ const { batchAndPostEvents } = require('./helper');
3
7
 
4
8
  class RequestQueueHandler {
5
9
  constructor() {
@@ -48,6 +52,15 @@ class RequestQueueHandler {
48
52
  }
49
53
  }
50
54
 
55
+ shutdownSync = () => {
56
+ this.removeEventBatchPolling('REMOVING');
57
+
58
+ fs.writeFileSync(path.join(__dirname, PENDING_QUEUES_FILE), JSON.stringify(this.queue));
59
+ this.queue = [];
60
+ cp.spawnSync('node', [path.join(__dirname, 'cleanupQueueSync.js'), path.join(__dirname, PENDING_QUEUES_FILE)], {stdio: 'inherit'});
61
+ fs.unlinkSync(path.join(__dirname, PENDING_QUEUES_FILE));
62
+ }
63
+
51
64
  shutdown = async () => {
52
65
  this.removeEventBatchPolling('REMOVING');
53
66
  while(this.queue.length > 0) {
@@ -1,5 +1,6 @@
1
1
  const ipc = require('node-ipc');
2
2
  const { consoleHolder } = require('../helper/constants');
3
+ const { requestQueueHandler } = require('../helper/helper');
3
4
 
4
5
  exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
5
6
  if (ipc.server) {
@@ -26,6 +27,9 @@ exports.startIPCServer = (subscribeServerEvents, unsubscribeServerEvents) => {
26
27
  process.on('exit', () => {
27
28
  unsubscribeServerEvents(ipc.server);
28
29
  ipc.server.stop();
30
+ // Cleaning up all remaining event in request queue handler. Any synchronous operations
31
+ // on exit handler will block the process
32
+ requestQueueHandler.shutdownSync();
29
33
  });
30
34
 
31
35
  });
@@ -186,7 +186,6 @@ class MyReporter {
186
186
  }
187
187
 
188
188
  await this.uploadTestSteps();
189
- await requestQueueHandler.shutdown();
190
189
  });
191
190
  }
192
191
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "browserstack-cypress-cli",
3
- "version": "1.31.2",
3
+ "version": "1.31.4",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {