browserstack-cypress-cli 1.31.3 → 1.31.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.
@@ -10,7 +10,7 @@ const logger = require('./logger').winstonLogger,
10
10
 
11
11
  const request = require('request');
12
12
  const decompress = require('decompress');
13
-
13
+ const unzipper = require("unzipper");
14
14
 
15
15
  let BUILD_ARTIFACTS_TOTAL_COUNT = 0;
16
16
  let BUILD_ARTIFACTS_FAIL_COUNT = 0;
@@ -121,13 +121,15 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
121
121
  reject(err);
122
122
  });
123
123
  writer.on('close', async () => {
124
- if (!error) {
125
- await unzipFile(filePath, fileName);
126
- fs.unlinkSync(tmpFilePath);
127
- resolve(true);
124
+ try {
125
+ if (!error) {
126
+ await unzipFile(filePath, fileName);
127
+ fs.unlinkSync(tmpFilePath);
128
+ }
129
+ } catch (error) {
130
+ reject(error);
128
131
  }
129
- //no need to call the reject here, as it will have been called in the
130
- //'error' stream;
132
+ resolve(true);
131
133
  });
132
134
  }
133
135
  });
@@ -136,13 +138,25 @@ const downloadAndUnzip = async (filePath, fileName, url) => {
136
138
 
137
139
  const unzipFile = async (filePath, fileName) => {
138
140
  return new Promise( async (resolve, reject) => {
139
- await decompress(path.join(filePath, fileName), filePath)
140
- .then((files) => {
141
+ try {
142
+ await decompress(path.join(filePath, fileName), filePath);
141
143
  resolve();
142
- })
143
- .catch((error) => {
144
- reject(error);
145
- });
144
+ } catch (error) {
145
+ logger.debug(`Error unzipping with decompress, trying with unzipper. Stacktrace: ${error}.`);
146
+ try {
147
+ fs.createReadStream(path.join(filePath, fileName))
148
+ .pipe(unzipper.Extract({ path: filePath }))
149
+ .on("close", () => {
150
+ resolve();
151
+ })
152
+ .on("error", (err) => {
153
+ reject(err);
154
+ });
155
+ } catch (unzipperError) {
156
+ logger.debug(`Unzipper package error: ${unzipperError}`);
157
+ reject(Constants.userMessages.BUILD_ARTIFACTS_UNZIP_FAILURE);
158
+ }
159
+ }
146
160
  });
147
161
  }
148
162
 
@@ -123,7 +123,8 @@ const userMessages = {
123
123
  CYPRESS_PORT_WARNING:
124
124
  "The requested port number <x> is ignored. The default BrowserStack port will be used for this execution",
125
125
  CYPRESS_INTERACTIVE_SESSION_CONFLICT_VALUES:
126
- "Conflicting values (True & False) were found for the interactive_debugging capability. Please resolve this issue to proceed further."
126
+ "Conflicting values (True & False) were found for the interactive_debugging capability. Please resolve this issue to proceed further.",
127
+ BUILD_ARTIFACTS_UNZIP_FAILURE: "Failed to unzip build artifacts.",
127
128
  };
128
129
 
129
130
  const validationMessages = {
@@ -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.3",
3
+ "version": "1.31.5",
4
4
  "description": "BrowserStack Cypress CLI for Cypress integration with BrowserStack's remote devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -34,7 +34,8 @@
34
34
  "windows-release": "^5.1.0",
35
35
  "winston": "2.4.4",
36
36
  "yargs": "14.2.3",
37
- "decompress": "4.2.1"
37
+ "decompress": "4.2.1",
38
+ "unzipper": "^0.12.3"
38
39
  },
39
40
  "repository": {
40
41
  "type": "git",