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/install.js
CHANGED
@@ -1,33 +1,108 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
_templateObject3 = _taggedTemplateLiteral(['\n ', ' Skipping binary installation: Environment variable CYPRESS_INSTALL_BINARY = 0.'], ['\n ', ' Skipping binary installation: Environment variable CYPRESS_INSTALL_BINARY = 0.']),
|
6
|
-
_templateObject4 = _taggedTemplateLiteral(['\n ', ' Overriding Cypress cache directory to: ', '\n\n Previous installs of Cypress may not be found.\n '], ['\n ', ' Overriding Cypress cache directory to: ', '\n\n Previous installs of Cypress may not be found.\n ']),
|
7
|
-
_templateObject5 = _taggedTemplateLiteral(['\n Failed to access ', ':\n\n ', '\n '], ['\n Failed to access ', ':\n\n ', '\n ']),
|
8
|
-
_templateObject6 = _taggedTemplateLiteral(['\n Cypress ', ' is installed in ', '\n '], ['\n Cypress ', ' is installed in ', '\n ']),
|
9
|
-
_templateObject7 = _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 '], ['\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 ']);
|
3
|
+
function _templateObject7() {
|
4
|
+
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 "]);
|
10
5
|
|
11
|
-
function
|
6
|
+
_templateObject7 = function _templateObject7() {
|
7
|
+
return data;
|
8
|
+
};
|
9
|
+
|
10
|
+
return data;
|
11
|
+
}
|
12
|
+
|
13
|
+
function _templateObject6() {
|
14
|
+
var data = _taggedTemplateLiteral(["\n Cypress ", " is installed in ", "\n "]);
|
15
|
+
|
16
|
+
_templateObject6 = function _templateObject6() {
|
17
|
+
return data;
|
18
|
+
};
|
19
|
+
|
20
|
+
return data;
|
21
|
+
}
|
22
|
+
|
23
|
+
function _templateObject5() {
|
24
|
+
var data = _taggedTemplateLiteral(["\n Failed to access ", ":\n\n ", "\n "]);
|
25
|
+
|
26
|
+
_templateObject5 = function _templateObject5() {
|
27
|
+
return data;
|
28
|
+
};
|
29
|
+
|
30
|
+
return data;
|
31
|
+
}
|
32
|
+
|
33
|
+
function _templateObject4() {
|
34
|
+
var data = _taggedTemplateLiteral(["\n ", " Overriding Cypress cache directory to: ", "\n\n Previous installs of Cypress may not be found.\n "]);
|
35
|
+
|
36
|
+
_templateObject4 = function _templateObject4() {
|
37
|
+
return data;
|
38
|
+
};
|
39
|
+
|
40
|
+
return data;
|
41
|
+
}
|
42
|
+
|
43
|
+
function _templateObject3() {
|
44
|
+
var data = _taggedTemplateLiteral(["\n ", " Skipping binary installation: Environment variable CYPRESS_INSTALL_BINARY = 0."]);
|
45
|
+
|
46
|
+
_templateObject3 = function _templateObject3() {
|
47
|
+
return data;
|
48
|
+
};
|
49
|
+
|
50
|
+
return data;
|
51
|
+
}
|
52
|
+
|
53
|
+
function _templateObject2() {
|
54
|
+
var data = _taggedTemplateLiteral(["\n ", " Warning: It looks like you've installed Cypress globally.\n\n This will work, but it's not recommended.\n\n The recommended way to install Cypress is as a devDependency per project.\n\n You should probably run these commands:\n\n - ", "\n - ", "\n "], ["\n ", " Warning: It looks like you\\'ve installed Cypress globally.\n\n This will work, but it'\\s not recommended.\n\n The recommended way to install Cypress is as a devDependency per project.\n\n You should probably run these commands:\n\n - ", "\n - ", "\n "]);
|
55
|
+
|
56
|
+
_templateObject2 = function _templateObject2() {
|
57
|
+
return data;
|
58
|
+
};
|
59
|
+
|
60
|
+
return data;
|
61
|
+
}
|
62
|
+
|
63
|
+
function _templateObject() {
|
64
|
+
var data = _taggedTemplateLiteral(["\n Skipping installation:\n\n Pass the ", " option if you'd like to reinstall anyway.\n "]);
|
65
|
+
|
66
|
+
_templateObject = function _templateObject() {
|
67
|
+
return data;
|
68
|
+
};
|
69
|
+
|
70
|
+
return data;
|
71
|
+
}
|
72
|
+
|
73
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
12
74
|
|
13
75
|
var _ = require('lodash');
|
76
|
+
|
14
77
|
var os = require('os');
|
78
|
+
|
15
79
|
var path = require('path');
|
80
|
+
|
16
81
|
var chalk = require('chalk');
|
82
|
+
|
17
83
|
var debug = require('debug')('cypress:cli');
|
84
|
+
|
18
85
|
var Listr = require('listr');
|
86
|
+
|
19
87
|
var verbose = require('@cypress/listr-verbose-renderer');
|
88
|
+
|
20
89
|
var Promise = require('bluebird');
|
90
|
+
|
21
91
|
var logSymbols = require('log-symbols');
|
22
92
|
|
23
93
|
var _require = require('common-tags'),
|
24
94
|
stripIndent = _require.stripIndent;
|
25
95
|
|
26
96
|
var fs = require('../fs');
|
97
|
+
|
27
98
|
var download = require('./download');
|
99
|
+
|
28
100
|
var util = require('../util');
|
101
|
+
|
29
102
|
var state = require('./state');
|
103
|
+
|
30
104
|
var unzip = require('./unzip');
|
105
|
+
|
31
106
|
var logger = require('../logger');
|
32
107
|
|
33
108
|
var _require2 = require('../errors'),
|
@@ -36,7 +111,7 @@ var _require2 = require('../errors'),
|
|
36
111
|
|
37
112
|
var alreadyInstalledMsg = function alreadyInstalledMsg() {
|
38
113
|
if (!util.isPostInstall()) {
|
39
|
-
logger.log(stripIndent(_templateObject, chalk.yellow('--force')));
|
114
|
+
logger.log(stripIndent(_templateObject(), chalk.yellow('--force')));
|
40
115
|
}
|
41
116
|
};
|
42
117
|
|
@@ -45,14 +120,12 @@ var displayCompletionMsg = function displayCompletionMsg() {
|
|
45
120
|
if (util.isInstalledGlobally()) {
|
46
121
|
// if we are display a warning
|
47
122
|
logger.log();
|
48
|
-
logger.warn(stripIndent(_templateObject2, logSymbols.warning, chalk.cyan('npm uninstall -g cypress'), chalk.cyan('npm install --save-dev cypress')));
|
49
|
-
|
123
|
+
logger.warn(stripIndent(_templateObject2(), logSymbols.warning, chalk.cyan('npm uninstall -g cypress'), chalk.cyan('npm install --save-dev cypress')));
|
50
124
|
return;
|
51
125
|
}
|
52
126
|
|
53
127
|
logger.log();
|
54
128
|
logger.log('You can now open Cypress by running:', chalk.cyan(path.join('node_modules', '.bin', 'cypress'), 'open'));
|
55
|
-
|
56
129
|
logger.log();
|
57
130
|
logger.log(chalk.grey('https://on.cypress.io/installing-cypress'));
|
58
131
|
logger.log();
|
@@ -62,28 +135,27 @@ var downloadAndUnzip = function downloadAndUnzip(_ref) {
|
|
62
135
|
var version = _ref.version,
|
63
136
|
installDir = _ref.installDir,
|
64
137
|
downloadDir = _ref.downloadDir;
|
65
|
-
|
66
138
|
var progress = {
|
67
139
|
throttle: 100,
|
68
140
|
onProgress: null
|
69
141
|
};
|
70
142
|
var downloadDestination = path.join(downloadDir, 'cypress.zip');
|
71
|
-
var rendererOptions = getRendererOptions();
|
143
|
+
var rendererOptions = getRendererOptions(); // let the user know what version of cypress we're downloading!
|
72
144
|
|
73
|
-
|
74
|
-
logger.log('Installing Cypress ' + chalk.gray('(version: ' + version + ')'));
|
145
|
+
logger.log("Installing Cypress ".concat(chalk.gray("(version: ".concat(version, ")"))));
|
75
146
|
logger.log();
|
76
|
-
|
77
147
|
var tasks = new Listr([{
|
78
148
|
title: util.titleize('Downloading Cypress'),
|
79
149
|
task: function task(ctx, _task) {
|
80
150
|
// as our download progresses indicate the status
|
81
151
|
progress.onProgress = progessify(_task, 'Downloading Cypress');
|
82
|
-
|
83
|
-
|
152
|
+
return download.start({
|
153
|
+
version: version,
|
154
|
+
downloadDestination: downloadDestination,
|
155
|
+
progress: progress
|
156
|
+
}).then(function (redirectVersion) {
|
84
157
|
if (redirectVersion) version = redirectVersion;
|
85
|
-
|
86
|
-
debug('finished downloading file: ' + downloadDestination);
|
158
|
+
debug("finished downloading file: ".concat(downloadDestination));
|
87
159
|
}).then(function () {
|
88
160
|
// save the download destination for unzipping
|
89
161
|
util.setTaskTitle(_task, util.titleize(chalk.green('Downloaded Cypress')), rendererOptions.renderer);
|
@@ -99,19 +171,16 @@ var downloadAndUnzip = function downloadAndUnzip(_ref) {
|
|
99
171
|
task: function task(ctx, _task2) {
|
100
172
|
var cleanup = function cleanup() {
|
101
173
|
debug('removing zip file %s', downloadDestination);
|
102
|
-
|
103
174
|
return fs.removeAsync(downloadDestination);
|
104
175
|
};
|
105
176
|
|
106
177
|
return cleanup().then(function () {
|
107
178
|
debug('finished installation in', installDir);
|
108
|
-
|
109
179
|
util.setTaskTitle(_task2, util.titleize(chalk.green('Finished Installation'), chalk.gray(installDir)), rendererOptions.renderer);
|
110
180
|
});
|
111
181
|
}
|
112
|
-
}], rendererOptions);
|
182
|
+
}], rendererOptions); // start the tasks!
|
113
183
|
|
114
|
-
// start the tasks!
|
115
184
|
return Promise.resolve(tasks.run());
|
116
185
|
};
|
117
186
|
|
@@ -135,29 +204,24 @@ var start = function start() {
|
|
135
204
|
|
136
205
|
var pkgVersion = util.pkgVersion();
|
137
206
|
var needVersion = pkgVersion;
|
207
|
+
debug('version in package.json is', needVersion); // let this environment variable reset the binary version we need
|
138
208
|
|
139
|
-
debug('version in package.json is', needVersion);
|
140
|
-
|
141
|
-
// let this environment variable reset the binary version we need
|
142
209
|
if (util.getEnv('CYPRESS_INSTALL_BINARY')) {
|
143
210
|
// because passed file paths are often double quoted
|
144
211
|
// and might have extra whitespace around, be robust and trim the string
|
145
212
|
var trimAndRemoveDoubleQuotes = true;
|
146
213
|
var envVarVersion = util.getEnv('CYPRESS_INSTALL_BINARY', trimAndRemoveDoubleQuotes);
|
147
|
-
|
148
214
|
debug('using environment variable CYPRESS_INSTALL_BINARY "%s"', envVarVersion);
|
149
215
|
|
150
216
|
if (envVarVersion === '0') {
|
151
217
|
debug('environment variable CYPRESS_INSTALL_BINARY = 0, skipping install');
|
152
|
-
logger.log(stripIndent(_templateObject3, chalk.yellow('Note:')));
|
153
|
-
|
218
|
+
logger.log(stripIndent(_templateObject3(), chalk.yellow('Note:')));
|
154
219
|
logger.log();
|
155
|
-
|
156
220
|
return Promise.resolve();
|
157
|
-
}
|
158
|
-
|
159
|
-
// if this doesn't match the expected version
|
221
|
+
} // if this doesn't match the expected version
|
160
222
|
// then print warning to the user
|
223
|
+
|
224
|
+
|
161
225
|
if (envVarVersion !== needVersion) {
|
162
226
|
// reset the version to the env var version
|
163
227
|
needVersion = envVarVersion;
|
@@ -166,44 +230,38 @@ var start = function start() {
|
|
166
230
|
|
167
231
|
if (util.getEnv('CYPRESS_CACHE_FOLDER')) {
|
168
232
|
var envCache = util.getEnv('CYPRESS_CACHE_FOLDER');
|
169
|
-
|
170
|
-
logger.log(stripIndent(_templateObject4, chalk.yellow('Note:'), chalk.cyan(envCache)));
|
171
|
-
|
233
|
+
logger.log(stripIndent(_templateObject4(), chalk.yellow('Note:'), chalk.cyan(envCache)));
|
172
234
|
logger.log();
|
173
235
|
}
|
174
236
|
|
175
237
|
var installDir = state.getVersionDir(pkgVersion);
|
176
238
|
var cacheDir = state.getCacheDir();
|
177
239
|
var binaryDir = state.getBinaryDir(pkgVersion);
|
178
|
-
|
179
|
-
|
180
|
-
|
240
|
+
return fs.ensureDirAsync(cacheDir)["catch"]({
|
241
|
+
code: 'EACCES'
|
242
|
+
}, function (err) {
|
243
|
+
return throwFormErrorText(errors.invalidCacheDirectory)(stripIndent(_templateObject5(), chalk.cyan(cacheDir), err.message));
|
181
244
|
}).then(function () {
|
182
245
|
return state.getBinaryPkgVersionAsync(binaryDir);
|
183
246
|
}).then(function (binaryVersion) {
|
184
247
|
if (!binaryVersion) {
|
185
248
|
debug('no binary installed under cli version');
|
186
|
-
|
187
249
|
return true;
|
188
250
|
}
|
189
251
|
|
190
252
|
debug('installed version is', binaryVersion, 'version needed is', needVersion);
|
191
|
-
|
192
253
|
logger.log();
|
193
|
-
logger.log(stripIndent(_templateObject6, chalk.green(binaryVersion), chalk.cyan(installDir)));
|
194
|
-
|
254
|
+
logger.log(stripIndent(_templateObject6(), chalk.green(binaryVersion), chalk.cyan(installDir)));
|
195
255
|
logger.log();
|
196
256
|
|
197
257
|
if (options.force) {
|
198
258
|
debug('performing force install over existing binary');
|
199
|
-
|
200
259
|
return true;
|
201
260
|
}
|
202
261
|
|
203
262
|
if (binaryVersion === needVersion || !util.isSemver(needVersion)) {
|
204
263
|
// our version matches, tell the user this is a noop
|
205
264
|
alreadyInstalledMsg();
|
206
|
-
|
207
265
|
return false;
|
208
266
|
}
|
209
267
|
|
@@ -212,26 +270,22 @@ var start = function start() {
|
|
212
270
|
// noop if we've been told not to download
|
213
271
|
if (!shouldInstall) {
|
214
272
|
debug('Not downloading or installing binary');
|
215
|
-
|
216
273
|
return;
|
217
274
|
}
|
218
275
|
|
219
276
|
if (needVersion !== pkgVersion) {
|
220
|
-
logger.log(chalk.yellow(stripIndent(_templateObject7, logSymbols.warning, chalk.green(pkgVersion), chalk.green(needVersion))));
|
221
|
-
|
277
|
+
logger.log(chalk.yellow(stripIndent(_templateObject7(), logSymbols.warning, chalk.green(pkgVersion), chalk.green(needVersion))));
|
222
278
|
logger.log();
|
223
|
-
}
|
279
|
+
} // see if version supplied is a path to a binary
|
280
|
+
|
224
281
|
|
225
|
-
// see if version supplied is a path to a binary
|
226
282
|
return fs.pathExistsAsync(needVersion).then(function (exists) {
|
227
283
|
if (exists) {
|
228
284
|
return path.extname(needVersion) === '.zip' ? needVersion : false;
|
229
285
|
}
|
230
286
|
|
231
287
|
var possibleFile = util.formAbsolutePath(needVersion);
|
232
|
-
|
233
288
|
debug('checking local file', possibleFile, 'cwd', process.cwd());
|
234
|
-
|
235
289
|
return fs.pathExistsAsync(possibleFile).then(function (exists) {
|
236
290
|
// if this exists return the path to it
|
237
291
|
// else false
|
@@ -244,12 +298,9 @@ var start = function start() {
|
|
244
298
|
}).then(function (pathToLocalFile) {
|
245
299
|
if (pathToLocalFile) {
|
246
300
|
var absolutePath = path.resolve(needVersion);
|
247
|
-
|
248
301
|
debug('found local file at', absolutePath);
|
249
302
|
debug('skipping download');
|
250
|
-
|
251
303
|
var rendererOptions = getRendererOptions();
|
252
|
-
|
253
304
|
return new Listr([unzipTask({
|
254
305
|
progress: {
|
255
306
|
throttle: 100,
|
@@ -267,12 +318,13 @@ var start = function start() {
|
|
267
318
|
}
|
268
319
|
|
269
320
|
debug('preparing to download and unzip version ', needVersion, 'to path', installDir);
|
270
|
-
|
271
321
|
var downloadDir = os.tmpdir();
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
322
|
+
return downloadAndUnzip({
|
323
|
+
version: needVersion,
|
324
|
+
installDir: installDir,
|
325
|
+
downloadDir: downloadDir
|
326
|
+
});
|
327
|
+
}) // delay 1 sec for UX, unless we are testing
|
276
328
|
.then(function () {
|
277
329
|
return Promise.delay(1000);
|
278
330
|
}).then(displayCompletionMsg);
|
@@ -288,14 +340,16 @@ var unzipTask = function unzipTask(_ref2) {
|
|
288
340
|
installDir = _ref2.installDir,
|
289
341
|
progress = _ref2.progress,
|
290
342
|
rendererOptions = _ref2.rendererOptions;
|
291
|
-
|
292
343
|
return {
|
293
344
|
title: util.titleize('Unzipping Cypress'),
|
294
345
|
task: function task(ctx, _task3) {
|
295
346
|
// as our unzip progresses indicate the status
|
296
347
|
progress.onProgress = progessify(_task3, 'Unzipping Cypress');
|
297
|
-
|
298
|
-
|
348
|
+
return unzip.start({
|
349
|
+
zipFilePath: zipFilePath,
|
350
|
+
installDir: installDir,
|
351
|
+
progress: progress
|
352
|
+
}).then(function () {
|
299
353
|
util.setTaskTitle(_task3, util.titleize(chalk.green('Unzipped Cypress')), rendererOptions.renderer);
|
300
354
|
});
|
301
355
|
}
|
@@ -305,18 +359,16 @@ var unzipTask = function unzipTask(_ref2) {
|
|
305
359
|
var progessify = function progessify(task, title) {
|
306
360
|
// return higher order function
|
307
361
|
return function (percentComplete, remaining) {
|
308
|
-
percentComplete = chalk.white(
|
309
|
-
|
310
|
-
// pluralize seconds remaining
|
311
|
-
remaining = chalk.gray(remaining + 's');
|
362
|
+
percentComplete = chalk.white(" ".concat(percentComplete, "%")); // pluralize seconds remaining
|
312
363
|
|
364
|
+
remaining = chalk.gray("".concat(remaining, "s"));
|
313
365
|
util.setTaskTitle(task, util.titleize(title, percentComplete, remaining), getRendererOptions().renderer);
|
314
366
|
};
|
315
|
-
};
|
316
|
-
|
317
|
-
// if we are running in CI then use
|
367
|
+
}; // if we are running in CI then use
|
318
368
|
// the verbose renderer else use
|
319
369
|
// the default
|
370
|
+
|
371
|
+
|
320
372
|
var getRendererOptions = function getRendererOptions() {
|
321
373
|
var renderer = util.isCi() ? verbose : 'default';
|
322
374
|
|
package/lib/tasks/state.js
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
var _ = require('lodash');
|
4
|
+
|
4
5
|
var os = require('os');
|
6
|
+
|
5
7
|
var path = require('path');
|
8
|
+
|
6
9
|
var untildify = require('untildify');
|
10
|
+
|
7
11
|
var debug = require('debug')('cypress:cli');
|
8
12
|
|
9
13
|
var fs = require('../fs');
|
14
|
+
|
10
15
|
var util = require('../util');
|
11
16
|
|
12
17
|
var getPlatformExecutable = function getPlatformExecutable() {
|
@@ -15,13 +20,16 @@ var getPlatformExecutable = function getPlatformExecutable() {
|
|
15
20
|
switch (platform) {
|
16
21
|
case 'darwin':
|
17
22
|
return 'Contents/MacOS/Cypress';
|
23
|
+
|
18
24
|
case 'linux':
|
19
25
|
return 'Cypress';
|
26
|
+
|
20
27
|
case 'win32':
|
21
28
|
return 'Cypress.exe';
|
22
29
|
// TODO handle this error using our standard
|
30
|
+
|
23
31
|
default:
|
24
|
-
throw new Error(
|
32
|
+
throw new Error("Platform: \"".concat(platform, "\" is not supported."));
|
25
33
|
}
|
26
34
|
};
|
27
35
|
|
@@ -31,13 +39,16 @@ var getPlatFormBinaryFolder = function getPlatFormBinaryFolder() {
|
|
31
39
|
switch (platform) {
|
32
40
|
case 'darwin':
|
33
41
|
return 'Cypress.app';
|
42
|
+
|
34
43
|
case 'linux':
|
35
44
|
return 'Cypress';
|
45
|
+
|
36
46
|
case 'win32':
|
37
47
|
return 'Cypress';
|
38
48
|
// TODO handle this error using our standard
|
49
|
+
|
39
50
|
default:
|
40
|
-
throw new Error(
|
51
|
+
throw new Error("Platform: \"".concat(platform, "\" is not supported."));
|
41
52
|
}
|
42
53
|
};
|
43
54
|
|
@@ -47,40 +58,42 @@ var getBinaryPkgPath = function getBinaryPkgPath(binaryDir) {
|
|
47
58
|
switch (platform) {
|
48
59
|
case 'darwin':
|
49
60
|
return path.join(binaryDir, 'Contents', 'Resources', 'app', 'package.json');
|
61
|
+
|
50
62
|
case 'linux':
|
51
63
|
return path.join(binaryDir, 'resources', 'app', 'package.json');
|
64
|
+
|
52
65
|
case 'win32':
|
53
66
|
return path.join(binaryDir, 'resources', 'app', 'package.json');
|
54
67
|
// TODO handle this error using our standard
|
68
|
+
|
55
69
|
default:
|
56
|
-
throw new Error(
|
70
|
+
throw new Error("Platform: \"".concat(platform, "\" is not supported."));
|
57
71
|
}
|
58
72
|
};
|
59
|
-
|
60
73
|
/**
|
61
74
|
* Get path to binary directory
|
62
75
|
*/
|
76
|
+
|
77
|
+
|
63
78
|
var getBinaryDir = function getBinaryDir() {
|
64
79
|
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : util.pkgVersion();
|
65
|
-
|
66
80
|
return path.join(getVersionDir(version), getPlatFormBinaryFolder());
|
67
81
|
};
|
68
82
|
|
69
83
|
var getVersionDir = function getVersionDir() {
|
70
84
|
var version = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : util.pkgVersion();
|
71
|
-
|
72
85
|
return path.join(getCacheDir(), version);
|
73
86
|
};
|
74
|
-
|
75
87
|
/**
|
76
88
|
* When executing "npm postinstall" hook, the working directory is set to
|
77
89
|
* "<current folder>/node_modules/cypress", which can be surprising when using relative paths.
|
78
90
|
*/
|
91
|
+
|
92
|
+
|
79
93
|
var isInstallingFromPostinstallHook = function isInstallingFromPostinstallHook() {
|
80
94
|
// individual folders
|
81
95
|
var cwdFolders = process.cwd().split(path.sep);
|
82
96
|
var length = cwdFolders.length;
|
83
|
-
|
84
97
|
return cwdFolders[length - 2] === 'node_modules' && cwdFolders[length - 1] === 'cypress';
|
85
98
|
};
|
86
99
|
|
@@ -89,12 +102,10 @@ var getCacheDir = function getCacheDir() {
|
|
89
102
|
|
90
103
|
if (util.getEnv('CYPRESS_CACHE_FOLDER')) {
|
91
104
|
var envVarCacheDir = untildify(util.getEnv('CYPRESS_CACHE_FOLDER'));
|
92
|
-
|
93
105
|
debug('using environment variable CYPRESS_CACHE_FOLDER %s', envVarCacheDir);
|
94
106
|
|
95
107
|
if (!path.isAbsolute(envVarCacheDir) && isInstallingFromPostinstallHook()) {
|
96
108
|
var packageRootFolder = path.join('..', '..', envVarCacheDir);
|
97
|
-
|
98
109
|
cache_directory = path.resolve(packageRootFolder);
|
99
110
|
debug('installing from postinstall hook, original root folder is %s', packageRootFolder);
|
100
111
|
debug('and resolved cache directory is %s', cache_directory);
|
@@ -109,6 +120,7 @@ var getCacheDir = function getCacheDir() {
|
|
109
120
|
var parseRealPlatformBinaryFolderAsync = function parseRealPlatformBinaryFolderAsync(binaryPath) {
|
110
121
|
return fs.realpathAsync(binaryPath).then(function (realPath) {
|
111
122
|
debug('CYPRESS_RUN_BINARY has realpath:', realPath);
|
123
|
+
|
112
124
|
if (!realPath.toString().endsWith(getPlatformExecutable())) {
|
113
125
|
return false;
|
114
126
|
}
|
@@ -124,22 +136,23 @@ var parseRealPlatformBinaryFolderAsync = function parseRealPlatformBinaryFolderA
|
|
124
136
|
var getDistDir = function getDistDir() {
|
125
137
|
return path.join(__dirname, '..', '..', 'dist');
|
126
138
|
};
|
127
|
-
|
128
139
|
/**
|
129
140
|
* Returns full filename to the file that keeps the Test Runner verification state as JSON text.
|
130
141
|
* Note: the binary state file will be stored one level up from the given binary folder.
|
131
142
|
* @param {string} binaryDir - full path to the folder holding the binary.
|
132
143
|
*/
|
144
|
+
|
145
|
+
|
133
146
|
var getBinaryStatePath = function getBinaryStatePath(binaryDir) {
|
134
147
|
return path.join(binaryDir, '..', 'binary_state.json');
|
135
148
|
};
|
136
149
|
|
137
150
|
var getBinaryStateContentsAsync = function getBinaryStateContentsAsync(binaryDir) {
|
138
151
|
var fullPath = getBinaryStatePath(binaryDir);
|
139
|
-
|
140
|
-
|
152
|
+
return fs.readJsonAsync(fullPath)["catch"]({
|
153
|
+
code: 'ENOENT'
|
154
|
+
}, SyntaxError, function () {
|
141
155
|
debug('could not read binary_state.json file at "%s"', fullPath);
|
142
|
-
|
143
156
|
return {};
|
144
157
|
});
|
145
158
|
};
|
@@ -151,16 +164,21 @@ var getBinaryVerifiedAsync = function getBinaryVerifiedAsync(binaryDir) {
|
|
151
164
|
var clearBinaryStateAsync = function clearBinaryStateAsync(binaryDir) {
|
152
165
|
return fs.removeAsync(getBinaryStatePath(binaryDir));
|
153
166
|
};
|
154
|
-
|
155
167
|
/**
|
156
168
|
* Writes the new binary status.
|
157
169
|
* @param {boolean} verified The new test runner state after smoke test
|
158
170
|
* @param {string} binaryDir Folder holding the binary
|
159
171
|
* @returns {Promise<void>} returns a promise
|
160
172
|
*/
|
173
|
+
|
174
|
+
|
161
175
|
var writeBinaryVerifiedAsync = function writeBinaryVerifiedAsync(verified, binaryDir) {
|
162
176
|
return getBinaryStateContentsAsync(binaryDir).then(function (contents) {
|
163
|
-
return fs.outputJsonAsync(getBinaryStatePath(binaryDir), _.extend(contents, {
|
177
|
+
return fs.outputJsonAsync(getBinaryStatePath(binaryDir), _.extend(contents, {
|
178
|
+
verified: verified
|
179
|
+
}), {
|
180
|
+
spaces: 2
|
181
|
+
});
|
164
182
|
});
|
165
183
|
};
|
166
184
|
|
@@ -170,9 +188,7 @@ var getPathToExecutable = function getPathToExecutable(binaryDir) {
|
|
170
188
|
|
171
189
|
var getBinaryPkgVersionAsync = function getBinaryPkgVersionAsync(binaryDir) {
|
172
190
|
var pathToPackageJson = getBinaryPkgPath(binaryDir);
|
173
|
-
|
174
191
|
debug('Reading binary package.json from:', pathToPackageJson);
|
175
|
-
|
176
192
|
return fs.pathExistsAsync(pathToPackageJson).then(function (exists) {
|
177
193
|
if (!exists) {
|
178
194
|
return null;
|