cypress 4.4.1 → 4.5.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/lib/util.js CHANGED
@@ -1,64 +1,108 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _templateObject = _taggedTemplateLiteral(['\n\n ', ' Warning: Cypress failed to start.\n\n This is likely due to a misconfigured DISPLAY environment variable.\n\n DISPLAY was set to: "', '"\n\n Cypress will attempt to fix the problem and rerun.\n '], ['\n\n ', ' Warning: Cypress failed to start.\n\n This is likely due to a misconfigured DISPLAY environment variable.\n\n DISPLAY was set to: "', '"\n\n Cypress will attempt to fix the problem and rerun.\n ']),
4
- _templateObject2 = _taggedTemplateLiteral(['\n Platform: ', ' (', ')\n Cypress Version: ', '\n '], ['\n Platform: ', ' (', ')\n Cypress Version: ', '\n ']);
3
+ function _templateObject2() {
4
+ var data = _taggedTemplateLiteral(["\n Platform: ", " (", ")\n Cypress Version: ", "\n "]);
5
5
 
6
- function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
6
+ _templateObject2 = function _templateObject2() {
7
+ return data;
8
+ };
9
+
10
+ return data;
11
+ }
12
+
13
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
14
+
15
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+
17
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
18
+
19
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
20
+
21
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
22
+
23
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
7
24
 
8
- function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
25
+ function _templateObject() {
26
+ var data = _taggedTemplateLiteral(["\n\n ", " Warning: Cypress failed to start.\n\n This is likely due to a misconfigured DISPLAY environment variable.\n\n DISPLAY was set to: \"", "\"\n\n Cypress will attempt to fix the problem and rerun.\n "]);
27
+
28
+ _templateObject = function _templateObject() {
29
+ return data;
30
+ };
31
+
32
+ return data;
33
+ }
34
+
35
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
9
36
 
10
37
  var _ = require('lodash');
38
+
11
39
  var R = require('ramda');
40
+
12
41
  var os = require('os');
42
+
13
43
  var ospath = require('ospath');
44
+
14
45
  var crypto = require('crypto');
46
+
15
47
  var la = require('lazy-ass');
48
+
16
49
  var is = require('check-more-types');
50
+
17
51
  var tty = require('tty');
52
+
18
53
  var path = require('path');
54
+
19
55
  var _isCi = require('is-ci');
56
+
20
57
  var execa = require('execa');
58
+
21
59
  var getos = require('getos');
60
+
22
61
  var chalk = require('chalk');
62
+
23
63
  var Promise = require('bluebird');
64
+
24
65
  var cachedir = require('cachedir');
66
+
25
67
  var logSymbols = require('log-symbols');
68
+
26
69
  var executable = require('executable');
27
70
 
28
71
  var _require = require('common-tags'),
29
72
  stripIndent = _require.stripIndent;
30
73
 
31
74
  var _supportsColor = require('supports-color');
75
+
32
76
  var _isInstalledGlobally = require('is-installed-globally');
77
+
33
78
  var pkg = require(path.join(__dirname, '..', 'package.json'));
79
+
34
80
  var logger = require('./logger');
81
+
35
82
  var debug = require('debug')('cypress:cli');
83
+
36
84
  var fs = require('./fs');
37
85
 
38
86
  var issuesUrl = 'https://github.com/cypress-io/cypress/issues';
39
-
40
87
  var getosAsync = Promise.promisify(getos);
41
-
42
88
  /**
43
89
  * Returns SHA512 of a file
44
90
  *
45
91
  * Implementation lifted from https://github.com/sindresorhus/hasha
46
92
  * but without bringing that dependency (since hasha is Node v8+)
47
93
  */
