cypress 5.1.0 → 5.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,98 +1,48 @@
1
1
  "use strict";
2
2
 
3
- function _templateObject5() {
4
- var data = _taggedTemplateLiteral(["\n Failed downloading the Cypress binary.\n Response code: ", "\n Response message: ", "\n "]);
3
+ const arch = require('arch');
5
4
 
6
- _templateObject5 = function _templateObject5() {
7
- return data;
8
- };
5
+ const la = require('lazy-ass');
9
6
 
10
- return data;
11
- }
7
+ const is = require('check-more-types');
12
8
 
13
- function _templateObject4() {
14
- var data = _taggedTemplateLiteral(["\n Corrupted download\n\n Expected downloaded file to have size: ", "\n Computed size: ", "\n "]);
9
+ const os = require('os');
15
10
 
16
- _templateObject4 = function _templateObject4() {
17
- return data;
18
- };
11
+ const url = require('url');
19
12
 
20
- return data;
21
- }
13
+ const path = require('path');
22
14
 
23
- function _templateObject3() {
24
- var data = _taggedTemplateLiteral(["\n Corrupted download\n\n Expected downloaded file to have checksum: ", "\n Computed checksum: ", "\n "]);
15
+ const debug = require('debug')('cypress:cli');
25
16
 
26
- _templateObject3 = function _templateObject3() {
27
- return data;
28
- };
17
+ const request = require('@cypress/request');
29
18
 
30
- return data;
31
- }
19
+ const Promise = require('bluebird');
32
20
 
33
- function _templateObject2() {
34
- var data = _taggedTemplateLiteral(["\n Corrupted download\n\n Expected downloaded file to have checksum: ", "\n Computed checksum: ", "\n\n Expected downloaded file to have size: ", "\n Computed size: ", "\n "]);
21
+ const requestProgress = require('request-progress');
35
22
 
36
- _templateObject2 = function _templateObject2() {
37
- return data;
38
- };
23
+ const {
24
+ stripIndent
25
+ } = require('common-tags');
39
26
 
40
- return data;
41
- }
27
+ const {
28
+ throwFormErrorText,
29
+ errors
30
+ } = require('../errors');
42
31
 
43
- function _templateObject() {
44
- var data = _taggedTemplateLiteral(["\n URL: ", "\n ", "\n "]);
32
+ const fs = require('../fs');
45
33
 
46
- _templateObject = function _templateObject() {
47
- return data;
48
- };
34
+ const util = require('../util');
49
35
 
50
- return data;
51
- }
36
+ const defaultBaseUrl = 'https://download.cypress.io/';
52
37
 
