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/index.js +15 -6
- package/lib/cli.js +56 -53
- package/lib/cypress.js +8 -9
- package/lib/errors.js +216 -84
- package/lib/exec/info.js +17 -13
- package/lib/exec/open.js +4 -1
- package/lib/exec/run.js +20 -24
- package/lib/exec/spawn.js +56 -53
- package/lib/exec/versions.js +9 -6
- package/lib/exec/xvfb.js +29 -27
- package/lib/fs.js +1 -1
- package/lib/logger.js +16 -12
- package/lib/tasks/cache.js +11 -12
- package/lib/tasks/download.js +100 -73
- package/lib/tasks/install.js +125 -73
- package/lib/tasks/state.js +35 -19
- package/lib/tasks/unzip.js +38 -44
- package/lib/tasks/verify.js +101 -64
- package/lib/util.js +112 -107
- package/package.json +1 -1
package/lib/tasks/download.js
CHANGED
@@ -1,22 +1,75 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
_templateObject3 = _taggedTemplateLiteral(['\n Corrupted download\n\n Expected downloaded file to have checksum: ', '\n Computed checksum: ', '\n '], ['\n Corrupted download\n\n Expected downloaded file to have checksum: ', '\n Computed checksum: ', '\n ']),
|
6
|
-
_templateObject4 = _taggedTemplateLiteral(['\n Corrupted download\n\n Expected downloaded file to have size: ', '\n Computed size: ', '\n '], ['\n Corrupted download\n\n Expected downloaded file to have size: ', '\n Computed size: ', '\n ']),
|
7
|
-
_templateObject5 = _taggedTemplateLiteral(['\n Failed downloading the Cypress binary.\n Response code: ', '\n Response message: ', '\n '], ['\n Failed downloading the Cypress binary.\n Response code: ', '\n Response message: ', '\n ']);
|
3
|
+
function _templateObject5() {
|
4
|
+
var data = _taggedTemplateLiteral(["\n Failed downloading the Cypress binary.\n Response code: ", "\n Response message: ", "\n "]);
|
8
5
|
|
9
|
-
function
|
6
|
+
_templateObject5 = function _templateObject5() {
|
7
|
+
return data;
|
8
|
+
};
|
9
|
+
|
10
|
+
return data;
|
11
|
+
}
|
12
|
+
|
13
|
+
function _templateObject4() {
|
14
|
+
var data = _taggedTemplateLiteral(["\n Corrupted download\n\n Expected downloaded file to have size: ", "\n Computed size: ", "\n "]);
|
15
|
+
|
16
|
+
_templateObject4 = function _templateObject4() {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
|
20
|
+
return data;
|
21
|
+
}
|
22
|
+
|
23
|
+
function _templateObject3() {
|
24
|
+
var data = _taggedTemplateLiteral(["\n Corrupted download\n\n Expected downloaded file to have checksum: ", "\n Computed checksum: ", "\n "]);
|
25
|
+
|
26
|
+
_templateObject3 = function _templateObject3() {
|
27
|
+
return data;
|
28
|
+
};
|
29
|
+
|
30
|
+
return data;
|
31
|
+
}
|
32
|
+
|
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 "]);
|
35
|
+
|
36
|
+
_templateObject2 = function _templateObject2() {
|
37
|
+
return data;
|
38
|
+
};
|
39
|
+
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
|
43
|
+
function _templateObject() {
|
44
|
+
var data = _taggedTemplateLiteral(["\n URL: ", "\n ", "\n "]);
|
45
|
+
|
46
|
+
_templateObject = function _templateObject() {
|
47
|
+
return data;
|
48
|
+
};
|
49
|
+
|
50
|
+
return data;
|
51
|
+
}
|
52
|
+
|
53
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
10
54
|
|
11
55
|
var arch = require('arch');
|
56
|
+
|
12
57
|
var la = require('lazy-ass');
|
58
|
+
|
13
59
|
var is = require('check-more-types');
|
60
|
+
|
14
61
|
var os = require('os');
|
62
|
+
|
15
63
|
var url = require('url');
|
64
|
+
|
16
65
|
var path = require('path');
|
66
|
+
|
17
67
|
var debug = require('debug')('cypress:cli');
|
68
|
+
|
18
69
|
var request = require('@cypress/request');
|
70
|
+
|
19
71
|
var Promise = require('bluebird');
|
72
|
+
|
20
73
|
var requestProgress = require('request-progress');
|
21
74
|
|
22
75
|
var _require = require('common-tags'),
|
@@ -27,6 +80,7 @@ var _require2 = require('../errors'),
|
|
27
80
|
errors = _require2.errors;
|
28
81
|
|
29
82
|
var fs = require('../fs');
|
83
|
+
|
30
84
|
var util = require('../util');
|
31
85
|
|
32
86
|
var defaultBaseUrl = 'https://download.cypress.io/';
|
@@ -38,7 +92,6 @@ var getProxyUrl = function getProxyUrl() {
|
|
38
92
|
var getRealOsArch = function getRealOsArch() {
|
39
93
|
// os.arch() returns the arch for which this node was compiled
|
40
94
|
// we want the operating system's arch instead: x64 or x86
|
41
|
-
|
42
95
|
var osArch = arch();
|
43
96
|
|
44
97
|
if (osArch === 'x86') {
|
@@ -67,18 +120,16 @@ var prepend = function prepend(urlPath) {
|
|
67
120
|
var endpoint = url.resolve(getBaseUrl(), urlPath);
|
68
121
|
var platform = os.platform();
|
69
122
|
var arch = getRealOsArch();
|
70
|
-
|
71
|
-
return endpoint + '?platform=' + platform + '&arch=' + arch;
|
123
|
+
return "".concat(endpoint, "?platform=").concat(platform, "&arch=").concat(arch);
|
72
124
|
};
|
73
125
|
|
74
126
|
var getUrl = function getUrl(version) {
|
75
127
|
if (is.url(version)) {
|
76
128
|
debug('version is already an url', version);
|
77
|
-
|
78
129
|
return version;
|
79
130
|
}
|
80
131
|
|
81
|
-
return version ? prepend(
|
132
|
+
return version ? prepend("desktop/".concat(version)) : prepend('desktop');
|
82
133
|
};
|
83
134
|
|
84
135
|
var statusMessage = function statusMessage(err) {
|
@@ -86,50 +137,42 @@ var statusMessage = function statusMessage(err) {
|
|
86
137
|
};
|
87
138
|
|
88
139
|
var prettyDownloadErr = function prettyDownloadErr(err, version) {
|
89
|
-
var msg = stripIndent(_templateObject, getUrl(version), statusMessage(err));
|
90
|
-
|
140
|
+
var msg = stripIndent(_templateObject(), getUrl(version), statusMessage(err));
|
91
141
|
debug(msg);
|
92
|
-
|
93
142
|
return throwFormErrorText(errors.failedDownload)(msg);
|
94
143
|
};
|
95
|
-
|
96
144
|
/**
|
97
145
|
* Checks checksum and file size for the given file. Allows both
|
98
146
|
* values or just one of them to be checked.
|
99
147
|
*/
|
148
|
+
|
149
|
+
|
100
150
|
var verifyDownloadedFile = function verifyDownloadedFile(filename, expectedSize, expectedChecksum) {
|
101
151
|
if (expectedSize && expectedChecksum) {
|
102
152
|
debug('verifying checksum and file size');
|
103
|
-
|
104
153
|
return Promise.join(util.getFileChecksum(filename), util.getFileSize(filename), function (checksum, filesize) {
|
105
154
|
if (checksum === expectedChecksum && filesize === expectedSize) {
|
106
155
|
debug('downloaded file has the expected checksum and size ✅');
|
107
|
-
|
108
156
|
return;
|
109
157
|
}
|
110
158
|
|
111
159
|
debug('raising error: checksum or file size mismatch');
|
112
|
-
var text = stripIndent(_templateObject2, expectedChecksum, checksum, expectedSize, filesize);
|
113
|
-
|
160
|
+
var text = stripIndent(_templateObject2(), expectedChecksum, checksum, expectedSize, filesize);
|
114
161
|
debug(text);
|
115
|
-
|
116
162
|
throw new Error(text);
|
117
163
|
});
|
118
164
|
}
|
119
165
|
|
120
166
|
if (expectedChecksum) {
|
121
167
|
debug('only checking expected file checksum %d', expectedChecksum);
|
122
|
-
|
123
168
|
return util.getFileChecksum(filename).then(function (checksum) {
|
124
169
|
if (checksum === expectedChecksum) {
|
125
170
|
debug('downloaded file has the expected checksum ✅');
|
126
|
-
|
127
171
|
return;
|
128
172
|
}
|
129
173
|
|
130
174
|
debug('raising error: file checksum mismatch');
|
131
|
-
var text = stripIndent(_templateObject3, expectedChecksum, checksum);
|
132
|
-
|
175
|
+
var text = stripIndent(_templateObject3(), expectedChecksum, checksum);
|
133
176
|
throw new Error(text);
|
134
177
|
});
|
135
178
|
}
|
@@ -138,69 +181,59 @@ var verifyDownloadedFile = function verifyDownloadedFile(filename, expectedSize,
|
|
138
181
|
// maybe we don't have a checksum, but at least CDN returns content length
|
139
182
|
// which we can check against the file size
|
140
183
|
debug('only checking expected file size %d', expectedSize);
|
141
|
-
|
142
184
|
return util.getFileSize(filename).then(function (filesize) {
|
143
185
|
if (filesize === expectedSize) {
|
144
186
|
debug('downloaded file has the expected size ✅');
|
145
|
-
|
146
187
|
return;
|
147
188
|
}
|
148
189
|
|
149
190
|
debug('raising error: file size mismatch');
|
150
|
-
var text = stripIndent(_templateObject4, expectedSize, filesize);
|
151
|
-
|
191
|
+
var text = stripIndent(_templateObject4(), expectedSize, filesize);
|
152
192
|
throw new Error(text);
|
153
193
|
});
|
154
194
|
}
|
155
195
|
|
156
196
|
debug('downloaded file lacks checksum or size to verify');
|
157
|
-
|
158
197
|
return Promise.resolve();
|
159
|
-
};
|
160
|
-
|
161
|
-
// downloads from given url
|
198
|
+
}; // downloads from given url
|
162
199
|
// return an object with
|
163
200
|
// {filename: ..., downloaded: true}
|
201
|
+
|
202
|
+
|
164
203
|
var downloadFromUrl = function downloadFromUrl(_ref) {
|
165
204
|
var url = _ref.url,
|
166
205
|
downloadDestination = _ref.downloadDestination,
|
167
206
|
progress = _ref.progress;
|
168
|
-
|
169
207
|
return new Promise(function (resolve, reject) {
|
170
208
|
var proxy = getProxyUrl();
|
171
|
-
|
172
209
|
debug('Downloading package', {
|
173
210
|
url: url,
|
174
211
|
proxy: proxy,
|
175
212
|
downloadDestination: downloadDestination
|
176
213
|
});
|
177
|
-
|
178
|
-
var redirectVersion = void 0;
|
179
|
-
|
214
|
+
var redirectVersion;
|
180
215
|
var req = request({
|
181
216
|
url: url,
|
182
217
|
proxy: proxy,
|
183
218
|
followRedirect: function followRedirect(response) {
|
184
219
|
var version = response.headers['x-version'];
|
185
|
-
|
186
220
|
debug('redirect version:', version);
|
221
|
+
|
187
222
|
if (version) {
|
188
223
|
// set the version in options if we have one.
|
189
224
|
// this insulates us from potential redirect
|
190
225
|
// problems where version would be set to undefined.
|
191
226
|
redirectVersion = version;
|
192
|
-
}
|
227
|
+
} // yes redirect
|
228
|
+
|
193
229
|
|
194
|
-
// yes redirect
|
195
230
|
return true;
|
196
231
|
}
|
197
|
-
});
|
232
|
+
}); // closure
|
198
233
|
|
199
|
-
// closure
|
200
234
|
var started = null;
|
201
|
-
var expectedSize
|
202
|
-
var expectedChecksum
|
203
|
-
|
235
|
+
var expectedSize;
|
236
|
+
var expectedChecksum;
|
204
237
|
requestProgress(req, {
|
205
238
|
throttle: progress.throttle
|
206
239
|
}).on('response', function (response) {
|
@@ -209,7 +242,6 @@ var downloadFromUrl = function downloadFromUrl(_ref) {
|
|
209
242
|
// these custom headers "x-amz-meta-..."
|
210
243
|
// see https://github.com/cypress-io/cypress/pull/4092
|
211
244
|
expectedSize = response.headers['x-amz-meta-size'] || response.headers['content-length'];
|
212
|
-
|
213
245
|
expectedChecksum = response.headers['x-amz-meta-checksum'];
|
214
246
|
|
215
247
|
if (expectedChecksum) {
|
@@ -220,77 +252,72 @@ var downloadFromUrl = function downloadFromUrl(_ref) {
|
|
220
252
|
// convert from string (all Amazon custom headers are strings)
|
221
253
|
expectedSize = Number(expectedSize);
|
222
254
|
debug('expected file size %d', expectedSize);
|
223
|
-
}
|
224
|
-
|
225
|
-
// start counting now once we've gotten
|
255
|
+
} // start counting now once we've gotten
|
226
256
|
// response headers
|
227
|
-
started = new Date();
|
228
257
|
|
229
|
-
// if our status code does not start with 200
|
230
|
-
if (!/^2/.test(response.statusCode)) {
|
231
|
-
debug('response code %d', response.statusCode);
|
232
258
|
|
233
|
-
|
259
|
+
started = new Date(); // if our status code does not start with 200
|
234
260
|
|
261
|
+
if (!/^2/.test(response.statusCode)) {
|
262
|
+
debug('response code %d', response.statusCode);
|
263
|
+
var err = new Error(stripIndent(_templateObject5(), response.statusCode, response.statusMessage));
|
235
264
|
reject(err);
|
236
265
|
}
|
237
266
|
}).on('error', reject).on('progress', function (state) {
|
238
267
|
// total time we've elapsed
|
239
268
|
// starting on our first progress notification
|
240
|
-
var elapsed = new Date() - started;
|
269
|
+
var elapsed = new Date() - started; // request-progress sends a value between 0 and 1
|
241
270
|
|
242
|
-
// request-progress sends a value between 0 and 1
|
243
271
|
var percentage = util.convertPercentToPercentage(state.percent);
|
272
|
+
var eta = util.calculateEta(percentage, elapsed); // send up our percent and seconds remaining
|
244
273
|
|
245
|
-
var eta = util.calculateEta(percentage, elapsed);
|
246
|
-
|
247
|
-
// send up our percent and seconds remaining
|
248
274
|
progress.onProgress(percentage, util.secsRemaining(eta));
|
249
|
-
})
|
250
|
-
// save this download here
|
275
|
+
}) // save this download here
|
251
276
|
.pipe(fs.createWriteStream(downloadDestination)).on('finish', function () {
|
252
277
|
debug('downloading finished');
|
253
|
-
|
254
278
|
verifyDownloadedFile(downloadDestination, expectedSize, expectedChecksum).then(function () {
|
255
279
|
return resolve(redirectVersion);
|
256
280
|
}, reject);
|
257
281
|
});
|
258
282
|
});
|
259
283
|
};
|
260
|
-
|
261
284
|
/**
|
262
285
|
* Download Cypress.zip from external url to local file.
|
263
286
|
* @param [string] version Could be "3.3.0" or full URL
|
264
287
|
* @param [string] downloadDestination Local filename to save as
|
265
288
|
*/
|
289
|
+
|
290
|
+
|
266
291
|
var start = function start(opts) {
|
267
292
|
var version = opts.version,
|
268
293
|
downloadDestination = opts.downloadDestination,
|
269
294
|
progress = opts.progress;
|
270
295
|
|
271
|
-
|
272
296
|
if (!downloadDestination) {
|
273
297
|
la(is.unemptyString(downloadDestination), 'missing download dir', opts);
|
274
298
|
}
|
275
299
|
|
276
300
|
if (!progress) {
|
277
|
-
progress = {
|
301
|
+
progress = {
|
302
|
+
onProgress: function onProgress() {
|
278
303
|
return {};
|
279
|
-
}
|
304
|
+
}
|
305
|
+
};
|
280
306
|
}
|
281
307
|
|
282
308
|
var url = getUrl(version);
|
283
|
-
|
284
309
|
progress.throttle = 100;
|
285
|
-
|
286
310
|
debug('needed Cypress version: %s', version);
|
287
311
|
debug('source url %s', url);
|
288
|
-
debug(
|
312
|
+
debug("downloading cypress.zip to \"".concat(downloadDestination, "\"")); // ensure download dir exists
|
289
313
|
|
290
|
-
// ensure download dir exists
|
291
314
|
return fs.ensureDirAsync(path.dirname(downloadDestination)).then(function () {
|
292
|
-
return downloadFromUrl({
|
293
|
-
|
315
|
+
return downloadFromUrl({
|
316
|
+
url: url,
|
317
|
+
downloadDestination: downloadDestination,
|
318
|
+
progress: progress
|
319
|
+
});
|
320
|
+
})["catch"](function (err) {
|
294
321
|
return prettyDownloadErr(err, version);
|
295
322
|
});
|
296
323
|
};
|