cypress 5.0.0 → 5.4.0

Sign up to get free protection for your applications and to get access to all the features.
package/lib/cli.js CHANGED
@@ -55,6 +55,10 @@ function unknownOption(flag) {
55
55
 
56
56
  commander.Command.prototype.unknownOption = unknownOption;
57
57
 
58
+ var coerceFalseOrString = function coerceFalseOrString(arg) {
59
+ return arg !== 'false' ? arg : false;
60
+ };
61
+
58
62
  var coerceFalse = function coerceFalse(arg) {
59
63
  return arg !== 'false';
60
64
  };
@@ -119,8 +123,10 @@ var descriptions = {
119
123
  browserOpenMode: 'path to a custom browser to be added to the list of available browsers in Cypress',
120
124
  browserRunMode: 'runs Cypress in the browser with the given name. if a filesystem path is supplied, Cypress will attempt to use the browser at that path.',
121
125
  cacheClear: 'delete all cached binaries',
126
+ cachePrune: 'deletes all cached binaries except for the version currently in use',
122
127
  cacheList: 'list cached binary versions',
123
128
  cachePath: 'print the path to the binary cache',
129
+ cacheSize: 'Used with the list command to show the sizes of the cached folders',
124
130
  ciBuildId: 'the unique identifier for a run on your CI provider. typically a "BUILD_ID" env var. this value is automatically detected for most CI providers',
125
131
  config: 'sets configuration values. separate multiple values with a comma. overrides any value in cypress.json.',
126
132
  configFile: 'path to JSON file where configuration values are set. defaults to "cypress.json". pass "false" to disable.',
@@ -196,7 +202,7 @@ var castCypressRunOptions = function castCypressRunOptions(opts) {
196
202
  // boolean arguments
197
203
  var result = R.evolve({
198
204
  port: coerceAnyStringToInt,
199
- configFile: coerceFalse
205
+ configFile: coerceFalseOrString
200
206
  })(opts);
201
207
  return result;
202
208
  };
@@ -295,7 +301,7 @@ module.exports = {
295
301
 
296
302
  require('./tasks/verify').start(options)["catch"](util.logErrorExit1);
297
303
  });
298
- program.command('cache').usage('[command]').description('Manages the Cypress binary cache').option('list', text('cacheList')).option('path', text('cachePath')).option('clear', text('cacheClear')).action(function (opts, args) {
304
+ program.command('cache').usage('[command]').description('Manages the Cypress binary cache').option('list', text('cacheList')).option('path', text('cachePath')).option('clear', text('cacheClear')).option('prune', text('cachePrune')).option('--size', text('cacheSize')).action(function (opts, args) {
299
305
  if (!args || !args.length) {
300
306
  this.outputHelp();
301
307
  util.exit(1);
@@ -304,10 +310,15 @@ module.exports = {
304
310
  var _args = _slicedToArray(args, 1),
305
311
  command = _args[0];
306
312
 
307
- if (!_.includes(['list', 'path', 'clear'], command)) {
313
+ if (!_.includes(['list', 'path', 'clear', 'prune'], command)) {
308
314
  unknownOption.call(this, "cache ".concat(command), 'command');
309
315
  }
310
316
 
317
+ if (command === 'list') {
318
+ cache.list(opts.size);
319
+ return;
320
+ }
321
+
311
322
  cache[command]();
312
323
  });
313
324
  program.command('info').usage('[command]').description('Prints Cypress and system information').option('--dev', text('dev'), coerceFalse).action(function (opts) {
package/lib/errors.js CHANGED
@@ -121,7 +121,7 @@ function _templateObject6() {
121
121
  }
122
122
 
123
123
  function _templateObject5() {
124
- var data = _taggedTemplateLiteral(["\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n "], ["\\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n "]);
124
+ var data = _taggedTemplateLiteral(["\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n\n You can also try clearing the cache with 'cypress cache clear' and reinstalling. \n "], ["\\n\n Reasons this may happen:\n\n - node was installed as 'root' or with 'sudo'\n - the cypress npm package as 'root' or with 'sudo'\n\n Please check that you have the appropriate user permissions.\n\n You can also try clearing the cache with 'cypress cache clear' and reinstalling. \n "]);
125
125
 
126
126
  _templateObject5 = function _templateObject5() {
127
127
  return data;
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
4
+
5
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
+
7
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
8
+
3
9
  var state = require('./state');
4
10
 
5
11
  var logger = require('../logger');
@@ -17,13 +23,18 @@ var moment = require('moment');
17
23
 
18
24
  var chalk = require('chalk');
19
25
 
20
- var _ = require('lodash'); // output colors for the table
26
+ var _ = require('lodash');
27
+
28
+ var getFolderSize = require('./get-folder-size');
29
+
30
+ var Bluebird = require('bluebird'); // output colors for the table
21
31
 
22
32
 
23
33
  var colors = {
24
34
  titles: chalk.white,
25
35
  dates: chalk.cyan,
26
- values: chalk.green
36
+ values: chalk.green,
37
+ size: chalk.gray
27
38
  };
28
39
 
29
40
  var logCachePath = function logCachePath() {
@@ -34,27 +45,69 @@ var logCachePath = function logCachePath() {
34
45
  var clear = function clear() {
35
46
  return fs.removeAsync(state.getCacheDir());
36
47
  };
48
+
49
+ var prune = function prune() {
50
+ var cacheDir = state.getCacheDir();
51
+ var currentVersion = util.pkgVersion();
52
+ var deletedBinary = false;
53
+ return fs.readdirAsync(cacheDir).then(function (versions) {
54
+ return Bluebird.all(versions.map(function (version) {
55
+ if (version !== currentVersion) {
56
+ deletedBinary = true;
57
+ var versionDir = join(cacheDir, version);
58
+ return fs.removeAsync(versionDir);
59
+ }
60
+ }));
61
+ }).then(function () {
62
+ if (deletedBinary) {
63
+ logger.always("Deleted all binary caches except for the ".concat(currentVersion, " binary cache."));
64
+ } else {
65
+ logger.always("No binary caches found to prune.");
66
+ }
67
+ })["catch"]({
68
+ code: 'ENOENT'
69
+ }, function () {
70
+ logger.always("No Cypress cache was found at ".concat(cacheDir, ". Nothing to prune."));
71
+ });
72
+ };
73
+
74
+ var fileSizeInMB = function fileSizeInMB(size) {
75
+ return "".concat((size / 1024 / 1024).toFixed(1), "MB");
76
+ };
37
77
  /**
38
78
  * Collects all cached versions, finds when each was used
39
79
  * and prints a table with results to the terminal
40
80
  */
41
81
 
42
82
 
43
- var list = function list() {
44
- return getCachedVersions().then(function (binaries) {
83
+ var list = function list(showSize) {
84
+ return getCachedVersions(showSize).then(function (binaries) {
85
+ var head = [colors.titles('version'), colors.titles('last used')];
86
+
87
+ if (showSize) {
88
+ head.push(colors.titles('size'));
89
+ }
90
+
45
91
  var table = new Table({
46
- head: [colors.titles('version'), colors.titles('last used')]
92
+ head: head
47
93
  });
48
94
  binaries.forEach(function (binary) {
49
95
  var versionString = colors.values(binary.version);
50
96
  var lastUsed = binary.accessed ? colors.dates(binary.accessed) : 'unknown';
51
- return table.push([versionString, lastUsed]);
97
+ var row = [versionString, lastUsed];
98
+
99
+ if (showSize) {
100
+ var size = colors.size(fileSizeInMB(binary.size));
101
+ row.push(size);
102
+ }
103
+
104
+ return table.push(row);
52
105
  });
53
106
  logger.always(table.toString());
54
107
  });
55
108
  };
56
109
 
57
- var getCachedVersions = function getCachedVersions() {
110
+ var getCachedVersions = function getCachedVersions(showSize) {
58
111
  var cacheDir = state.getCacheDir();
59
112
  return fs.readdirAsync(cacheDir).filter(util.isSemver).map(function (version) {
60
113
  return {
@@ -82,12 +135,24 @@ var getCachedVersions = function getCachedVersions() {
82
135
  // could not find the binary or gets its stats
83
136
  return binary;
84
137
  });
138
+ }).mapSeries(function (binary) {
139
+ if (showSize) {
140
+ var binaryDir = state.getBinaryDir(binary.version);
141
+ return getFolderSize(binaryDir).then(function (size) {
142
+ return _objectSpread(_objectSpread({}, binary), {}, {
143
+ size: size
144
+ });
145
+ });
146
+ }
147
+
148
+ return binary;
85
149
  });
86
150
  };
87
151
 
88
152
  module.exports = {
89
153
  path: logCachePath,
90
154
  clear: clear,
155
+ prune: prune,
91
156
  list: list,
92
157
  getCachedVersions: getCachedVersions
93
158
  };
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+
7
+ var fs = require('../fs');
8
+
9
+ var _require = require('path'),
10
+ join = _require.join;
11
+
12
+ var Bluebird = require('bluebird');
13
+ /**
14
+ * Get the size of a folder or a file.
15
+ *
16
+ * This function returns the actual file size of the folder (size), not the allocated space on disk (size on disk).
17
+ * For more details between the difference, check this link:
18
+ * https://www.howtogeek.com/180369/why-is-there-a-big-difference-between-size-and-size-on-disk/
19
+ *
20
+ * @param {string} path path to the file or the folder.
21
+ */
22
+
23
+
24
+ function getSize(_x) {
25
+ return _getSize.apply(this, arguments);
26
+ }
27
+
28
+ function _getSize() {
29
+ _getSize = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(path) {
30
+ var stat, list;
31
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
32
+ while (1) {
33
+ switch (_context2.prev = _context2.next) {
34
+ case 0:
35
+ _context2.next = 2;
36
+ return fs.lstat(path);
37
+
38
+ case 2:
39
+ stat = _context2.sent;
40
+
41
+ if (!stat.isDirectory()) {
42
+ _context2.next = 8;
43
+ break;
44
+ }
45
+
46
+ _context2.next = 6;
47
+ return fs.readdir(path);
48
+
49
+ case 6:
50
+ list = _context2.sent;
51
+ return _context2.abrupt("return", Bluebird.resolve(list).reduce( /*#__PURE__*/function () {
52
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(prev, curr) {
53
+ var currPath, s;
54
+ return regeneratorRuntime.wrap(function _callee$(_context) {
55
+ while (1) {
56
+ switch (_context.prev = _context.next) {
57
+ case 0:
58
+ currPath = join(path, curr);
59
+ _context.next = 3;
60
+ return fs.lstat(currPath);
61
+
62
+ case 3:
63
+ s = _context.sent;
64
+
65
+ if (!s.isDirectory()) {
66
+ _context.next = 10;
67
+ break;
68
+ }
69
+
70
+ _context.t0 = prev;
71
+ _context.next = 8;
72
+ return getSize(currPath);
73
+
74
+ case 8:
75
+ _context.t1 = _context.sent;
76
+ return _context.abrupt("return", _context.t0 + _context.t1);
77
+
78
+ case 10:
79
+ return _context.abrupt("return", prev + s.size);
80
+
81
+ case 11:
82
+ case "end":
83
+ return _context.stop();
84
+ }
85
+ }
86
+ }, _callee);
87
+ }));
88
+
89
+ return function (_x2, _x3) {
90
+ return _ref.apply(this, arguments);
91
+ };
92
+ }(), 0));
93
+
94
+ case 8:
95
+ return _context2.abrupt("return", stat.size);
96
+
97
+ case 9:
98
+ case "end":
99
+ return _context2.stop();
100
+ }
101
+ }
102
+ }, _callee2);
103
+ }));
104
+ return _getSize.apply(this, arguments);
105
+ }
106
+
107
+ module.exports = getSize;
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
+
3
5
  function _templateObject7() {
4
6
  var data = _taggedTemplateLiteral(["\n ", " Warning: Forcing a binary version different than the default.\n\n The CLI expected to install version: ", "\n\n Instead we will install version: ", "\n\n These versions may not work properly together.\n "]);
5
7
 
@@ -20,6 +22,18 @@ function _templateObject6() {
20
22
  return data;
21
23
  }
22
24
 
25
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
26
+
27
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
28
+
29
+ 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(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
30
+
31
+ 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; }
32
+
33
+ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
34
+
35
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
36
+
23
37
  function _templateObject5() {
24
38
  var data = _taggedTemplateLiteral(["\n Failed to access ", ":\n\n ", "\n "]);
25
39
 
@@ -72,10 +86,32 @@ function _templateObject() {
72
86
 
73
87
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
74
88
 
89
+ function _wrapRegExp(re, groups) { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _RegExp = _wrapNativeSuper(RegExp); var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = _RegExp.call(this, re, flags); _groups.set(_this, groups || _groups.get(re)); return _this; } _inherits(BabelRegExp, _RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = []; args.push.apply(args, arguments); if (_typeof(args[args.length - 1]) !== "object") { args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
90
+
91
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
92
+
93
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
94
+
95
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
96
+
97
+ function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
98
+
99
+ function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
100
+
101
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
102
+
103
+ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
104
+
105
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
106
+
107
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
108
+
75
109
  var _ = require('lodash');
76
110
 
77
111
  var os = require('os');
78
112
 
113
+ var url = require('url');
114
+
79
115
  var path = require('path');
80
116
 
81
117
  var chalk = require('chalk');
@@ -109,6 +145,102 @@ var _require2 = require('../errors'),
109
145
  throwFormErrorText = _require2.throwFormErrorText,
110
146
  errors = _require2.errors;
111
147
 
148
+ var getNpmArgv = function getNpmArgv() {
149
+ var json = process.env.npm_config_argv;
150
+
151
+ if (!json) {
152
+ return;
153
+ }
154
+
155
+ debug('found npm argv json %o', json);
156
+
157
+ try {
158
+ return JSON.parse(json).original || [];
159
+ } catch (e) {
160
+ return [];
161
+ }
162
+ }; // attempt to discover the version specifier used to install Cypress
163
+ // for example: "^5.0.0", "https://cdn.cypress.io/...", ...
164
+
165
+
166
+ var getVersionSpecifier = function getVersionSpecifier() {
167
+ var startDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : path.resolve(__dirname, '../..');
168
+ var argv = getNpmArgv();
169
+
170
+ if (argv) {
171
+ var tgz = _.find(argv, function (t) {
172
+ return t.endsWith('cypress.tgz');
173
+ });
174
+
175
+ if (tgz) {
176
+ return tgz;
177
+ }
178
+ }
179
+
180
+ var getVersionSpecifierFromPkg = function getVersionSpecifierFromPkg(dir) {
181
+ debug('looking for versionSpecifier %o', {
182
+ dir: dir
183
+ });
184
+
185
+ var tryParent = function tryParent() {
186
+ var parentPath = path.resolve(dir, '..');
187
+
188
+ if (parentPath === dir) {
189
+ debug('reached FS root with no versionSpecifier found');
190
+ return;
191
+ }
192
+
193
+ return getVersionSpecifierFromPkg(parentPath);
194
+ };
195
+
196
+ return fs.readJSON(path.join(dir, 'package.json'))["catch"](function () {
197
+ return {};
198
+ }).then(function (pkg) {
199
+ var specifier = _.chain(['dependencies', 'devDependencies', 'optionalDependencies']).map(function (prop) {
200
+ return _.get(pkg, "".concat(prop, ".cypress"));
201
+ }).compact().first().value();
202
+
203
+ return specifier || tryParent();
204
+ });
205
+ }; // recurse through parent directories until package.json with `cypress` is found
206
+
207
+
208
+ return getVersionSpecifierFromPkg(startDir).then(function (versionSpecifier) {
209
+ debug('finished looking for versionSpecifier', {
210
+ versionSpecifier: versionSpecifier
211
+ });
212
+ return versionSpecifier;
213
+ });
214
+ };
215
+
216
+ var betaNpmUrlRe = /*#__PURE__*/_wrapRegExp(/^\/beta\/npm\/([\.0-9]+)\/([\0-\.0-\uFFFF]+)\/cypress\.tgz$/, {
217
+ version: 1,
218
+ artifactSlug: 2
219
+ }); // convert a prerelease NPM package .tgz URL to the corresponding binary .zip URL
220
+
221
+
222
+ var getBinaryUrlFromPrereleaseNpmUrl = function getBinaryUrlFromPrereleaseNpmUrl(npmUrl) {
223
+ var parsed;
224
+
225
+ try {
226
+ parsed = url.parse(npmUrl);
227
+ } catch (e) {
228
+ return;
229
+ }
230
+
231
+ var matches = betaNpmUrlRe.exec(parsed.pathname);
232
+
233
+ if (parsed.hostname !== 'cdn.cypress.io' || !matches) {
234
+ return;
235
+ }
236
+
237
+ var _matches$groups = matches.groups,
238
+ version = _matches$groups.version,
239
+ artifactSlug = _matches$groups.artifactSlug;
240
+ parsed.pathname = "/beta/binary/".concat(version, "/").concat(os.platform(), "-").concat(os.arch(), "/").concat(artifactSlug, "/cypress.zip");
241
+ return parsed.format();
242
+ };
243
+
112
244
  var alreadyInstalledMsg = function alreadyInstalledMsg() {
113
245
  if (!util.isPostInstall()) {
114
246
  logger.log(stripIndent(_templateObject(), chalk.yellow('--force')));
@@ -204,6 +336,7 @@ var start = function start() {
204
336
 
205
337
  var pkgVersion = util.pkgVersion();
206
338
  var needVersion = pkgVersion;
339
+ var binaryUrlOverride;
207
340
  debug('version in package.json is', needVersion); // let this environment variable reset the binary version we need
208
341
 
209
342
  if (util.getEnv('CYPRESS_INSTALL_BINARY')) {
@@ -218,14 +351,9 @@ var start = function start() {
218
351
  logger.log(stripIndent(_templateObject3(), chalk.yellow('Note:')));
219
352
  logger.log();
220
353
  return Promise.resolve();
221
- } // if this doesn't match the expected version
222
- // then print warning to the user
223
-
224
-
225
- if (envVarVersion !== needVersion) {
226
- // reset the version to the env var version
227
- needVersion = envVarVersion;
228
354
  }
355
+
356
+ binaryUrlOverride = envVarVersion;
229
357
  }
230
358
 
231
359
  if (util.getEnv('CYPRESS_CACHE_FOLDER')) {
@@ -242,14 +370,32 @@ var start = function start() {
242
370
  }, function (err) {
243
371
  return throwFormErrorText(errors.invalidCacheDirectory)(stripIndent(_templateObject5(), chalk.cyan(cacheDir), err.message));
244
372
  }).then(function () {
245
- return state.getBinaryPkgVersionAsync(binaryDir);
246
- }).then(function (binaryVersion) {
373
+ return Promise.all([state.getBinaryPkgVersionAsync(binaryDir), getVersionSpecifier()]);
374
+ }).then(function (_ref2) {
375
+ var _ref3 = _slicedToArray(_ref2, 2),
376
+ binaryVersion = _ref3[0],
377
+ versionSpecifier = _ref3[1];
378
+
379
+ if (!binaryUrlOverride && versionSpecifier) {
380
+ var computedBinaryUrl = getBinaryUrlFromPrereleaseNpmUrl(versionSpecifier);
381
+
382
+ if (computedBinaryUrl) {
383
+ debug('computed binary url from version specifier %o', {
384
+ computedBinaryUrl: computedBinaryUrl,
385
+ needVersion: needVersion
386
+ });
387
+ binaryUrlOverride = computedBinaryUrl;
388
+ }
389
+ }
390
+
391
+ needVersion = binaryUrlOverride || needVersion;
392
+ debug('installed version is', binaryVersion, 'version needed is', needVersion);
393
+
247
394
  if (!binaryVersion) {
248
395
  debug('no binary installed under cli version');
249
396
  return true;
250
397
  }
251
398
 
252
- debug('installed version is', binaryVersion, 'version needed is', needVersion);
253
399
  logger.log();
254
400
  logger.log(stripIndent(_templateObject6(), chalk.green(binaryVersion), chalk.cyan(installDir)));
255
401
  logger.log();
@@ -332,14 +478,16 @@ var start = function start() {
332
478
  };
333
479
 
334
480
  module.exports = {
335
- start: start
481
+ start: start,
482
+ _getVersionSpecifier: getVersionSpecifier,
483
+ _getBinaryUrlFromPrereleaseNpmUrl: getBinaryUrlFromPrereleaseNpmUrl
336
484
  };
337
485
 
338
- var unzipTask = function unzipTask(_ref2) {
339
- var zipFilePath = _ref2.zipFilePath,
340
- installDir = _ref2.installDir,
341
- progress = _ref2.progress,
342
- rendererOptions = _ref2.rendererOptions;
486
+ var unzipTask = function unzipTask(_ref4) {
487
+ var zipFilePath = _ref4.zipFilePath,
488
+ installDir = _ref4.installDir,
489
+ progress = _ref4.progress,
490
+ rendererOptions = _ref4.rendererOptions;
343
491
  return {
344
492
  title: util.titleize('Unzipping Cypress'),
345
493
  task: function task(ctx, _task3) {
package/lib/util.js CHANGED
@@ -239,7 +239,7 @@ var dequote = function dequote(str) {
239
239
  };
240
240
 
241
241
  var parseOpts = function parseOpts(opts) {
242
- opts = _.pick(opts, 'browser', 'cachePath', 'cacheList', 'cacheClear', 'ciBuildId', 'config', 'configFile', 'cypressVersion', 'destination', 'detached', 'dev', 'exit', 'env', 'force', 'global', 'group', 'headed', 'headless', 'key', 'path', 'parallel', 'port', 'project', 'quiet', 'reporter', 'reporterOptions', 'record', 'spec', 'tag');
242
+ opts = _.pick(opts, 'browser', 'cachePath', 'cacheList', 'cacheClear', 'cachePrune', 'ciBuildId', 'config', 'configFile', 'cypressVersion', 'destination', 'detached', 'dev', 'exit', 'env', 'force', 'global', 'group', 'headed', 'headless', 'key', 'path', 'parallel', 'port', 'project', 'quiet', 'reporter', 'reporterOptions', 'record', 'spec', 'tag');
243
243
 
244
244
  if (opts.exit) {
245
245
  opts = _.omit(opts, 'exit');
@@ -307,7 +307,7 @@ var util = {
307
307
  } // https://github.com/cypress-io/cypress/issues/5431
308
308
 
309
309
 
310
- var NODE_OPTIONS = "--max-http-header-size=".concat(Math.pow(1024, 2), " --http-parser=legacy");
310
+ var NODE_OPTIONS = "--max-http-header-size=".concat(Math.pow(1024, 2));
311
311
 
312
312
  if (_.isString(process.env.NODE_OPTIONS)) {
313
313
  return {
@@ -449,20 +449,19 @@ var util = {
449
449
  },
450
450
  getEnv: function getEnv(varName, trim) {
451
451
  la(is.unemptyString(varName), 'expected environment variable name, not', varName);
452
- var envVar = process.env[varName];
453
- var configVar = process.env["npm_config_".concat(varName)];
454
- var packageConfigVar = process.env["npm_package_config_".concat(varName)];
452
+ var configVarName = "npm_config_".concat(varName);
453
+ var packageConfigVarName = "npm_package_config_".concat(varName);
455
454
  var result;
456
455
 
457
- if (envVar) {
456
+ if (process.env.hasOwnProperty(varName)) {
458
457
  debug("Using ".concat(varName, " from environment variable"));
459
- result = envVar;
460
- } else if (configVar) {
458
+ result = process.env[varName];
459
+ } else if (process.env.hasOwnProperty(configVarName)) {
461
460
  debug("Using ".concat(varName, " from npm config"));
462
- result = configVar;
463
- } else if (packageConfigVar) {
461
+ result = process.env[configVarName];
462
+ } else if (process.env.hasOwnProperty(packageConfigVarName)) {
464
463
  debug("Using ".concat(varName, " from package.json config"));
465
- result = packageConfigVar;
464
+ result = process.env[packageConfigVarName];
466
465
  } // environment variables are often set double quotes to escape characters
467
466
  // and on Windows it can lead to weird things: for example
468
467
  // set FOO="C:\foo.txt" && node -e "console.log('>>>%s<<<', process.env.FOO)"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cypress",
3
- "version": "5.0.0",
3
+ "version": "5.4.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "postinstall": "node index.js --exec install",
@@ -50,7 +50,8 @@
50
50
  "bin",
51
51
  "lib",
52
52
  "index.js",
53
- "types/**/*.d.ts"
53
+ "types/**/*.d.ts",
54
+ "types/net-stubbing.ts"
54
55
  ],
55
56
  "bin": {
56
57
  "cypress": "bin/cypress"