53
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
54
-
55
- var arch = require('arch');
56
-
57
- var la = require('lazy-ass');
58
-
59
- var is = require('check-more-types');
60
-
61
- var os = require('os');
62
-
63
- var url = require('url');
64
-
65
- var path = require('path');
66
-
67
- var debug = require('debug')('cypress:cli');
68
-
69
- var request = require('@cypress/request');
70
-
71
- var Promise = require('bluebird');
72
-
73
- var requestProgress = require('request-progress');
74
-
75
- var _require = require('common-tags'),
76
- stripIndent = _require.stripIndent;
77
-
78
- var _require2 = require('../errors'),
79
- throwFormErrorText = _require2.throwFormErrorText,
80
- errors = _require2.errors;
81
-
82
- var fs = require('../fs');
83
-
84
- var util = require('../util');
85
-
86
- var defaultBaseUrl = 'https://download.cypress.io/';
87
-
88
- var getProxyUrl = function getProxyUrl() {
38
+ const getProxyUrl = () => {
89
39
  return process.env.HTTPS_PROXY || process.env.https_proxy || process.env.npm_config_https_proxy || process.env.HTTP_PROXY || process.env.http_proxy || process.env.npm_config_proxy || null;
90
40
  };
91
41
 
92
- var getRealOsArch = function getRealOsArch() {
42
+ const getRealOsArch = () => {
93
43
  // os.arch() returns the arch for which this node was compiled
94
44
  // we want the operating system's arch instead: x64 or x86
95
- var osArch = arch();
45
+ const osArch = arch();
96
46
 
97
47
  if (osArch === 'x86') {
98
48
  // match process.platform output
@@ -102,9 +52,9 @@ var getRealOsArch = function getRealOsArch() {
102
52
  return osArch;
103
53
  };
104
54
 
105
- var getBaseUrl = function getBaseUrl() {
55
+ const getBaseUrl = () => {
106
56
  if (util.getEnv('CYPRESS_DOWNLOAD_MIRROR')) {
107
- var baseUrl = util.getEnv('CYPRESS_DOWNLOAD_MIRROR');
57
+ let baseUrl = util.getEnv('CYPRESS_DOWNLOAD_MIRROR');
108
58
 
109
59
  if (!baseUrl.endsWith('/')) {
110
60
  baseUrl += '/';
@@ -116,28 +66,31 @@ var getBaseUrl = function getBaseUrl() {
116
66
  return defaultBaseUrl;
117
67
  };
118
68
 
119
- var prepend = function prepend(urlPath) {
120
- var endpoint = url.resolve(getBaseUrl(), urlPath);
121
- var platform = os.platform();
122
- var arch = getRealOsArch();
123
- return "".concat(endpoint, "?platform=").concat(platform, "&arch=").concat(arch);
69
+ const prepend = urlPath => {
70
+ const endpoint = url.resolve(getBaseUrl(), urlPath);
71
+ const platform = os.platform();
72
+ const arch = getRealOsArch();
73
+ return `${endpoint}?platform=${platform}&arch=${arch}`;
124
74
  };
125
75
 
126
- var getUrl = function getUrl(version) {
76
+ const getUrl = version => {
127
77
  if (is.url(version)) {
128
78
  debug('version is already an url', version);
129
79
  return version;
130
80
  }
131
81
 
132
- return version ? prepend("desktop/".concat(version)) : prepend('desktop');
82
+ return version ? prepend(`desktop/${version}`) : prepend('desktop');
133
83
  };
134
84
 
135
- var statusMessage = function statusMessage(err) {
85
+ const statusMessage = err => {
136
86
  return err.statusCode ? [err.statusCode, err.statusMessage].join(' - ') : err.toString();
137
87
  };
138
88
 
139
- var prettyDownloadErr = function prettyDownloadErr(err, version) {
140
- var msg = stripIndent(_templateObject(), getUrl(version), statusMessage(err));
89
+ const prettyDownloadErr = (err, version) => {
90
+ const msg = stripIndent`
91
+ URL: ${getUrl(version)}
92
+ ${statusMessage(err)}
93
+ `;
141
94
  debug(msg);
142
95
  return throwFormErrorText(errors.failedDownload)(msg);
143
96
  };
@@ -147,17 +100,25 @@ var prettyDownloadErr = function prettyDownloadErr(err, version) {
147
100
  */
148
101
 
149
102
 
150
- var verifyDownloadedFile = function verifyDownloadedFile(filename, expectedSize, expectedChecksum) {
103
+ const verifyDownloadedFile = (filename, expectedSize, expectedChecksum) => {
151
104
  if (expectedSize && expectedChecksum) {
152
105
  debug('verifying checksum and file size');
153
- return Promise.join(util.getFileChecksum(filename), util.getFileSize(filename), function (checksum, filesize) {
106
+ return Promise.join(util.getFileChecksum(filename), util.getFileSize(filename), (checksum, filesize) => {
154
107
  if (checksum === expectedChecksum && filesize === expectedSize) {
155
108
  debug('downloaded file has the expected checksum and size ✅');
156
109
  return;
157
110
  }
158
111
 
159
112
  debug('raising error: checksum or file size mismatch');
160
- var text = stripIndent(_templateObject2(), expectedChecksum, checksum, expectedSize, filesize);
113
+ const text = stripIndent`
114
+ Corrupted download
115
+
116
+ Expected downloaded file to have checksum: ${expectedChecksum}
117
+ Computed checksum: ${checksum}
118
+
119
+ Expected downloaded file to have size: ${expectedSize}
120
+ Computed size: ${filesize}
121
+ `;
161
122
  debug(text);
162
123
  throw new Error(text);
163
124
  });
@@ -165,14 +126,19 @@ var verifyDownloadedFile = function verifyDownloadedFile(filename, expectedSize,
165
126
 
166
127
  if (expectedChecksum) {
167
128
  debug('only checking expected file checksum %d', expectedChecksum);
168
- return util.getFileChecksum(filename).then(function (checksum) {
129
+ return util.getFileChecksum(filename).then(checksum => {
169
130
  if (checksum === expectedChecksum) {
170
131
  debug('downloaded file has the expected checksum ✅');
171
132
  return;
172
133
  }
173
134
 
174
135
  debug('raising error: file checksum mismatch');
175
- var text = stripIndent(_templateObject3(), expectedChecksum, checksum);
136
+ const text = stripIndent`
137
+ Corrupted download
138
+
139
+ Expected downloaded file to have checksum: ${expectedChecksum}
140
+ Computed checksum: ${checksum}
141
+ `;
176
142
  throw new Error(text);
177
143
  });
178
144
  }
@@ -181,14 +147,19 @@ var verifyDownloadedFile = function verifyDownloadedFile(filename, expectedSize,
181
147
  // maybe we don't have a checksum, but at least CDN returns content length
182
148
  // which we can check against the file size
183
149
  debug('only checking expected file size %d', expectedSize);
184
- return util.getFileSize(filename).then(function (filesize) {
150
+ return util.getFileSize(filename).then(filesize => {
185
151
  if (filesize === expectedSize) {
186
152
  debug('downloaded file has the expected size ✅');
187
153
  return;
188
154
  }
189
155
 
190
156
  debug('raising error: file size mismatch');
191
- var text = stripIndent(_templateObject4(), expectedSize, filesize);
157
+ const text = stripIndent`
158
+ Corrupted download
159
+
160
+ Expected downloaded file to have size: ${expectedSize}
161
+ Computed size: ${filesize}
162
+ `;
192
163
  throw new Error(text);
193
164
  });
194
165
  }
@@ -200,23 +171,25 @@ var verifyDownloadedFile = function verifyDownloadedFile(filename, expectedSize,
200
171
  // {filename: ..., downloaded: true}
201
172
 
202
173
 
203
- var downloadFromUrl = function downloadFromUrl(_ref) {
204
- var url = _ref.url,
205
- downloadDestination = _ref.downloadDestination,
206
- progress = _ref.progress;
207
- return new Promise(function (resolve, reject) {
208
- var proxy = getProxyUrl();
174
+ const downloadFromUrl = ({
175
+ url,
176
+ downloadDestination,
177
+ progress
178
+ }) => {
179
+ return new Promise((resolve, reject) => {
180
+ const proxy = getProxyUrl();
209
181
  debug('Downloading package', {
210
- url: url,
211
- proxy: proxy,
212
- downloadDestination: downloadDestination
182
+ url,
183
+ proxy,
184
+ downloadDestination
213
185
  });
214
- var redirectVersion;
215
- var req = request({
216
- url: url,
217
- proxy: proxy,
218
- followRedirect: function followRedirect(response) {
219
- var version = response.headers['x-version'];
186
+ let redirectVersion;
187
+ const req = request({
188
+ url,
189
+ proxy,
190
+
191
+ followRedirect(response) {
192
+ const version = response.headers['x-version'];
220
193
  debug('redirect version:', version);
221
194
 
222
195
  if (version) {
@@ -229,14 +202,15 @@ var downloadFromUrl = function downloadFromUrl(_ref) {
229
202
 
230
203
  return true;
231
204
  }
205
+
232
206
  }); // closure
233
207
 
234
- var started = null;
235
- var expectedSize;
236
- var expectedChecksum;
208
+ let started = null;
209
+ let expectedSize;
210
+ let expectedChecksum;
237
211
  requestProgress(req, {
238
212
  throttle: progress.throttle
239
- }).on('response', function (response) {
213
+ }).on('response', response => {
240
214
  // we have computed checksum and filesize during test runner binary build
241
215
  // and have set it on the S3 object as user meta data, available via
242
216
  // these custom headers "x-amz-meta-..."
@@ -260,22 +234,26 @@ var downloadFromUrl = function downloadFromUrl(_ref) {
260
234
 
261
235
  if (!/^2/.test(response.statusCode)) {
262
236
  debug('response code %d', response.statusCode);
263
- var err = new Error(stripIndent(_templateObject5(), response.statusCode, response.statusMessage));
237
+ const err = new Error(stripIndent`
238
+ Failed downloading the Cypress binary.
239
+ Response code: ${response.statusCode}
240
+ Response message: ${response.statusMessage}
241
+ `);
264
242
  reject(err);
265
243
  }
266
- }).on('error', reject).on('progress', function (state) {
244
+ }).on('error', reject).on('progress', state => {
267
245
  // total time we've elapsed
268
246
  // starting on our first progress notification
269
- var elapsed = new Date() - started; // request-progress sends a value between 0 and 1
247
+ const elapsed = new Date() - started; // request-progress sends a value between 0 and 1
270
248
 
271
- var percentage = util.convertPercentToPercentage(state.percent);
272
- var eta = util.calculateEta(percentage, elapsed); // send up our percent and seconds remaining
249
+ const percentage = util.convertPercentToPercentage(state.percent);
250
+ const eta = util.calculateEta(percentage, elapsed); // send up our percent and seconds remaining
273
251
 
274
252
  progress.onProgress(percentage, util.secsRemaining(eta));
275
253
  }) // save this download here
276
- .pipe(fs.createWriteStream(downloadDestination)).on('finish', function () {
254
+ .pipe(fs.createWriteStream(downloadDestination)).on('finish', () => {
277
255
  debug('downloading finished');
278
- verifyDownloadedFile(downloadDestination, expectedSize, expectedChecksum).then(function () {
256
+ verifyDownloadedFile(downloadDestination, expectedSize, expectedChecksum).then(() => {
279
257
  return resolve(redirectVersion);
280
258
  }, reject);
281
259
  });
@@ -288,10 +266,12 @@ var downloadFromUrl = function downloadFromUrl(_ref) {
288
266
  */
289
267
 
290
268
 
291
- var start = function start(opts) {
292
- var version = opts.version,
293
- downloadDestination = opts.downloadDestination,
294
- progress = opts.progress;
269
+ const start = opts => {
270
+ let {
271
+ version,
272
+ downloadDestination,
273
+ progress
274
+ } = opts;
295
275
 
296
276
  if (!downloadDestination) {
297
277
  la(is.unemptyString(downloadDestination), 'missing download dir', opts);
@@ -299,31 +279,31 @@ var start = function start(opts) {
299
279
 
300
280
  if (!progress) {
301
281
  progress = {
302
- onProgress: function onProgress() {
282
+ onProgress: () => {
303
283
  return {};
304
284
  }
305
285
  };
306
286
  }
307
287
 
308
- var url = getUrl(version);
288
+ const url = getUrl(version);
309
289
  progress.throttle = 100;
310
290
  debug('needed Cypress version: %s', version);
311
291
  debug('source url %s', url);
312
- debug("downloading cypress.zip to \"".concat(downloadDestination, "\"")); // ensure download dir exists
292
+ debug(`downloading cypress.zip to "${downloadDestination}"`); // ensure download dir exists
313
293
 
314
- return fs.ensureDirAsync(path.dirname(downloadDestination)).then(function () {
294
+ return fs.ensureDirAsync(path.dirname(downloadDestination)).then(() => {
315
295
  return downloadFromUrl({
316
- url: url,
317
- downloadDestination: downloadDestination,
318
- progress: progress
296
+ url,
297
+ downloadDestination,
298
+ progress
319
299
  });
320
- })["catch"](function (err) {
300
+ }).catch(err => {
321
301
  return prettyDownloadErr(err, version);
322
302
  });
323
303
  };
324
304
 
325
305
  module.exports = {
326
- start: start,
327
- getUrl: getUrl,
328
- getProxyUrl: getProxyUrl
306
+ start,
307
+ getUrl,
308
+ getProxyUrl
329
309
  };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ const fs = require('../fs');
4
+
5
+ const {
6
+ join
7
+ } = require('path');
8
+
9
+ const Bluebird = require('bluebird');
10
+ /**
11
+ * Get the size of a folder or a file.
12
+ *
13
+ * This function returns the actual file size of the folder (size), not the allocated space on disk (size on disk).
14
+ * For more details between the difference, check this link:
15
+ * https://www.howtogeek.com/180369/why-is-there-a-big-difference-between-size-and-size-on-disk/
16
+ *
17
+ * @param {string} path path to the file or the folder.
18
+ */
19
+
20
+
21
+ async function getSize(path) {
22
+ const stat = await fs.lstat(path);
23
+
24
+ if (stat.isDirectory()) {
25
+ const list = await fs.readdir(path);
26
+ return Bluebird.resolve(list).reduce(async (prev, curr) => {
27
+ const currPath = join(path, curr);
28
+ const s = await fs.lstat(currPath);
29
+
30
+ if (s.isDirectory()) {
31
+ return prev + (await getSize(currPath));
32
+ }
33
+
34
+ return prev + s.size;
35
+ }, 0);
36
+ }
37
+
38
+ return stat.size;
39
+ }
40
+
41
+ module.exports = getSize;