@testim/testim-cli 3.245.0 → 3.246.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.
package/utils.js CHANGED
@@ -10,6 +10,10 @@ const { sessionType, testStatus: testStatusConst } = require('./commons/constant
10
10
  const path = require('path');
11
11
  const httpRequest = require('./commons/httpRequest');
12
12
  const decompress = require('decompress');
13
+ const os = require('os');
14
+
15
+ const HOMEDIR = os.homedir();
16
+ const TESTIM_BROWSER_DIR = path.join(HOMEDIR, '.testim-browser-profile');
13
17
 
14
18
  const OSS = [
15
19
  { osName: 'Linux', bs: { os: 'LINUX' }, sl: { platform: 'Linux' } },
@@ -183,7 +187,7 @@ function extractElementId(element) {
183
187
  }
184
188
 
185
189
  function isURL(path) {
186
- const legacyPattern = new RegExp('^(https?:\\/\\/)', 'i');
190
+ const legacyPattern = /^(https?:\/\/)/i;
187
191
 
188
192
  // https://gist.github.com/dperini/729294 (validator.js based on).
189
193
  const pattern = new RegExp(
@@ -304,7 +308,7 @@ function getPlanType(plan) {
304
308
  * @param time {number} in ms
305
309
  * @returns {Promise}
306
310
  */
307
- function delay(time) {
311
+ function delay(time) {
308
312
  return new Promise(((resolve) => {
309
313
  setTimeout(resolve, time);
310
314
  }));
@@ -356,7 +360,41 @@ function groupTestsByRetries(testResults = []) { // NOTE: This duplicates a func
356
360
  .value();
357
361
  }
358
362
 
363
+ async function getCdpAddressForHost(browserInstanceHost, timeout) {
364
+ try {
365
+ /**
366
+ Example response:
367
+ {
368
+ "Browser": "Chrome/81.0.4044.138",
369
+ "Protocol-Version": "1.3",
370
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
371
+ "V8-Version": "8.1.307.32",
372
+ "WebKit-Version": "537.36 (@8c6c7ba89cc9453625af54f11fd83179e23450fa)",
373
+ "webSocketDebuggerUrl": "ws://localhost:58938/devtools/browser/d4290379-ec08-4d03-a41a-ab9d9d4c36ac"
374
+ }
375
+ */
376
+ const debuggerAddress = await httpRequest.get(`http://${browserInstanceHost}/json/version`, undefined, undefined, timeout);
377
+ return debuggerAddress.webSocketDebuggerUrl;
378
+ } catch (e) {
379
+ throw new Error('unable to connect to devtools server');
380
+ }
381
+ }
382
+
383
+ function getArgsOnRemoteRunFailure() {
384
+ const { argv: args } = process;
385
+ if (!args.includes('--remoteRunId')) {
386
+ return undefined;
387
+ }
388
+ return {
389
+ remoteRunId: args[args.indexOf('--remoteRunId') + 1],
390
+ projectId: args[args.indexOf('--project') + 1],
391
+ token: args[args.indexOf('--token') + 1],
392
+ };
393
+ }
394
+
395
+
359
396
  module.exports = {
397
+ TESTIM_BROWSER_DIR,
360
398
  removePropertyFromObject,
361
399
  getTestUrl,
362
400
  getDuration,
@@ -390,4 +428,6 @@ module.exports = {
390
428
  groupTestsByRetries,
391
429
  getPlanType,
392
430
  delay,
431
+ getCdpAddressForHost,
432
+ getArgsOnRemoteRunFailure,
393
433
  };
package/utils.test.js CHANGED
@@ -39,4 +39,30 @@ describe('utils', () => {
39
39
  .to.equal('http://localhost:8080/#/project/project/branch/encoded%2520branch/test/test?result-id=result');
40
40
  });
41
41
  });
42
+
43
+ describe('getArgsOnRemoteRunFailure', () => {
44
+ let originalArgv;
45
+
46
+ beforeEach(() => {
47
+ originalArgv = process.argv;
48
+ });
49
+
50
+ afterEach(() => {
51
+ process.argv = originalArgv;
52
+ });
53
+
54
+ it('should return undefined if no remote run is current', () => {
55
+ process.argv = ['node', 'file.js', '--token', 'token', '--project', 'project-id'];
56
+ expect(utils.getArgsOnRemoteRunFailure()).to.be.undefined;
57
+ });
58
+
59
+ it('should return details if remote run is current', () => {
60
+ process.argv = ['node', 'file.js', '--token', 'token', '--project', 'project-id', '--remoteRunId', 'remote-run-id'];
61
+ expect(utils.getArgsOnRemoteRunFailure()).to.eql({
62
+ remoteRunId: 'remote-run-id',
63
+ projectId: 'project-id',
64
+ token: 'token',
65
+ });
66
+ });
67
+ });
42
68
  });