94
+
48
95
  var getFileChecksum = function getFileChecksum(filename) {
49
96
  la(is.unemptyString(filename), 'expected filename', filename);
50
97
 
51
98
  var hashStream = function hashStream() {
52
99
  var s = crypto.createHash('sha512');
53
-
54
100
  s.setEncoding('hex');
55
-
56
101
  return s;
57
102
  };
58
103
 
59
104
  return new Promise(function (resolve, reject) {
60
105
  var stream = fs.createReadStream(filename);
61
-
62
106
  stream.on('error', reject).pipe(hashStream()).on('error', reject).on('finish', function () {
63
107
  resolve(this.read());
64
108
  });
@@ -67,7 +111,6 @@ var getFileChecksum = function getFileChecksum(filename) {
67
111
 
68
112
  var getFileSize = function getFileSize(filename) {
69
113
  la(is.unemptyString(filename), 'expected filename', filename);
70
-
71
114
  return fs.statAsync(filename).get('size');
72
115
  };
73
116
 
@@ -79,18 +122,17 @@ var stringify = function stringify(val) {
79
122
 
80
123
  function normalizeModuleOptions() {
81
124
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
82
-
83
125
  return _.mapValues(options, stringify);
84
126
  }
85
-
86
127
  /**
87
128
  * Returns true if the platform is Linux. We do a lot of different
88
129
  * stuff on Linux (like Xvfb) and it helps to has readable code
89
130
  */
131
+
132
+
90
133
  var isLinux = function isLinux() {
91
134
  return os.platform() === 'linux';
92
135
  };
93
-
94
136
  /**
95
137
  * If the DISPLAY variable is set incorrectly, when trying to spawn
96
138
  * Cypress executable we get an error like this:
@@ -98,6 +140,8 @@ var isLinux = function isLinux() {
98
140
  [1005:0509/184205.663837:WARNING:browser_main_loop.cc(258)] Gtk: cannot open display: 99
99
141
  ```
100
142
  */
143
+
144
+
101
145
  var isBrokenGtkDisplay = function isBrokenGtkDisplay(str) {
102
146
  return isBrokenGtkDisplayRe.test(str);
103
147
  };
@@ -107,21 +151,17 @@ var isPossibleLinuxWithIncorrectDisplay = function isPossibleLinuxWithIncorrectD
107
151
  };
108
152
 
109
153
  var logBrokenGtkDisplayWarning = function logBrokenGtkDisplayWarning() {
110
- debug('Cypress exited due to a broken gtk display because of a potential invalid DISPLAY env... retrying after starting Xvfb');
111
-
112
- // if we get this error, we are on Linux and DISPLAY is set
113
- logger.warn(stripIndent(_templateObject, logSymbols.warning, process.env.DISPLAY));
154
+ debug('Cypress exited due to a broken gtk display because of a potential invalid DISPLAY env... retrying after starting Xvfb'); // if we get this error, we are on Linux and DISPLAY is set
114
155
 
156
+ logger.warn(stripIndent(_templateObject(), logSymbols.warning, process.env.DISPLAY));
115
157
  logger.warn();
116
158
  };
117
159
 
118
160
  function stdoutLineMatches(expectedLine, stdout) {
119
161
  var lines = stdout.split('\n').map(R.trim);
120
162
  var lineMatches = R.equals(expectedLine);
121
-
122
163
  return lines.some(lineMatches);
123
164
  }
124
-
125
165
  /**
126
166
  * Confirms if given value is a valid CYPRESS_INTERNAL_ENV value. Undefined values
127
167
  * are valid, because the system can set the default one.
@@ -129,18 +169,18 @@ function stdoutLineMatches(expectedLine, stdout) {
129
169
  * @param {string} value
130
170
  * @example util.isValidCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
131
171
  */
172
+
173
+
132
174
  function isValidCypressInternalEnvValue(value) {
133
175
  if (_.isUndefined(value)) {
134
176
  // will get default value
135
177
  return true;
136
- }
178
+ } // names of config environments, see "packages/server/config/app.yml"
137
179
 
138
- // names of config environments, see "packages/server/config/app.yml"
139
- var names = ['development', 'test', 'staging', 'production'];
140
180
 
181
+ var names = ['development', 'test', 'staging', 'production'];
141
182
  return _.includes(names, value);
142
183
  }
143
-
144
184
  /**
145
185
  * Confirms if given value is a non-production CYPRESS_INTERNAL_ENV value.
146
186
  * Undefined values are valid, because the system can set the default one.
@@ -148,14 +188,17 @@ function isValidCypressInternalEnvValue(value) {
148
188
  * @param {string} value
149
189
  * @example util.isNonProductionCypressInternalEnvValue(process.env.CYPRESS_INTERNAL_ENV)
150
190
  */
191
+
192
+
151
193
  function isNonProductionCypressInternalEnvValue(value) {
152
194
  return !_.isUndefined(value) && value !== 'production';
153
195
  }
154
-
155
196
  /**
156
197
  * Prints NODE_OPTIONS using debug() module, but only
157
198
  * if DEBUG=cypress... is set
158
199
  */
200
+
201
+
159
202
  function printNodeOptions() {
160
203
  var log = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : debug;
161
204
 
@@ -169,7 +212,6 @@ function printNodeOptions() {
169
212
  log('NODE_OPTIONS is not set');
170
213
  }
171
214
  }
172
-
173
215
  /**
174
216
  * Removes double quote characters
175
217
  * from the start and end of the given string IF they are both present
@@ -184,8 +226,11 @@ function printNodeOptions() {
184
226
  // returns string 'foo'
185
227
  ```
186
228
  */
229
+
230
+
187
231
  var dequote = function dequote(str) {
188
232
  la(is.string(str), 'expected a string to remove double quotes', str);
233
+
189
234
  if (str.length > 1 && str[0] === '"' && str[str.length - 1] === '"') {
190
235
  return str.substr(1, str.length - 2);
191
236
  }
@@ -198,44 +243,38 @@ var parseOpts = function parseOpts(opts) {
198
243
 
199
244
  if (opts.exit) {
200
245
  opts = _.omit(opts, 'exit');
201
- }
202
-
203
- // some options might be quoted - which leads to unexpected results
246
+ } // some options might be quoted - which leads to unexpected results
204
247
  // remove double quotes from certain options
248
+
249
+
205
250
  var removeQuotes = {
206
251
  group: dequote,
207
252
  ciBuildId: dequote
208
253
  };
209
254
  var cleanOpts = R.evolve(removeQuotes, opts);
210
-
211
255
  debug('parsed cli options %o', cleanOpts);
212
-
213
256
  return cleanOpts;
214
257
  };
215
-
216
258
  /**
217
259
  * Copy of packages/server/lib/browsers/utils.ts
218
260
  * because we need same functionality in CLI to show the path :(
219
261
  */
220
- var getApplicationDataFolder = function getApplicationDataFolder() {
221
- for (var _len = arguments.length, paths = Array(_len), _key = 0; _key < _len; _key++) {
222
- paths[_key] = arguments[_key];
223
- }
224
262
 
225
- var _process = process,
226
- env = _process.env;
227
263
 
228
- // allow overriding the app_data folder
264
+ var getApplicationDataFolder = function getApplicationDataFolder() {
265
+ var _process = process,
266
+ env = _process.env; // allow overriding the app_data folder
229
267
 
230
268
  var folder = env.CYPRESS_KONFIG_ENV || env.CYPRESS_INTERNAL_ENV || 'development';
231
-
232
269
  var PRODUCT_NAME = pkg.productName || pkg.name;
233
270
  var OS_DATA_PATH = ospath.data();
234
-
235
271
  var ELECTRON_APP_DATA_PATH = path.join(OS_DATA_PATH, PRODUCT_NAME);
236
272
 
237
- var p = path.join.apply(path, [ELECTRON_APP_DATA_PATH, 'cy', folder].concat(paths));
273
+ for (var _len = arguments.length, paths = new Array(_len), _key = 0; _key < _len; _key++) {
274
+ paths[_key] = arguments[_key];
275
+ }
238
276
 
277
+ var p = path.join.apply(path, [ELECTRON_APP_DATA_PATH, 'cy', folder].concat(paths));
239
278
  return p;
240
279
  };
241
280
 
@@ -245,13 +284,11 @@ var util = {
245
284
  isValidCypressInternalEnvValue: isValidCypressInternalEnvValue,
246
285
  isNonProductionCypressInternalEnvValue: isNonProductionCypressInternalEnvValue,
247
286
  printNodeOptions: printNodeOptions,
248
-
249
287
  isCi: function isCi() {
250
288
  return _isCi;
251
289
  },
252
290
  getEnvOverrides: function getEnvOverrides() {
253
291
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
254
-
255
292
  return _.chain({}).extend(util.getEnvColors()).extend(util.getForceTty()).omitBy(_.isUndefined) // remove undefined values
256
293
  .mapValues(function (value) {
257
294
  // stringify to 1 or 0
@@ -266,21 +303,22 @@ var util = {
266
303
  if (options.dev && nodeVersion < 12) {
267
304
  // `node` is used instead of Electron when --dev is passed, so this won't work if Node is too old
268
305
  debug('NODE_OPTIONS=--max-http-header-size could not be set because we\'re in dev mode and Node is < 12.0.0');
269
-
270
306
  return;
271
- }
307
+ } // https://github.com/cypress-io/cypress/issues/5431
272
308
 
273
- // https://github.com/cypress-io/cypress/issues/5431
274
- var NODE_OPTIONS = '--max-http-header-size=' + 1024 ** 2 + ' --http-parser=legacy';
309
+
310
+ var NODE_OPTIONS = "--max-http-header-size=".concat(Math.pow(1024, 2), " --http-parser=legacy");
275
311
 
276
312
  if (_.isString(process.env.NODE_OPTIONS)) {
277
313
  return {
278
- NODE_OPTIONS: NODE_OPTIONS + ' ' + process.env.NODE_OPTIONS,
314
+ NODE_OPTIONS: "".concat(NODE_OPTIONS, " ").concat(process.env.NODE_OPTIONS),
279
315
  ORIGINAL_NODE_OPTIONS: process.env.NODE_OPTIONS || ''
280
316
  };
281
317
  }
282
318
 
283
- return { NODE_OPTIONS: NODE_OPTIONS };
319
+ return {
320
+ NODE_OPTIONS: NODE_OPTIONS
321
+ };
284
322
  },
285
323
  getForceTty: function getForceTty() {
286
324
  return {
@@ -291,7 +329,6 @@ var util = {
291
329
  },
292
330
  getEnvColors: function getEnvColors() {
293
331
  var sc = util.supportsColor();
294
-
295
332
  return {
296
333
  FORCE_COLOR: sc,
297
334
  DEBUG_COLORS: sc,
@@ -306,15 +343,15 @@ var util = {
306
343
  // color then turn this off
307
344
  if (process.env.NO_COLOR) {
308
345
  return false;
309
- }
310
-
311
- // https://github.com/cypress-io/cypress/issues/1747
346
+ } // https://github.com/cypress-io/cypress/issues/1747
312
347
  // always return true in CI providers
348
+
349
+
313
350
  if (process.env.CI) {
314
351
  return true;
315
- }
352
+ } // ensure that both stdout and stderr support color
353
+
316
354
 
317
- // ensure that both stdout and stderr support color
318
355
  return Boolean(_supportsColor.stdout) && Boolean(_supportsColor.stderr);
319
356
  },
320
357
  cwd: function cwd() {
@@ -328,38 +365,31 @@ var util = {
328
365
  },
329
366
  logErrorExit1: function logErrorExit1(err) {
330
367
  logger.error(err.message);
331
-
332
368
  process.exit(1);
333
369
  },
334
-
335
-
336
370
  dequote: dequote,
337
-
338
371
  titleize: function titleize() {
339
- for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
372
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
340
373
  args[_key2] = arguments[_key2];
341
374
  }
342
375
 
343
376
  // prepend first arg with space
344
377
  // and pad so that all messages line up
345
- args[0] = _.padEnd(' ' + args[0], 24);
378
+ args[0] = _.padEnd(" ".concat(args[0]), 24); // get rid of any falsy values
346
379
 
347
- // get rid of any falsy values
348
380
  args = _.compact(args);
349
-
350
381
  return chalk.blue.apply(chalk, _toConsumableArray(args));
351
382
  },
352
383
  calculateEta: function calculateEta(percent, elapsed) {
353
384
  // returns the number of seconds remaining
354
-
355
385
  // if we're at 100% already just return 0
356
386
  if (percent === 100) {
357
387
  return 0;
358
- }
359
-
360
- // take the percentage and divide by one
388
+ } // take the percentage and divide by one
361
389
  // and multiple that against elapsed
362
390
  // subtracting what's already elapsed
391
+
392
+
363
393
  return elapsed * (1 / (percent / 100)) - elapsed;
364
394
  },
365
395
  convertPercentToPercentage: function convertPercentToPercentage(num) {
@@ -382,22 +412,18 @@ var util = {
382
412
  return _isInstalledGlobally;
383
413
  },
384
414
  isSemver: function isSemver(str) {
385
- return (/^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(str)
386
- );
415
+ return /^(\d+\.)?(\d+\.)?(\*|\d+)$/.test(str);
387
416
  },
388
417
  isExecutableAsync: function isExecutableAsync(filePath) {
389
418
  return Promise.resolve(executable(filePath));
390
419
  },
391
-
392
-
393
420
  isLinux: isLinux,
394
-
395
421
  getOsVersionAsync: function getOsVersionAsync() {
396
- return Promise.try(function () {
422
+ return Promise["try"](function () {
397
423
  if (isLinux()) {
398
424
  return getosAsync().then(function (osInfo) {
399
425
  return [osInfo.dist, osInfo.release].join(' - ');
400
- }).catch(function () {
426
+ })["catch"](function () {
401
427
  return os.release();
402
428
  });
403
429
  }
@@ -407,11 +433,9 @@ var util = {
407
433
  },
408
434
  getPlatformInfo: function getPlatformInfo() {
409
435
  return util.getOsVersionAsync().then(function (version) {
410
- return stripIndent(_templateObject2, os.platform(), version, util.pkgVersion());
436
+ return stripIndent(_templateObject2(), os.platform(), version, util.pkgVersion());
411
437
  });
412
438
  },
413
-
414
-
415
439
  // attention:
416
440
  // when passing relative path to NPM post install hook, the current working
417
441
  // directory is set to the `node_modules/cypress` folder
@@ -425,28 +449,21 @@ var util = {
425
449
  },
426
450
  getEnv: function getEnv(varName, trim) {
427
451
  la(is.unemptyString(varName), 'expected environment variable name, not', varName);
428
-
429
452
  var envVar = process.env[varName];
430
- var configVar = process.env['npm_config_' + varName];
431
- var packageConfigVar = process.env['npm_package_config_' + varName];
432
-
433
- var result = void 0;
453
+ var configVar = process.env["npm_config_".concat(varName)];
454
+ var packageConfigVar = process.env["npm_package_config_".concat(varName)];
455
+ var result;
434
456
 
435
457
  if (envVar) {
436
- debug('Using ' + varName + ' from environment variable');
437
-
458
+ debug("Using ".concat(varName, " from environment variable"));
438
459
  result = envVar;
439
460
  } else if (configVar) {
440
- debug('Using ' + varName + ' from npm config');
441
-
461
+ debug("Using ".concat(varName, " from npm config"));
442
462
  result = configVar;
443
463
  } else if (packageConfigVar) {
444
- debug('Using ' + varName + ' from package.json config');
445
-
464
+ debug("Using ".concat(varName, " from package.json config"));
446
465
  result = packageConfigVar;
447
- }
448
-
449
- // environment variables are often set double quotes to escape characters
466
+ } // environment variables are often set double quotes to escape characters
450
467
  // and on Windows it can lead to weird things: for example
451
468
  // set FOO="C:\foo.txt" && node -e "console.log('>>>%s<<<', process.env.FOO)"
452
469
  // will print
@@ -455,6 +472,8 @@ var util = {
455
472
  // so for sanity sake we should first trim whitespace characters and remove
456
473
  // double quotes around environment strings if the caller is expected to
457
474
  // use this environment string as a file path
475
+
476
+
458
477
  return trim ? dequote(_.trim(result)) : result;
459
478
  },
460
479
  getCacheDir: function getCacheDir() {
@@ -463,33 +482,19 @@ var util = {
463
482
  isPostInstall: function isPostInstall() {
464
483
  return process.env.npm_lifecycle_event === 'postinstall';
465
484
  },
466
-
467
-
468
485
  exec: execa,
469
-
470
486
  stdoutLineMatches: stdoutLineMatches,
471
-
472
487
  issuesUrl: issuesUrl,
473
-
474
488
  isBrokenGtkDisplay: isBrokenGtkDisplay,
475
-
476
489
  logBrokenGtkDisplayWarning: logBrokenGtkDisplayWarning,
477
-
478
490
  isPossibleLinuxWithIncorrectDisplay: isPossibleLinuxWithIncorrectDisplay,
479
-
480
491
  getGitHubIssueUrl: function getGitHubIssueUrl(number) {
481
492
  la(is.positive(number), 'github issue should be a positive number', number);
482
493
  la(_.isInteger(number), 'github issue should be an integer', number);
483
-
484
- return issuesUrl + '/' + number;
494
+ return "".concat(issuesUrl, "/").concat(number);
485
495
  },
486
-
487
-
488
496
  getFileChecksum: getFileChecksum,
489
-
490
497
  getFileSize: getFileSize,
491
-
492
498
  getApplicationDataFolder: getApplicationDataFolder
493
499
  };
494
-
495
500
  module.exports = util;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress",
3
- "version": "4.4.1",
3
+ "version": "4.5.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "postinstall": "node index.js --exec install",