cypress 4.4.1 → 4.5.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/exec/spawn.js
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
var _ = require('lodash');
|
4
|
+
|
4
5
|
var os = require('os');
|
6
|
+
|
5
7
|
var cp = require('child_process');
|
8
|
+
|
6
9
|
var path = require('path');
|
10
|
+
|
7
11
|
var Promise = require('bluebird');
|
12
|
+
|
8
13
|
var debug = require('debug')('cypress:cli');
|
14
|
+
|
9
15
|
var debugElectron = require('debug')('cypress:electron');
|
10
16
|
|
11
17
|
var util = require('../util');
|
18
|
+
|
12
19
|
var state = require('../tasks/state');
|
20
|
+
|
13
21
|
var xvfb = require('./xvfb');
|
22
|
+
|
14
23
|
var verify = require('../tasks/verify');
|
24
|
+
|
15
25
|
var errors = require('../errors');
|
16
26
|
|
17
27
|
var isXlibOrLibudevRe = /^(?:Xlib|libudev)/;
|
18
28
|
var isHighSierraWarningRe = /\*\*\* WARNING/;
|
19
29
|
var isRenderWorkerRe = /\.RenderWorker-/;
|
20
|
-
|
21
30
|
var GARBAGE_WARNINGS = [isXlibOrLibudevRe, isHighSierraWarningRe, isRenderWorkerRe];
|
22
31
|
|
23
32
|
var isGarbageLineWarning = function isGarbageLineWarning(str) {
|
@@ -41,11 +50,11 @@ function needsEverythingPipedDirectly() {
|
|
41
50
|
function getStdio(needsXvfb) {
|
42
51
|
if (needsEverythingPipedDirectly()) {
|
43
52
|
return 'pipe';
|
44
|
-
}
|
45
|
-
|
46
|
-
// https://github.com/cypress-io/cypress/issues/921
|
53
|
+
} // https://github.com/cypress-io/cypress/issues/921
|
47
54
|
// https://github.com/cypress-io/cypress/issues/1143
|
48
55
|
// https://github.com/cypress-io/cypress/issues/1745
|
56
|
+
|
57
|
+
|
49
58
|
if (needsStderrPiped(needsXvfb)) {
|
50
59
|
// returning pipe here so we can massage stderr
|
51
60
|
// and remove garbage from Xlib and libuv
|
@@ -58,10 +67,8 @@ function getStdio(needsXvfb) {
|
|
58
67
|
|
59
68
|
module.exports = {
|
60
69
|
isGarbageLineWarning: isGarbageLineWarning,
|
61
|
-
|
62
70
|
start: function start(args) {
|
63
71
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
64
|
-
|
65
72
|
var needsXvfb = xvfb.isNeeded();
|
66
73
|
var executable = state.getPathToExecutable(state.getBinaryDir());
|
67
74
|
|
@@ -69,16 +76,14 @@ module.exports = {
|
|
69
76
|
executable = path.resolve(util.getEnv('CYPRESS_RUN_BINARY'));
|
70
77
|
}
|
71
78
|
|
72
|
-
debug('needs to start own Xvfb?', needsXvfb);
|
73
|
-
|
74
|
-
// 1. Start arguments with "--" so Electron knows these are OUR
|
79
|
+
debug('needs to start own Xvfb?', needsXvfb); // 1. Start arguments with "--" so Electron knows these are OUR
|
75
80
|
// arguments and does not try to sanitize them. Otherwise on Windows
|
76
81
|
// an url in one of the arguments crashes it :(
|
77
82
|
// https://github.com/cypress-io/cypress/issues/5466
|
78
|
-
|
79
83
|
// 2. Always push cwd into the args
|
80
84
|
// which additionally acts as a signal to the
|
81
85
|
// binary that it was invoked through the NPM module
|
86
|
+
|
82
87
|
args = ['--'].concat(args, '--cwd', process.cwd());
|
83
88
|
|
84
89
|
_.defaults(options, {
|
@@ -90,7 +95,6 @@ module.exports = {
|
|
90
95
|
|
91
96
|
var spawn = function spawn() {
|
92
97
|
var overrides = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
93
|
-
|
94
98
|
return new Promise(function (resolve, reject) {
|
95
99
|
_.defaults(overrides, {
|
96
100
|
onStderrData: false,
|
@@ -102,33 +106,35 @@ module.exports = {
|
|
102
106
|
// the launch cmd to be 'npm run dev'
|
103
107
|
executable = 'node';
|
104
108
|
args.unshift(path.resolve(__dirname, '..', '..', '..', 'scripts', 'start.js'));
|
105
|
-
|
106
109
|
debug('in dev mode the args became %o', args);
|
107
110
|
}
|
108
111
|
|
109
112
|
var onStderrData = overrides.onStderrData,
|
110
113
|
electronLogging = overrides.electronLogging;
|
111
|
-
|
112
114
|
var envOverrides = util.getEnvOverrides(options);
|
115
|
+
|
113
116
|
var electronArgs = _.clone(args);
|
117
|
+
|
114
118
|
var node11WindowsFix = isPlatform('win32');
|
115
119
|
|
116
120
|
if (!options.dev && verify.needsSandbox()) {
|
117
121
|
// this is one of the Electron's command line switches
|
118
122
|
// thus it needs to be before "--" separator
|
119
123
|
electronArgs.unshift('--no-sandbox');
|
120
|
-
}
|
124
|
+
} // strip dev out of child process options
|
121
125
|
|
122
|
-
// strip dev out of child process options
|
123
|
-
var stdioOptions = _.pick(options, 'env', 'detached', 'stdio');
|
124
126
|
|
125
|
-
// figure out if we're going to be force enabling or disabling colors.
|
127
|
+
var stdioOptions = _.pick(options, 'env', 'detached', 'stdio'); // figure out if we're going to be force enabling or disabling colors.
|
126
128
|
// also figure out whether we should force stdout and stderr into thinking
|
127
129
|
// it is a tty as opposed to a pipe.
|
130
|
+
|
131
|
+
|
128
132
|
stdioOptions.env = _.extend({}, stdioOptions.env, envOverrides);
|
129
133
|
|
130
134
|
if (node11WindowsFix) {
|
131
|
-
stdioOptions = _.extend({}, stdioOptions, {
|
135
|
+
stdioOptions = _.extend({}, stdioOptions, {
|
136
|
+
windowsHide: false
|
137
|
+
});
|
132
138
|
}
|
133
139
|
|
134
140
|
if (electronLogging) {
|
@@ -143,16 +149,18 @@ module.exports = {
|
|
143
149
|
|
144
150
|
debug('spawning Cypress with executable: %s', executable);
|
145
151
|
debug('spawn args %o %o', electronArgs, _.omit(stdioOptions, 'env'));
|
146
|
-
|
147
152
|
var child = cp.spawn(executable, electronArgs, stdioOptions);
|
148
153
|
|
149
154
|
function resolveOn(event) {
|
150
155
|
return function (code, signal) {
|
151
|
-
debug('child event fired %o', {
|
156
|
+
debug('child event fired %o', {
|
157
|
+
event: event,
|
158
|
+
code: code,
|
159
|
+
signal: signal
|
160
|
+
});
|
152
161
|
|
153
162
|
if (code === null) {
|
154
163
|
var errorObject = errors.errors.childProcessKilled(event, signal);
|
155
|
-
|
156
164
|
return errors.getError(errorObject).then(reject);
|
157
165
|
}
|
158
166
|
|
@@ -162,13 +170,12 @@ module.exports = {
|
|
162
170
|
|
163
171
|
child.on('close', resolveOn('close'));
|
164
172
|
child.on('exit', resolveOn('exit'));
|
165
|
-
child.on('error', reject);
|
166
|
-
|
167
|
-
// if stdio options is set to 'pipe', then
|
173
|
+
child.on('error', reject); // if stdio options is set to 'pipe', then
|
168
174
|
// we should set up pipes:
|
169
175
|
// process STDIN (read stream) => child STDIN (writeable)
|
170
176
|
// child STDOUT => process STDOUT
|
171
177
|
// child STDERR => process STDERR with additional filtering
|
178
|
+
|
172
179
|
if (child.stdin) {
|
173
180
|
debug('piping process STDIN into child STDIN');
|
174
181
|
process.stdin.pipe(child.stdin);
|
@@ -177,38 +184,37 @@ module.exports = {
|
|
177
184
|
if (child.stdout) {
|
178
185
|
debug('piping child STDOUT to process STDOUT');
|
179
186
|
child.stdout.pipe(process.stdout);
|
180
|
-
}
|
181
|
-
|
182
|
-
// if this is defined then we are manually piping for linux
|
187
|
+
} // if this is defined then we are manually piping for linux
|
183
188
|
// to filter out the garbage
|
189
|
+
|
190
|
+
|
184
191
|
if (child.stderr) {
|
185
192
|
debug('piping child STDERR to process STDERR');
|
186
193
|
child.stderr.on('data', function (data) {
|
187
|
-
var str = data.toString();
|
194
|
+
var str = data.toString(); // bail if this is warning line garbage
|
188
195
|
|
189
|
-
// bail if this is warning line garbage
|
190
196
|
if (isGarbageLineWarning(str)) {
|
191
197
|
return;
|
192
|
-
}
|
193
|
-
|
194
|
-
// if we have a callback and this explictly returns
|
198
|
+
} // if we have a callback and this explictly returns
|
195
199
|
// false then bail
|
200
|
+
|
201
|
+
|
196
202
|
if (onStderrData && onStderrData(str) === false) {
|
197
203
|
return;
|
198
|
-
}
|
204
|
+
} // else pass it along!
|
205
|
+
|
199
206
|
|
200
|
-
// else pass it along!
|
201
207
|
process.stderr.write(data);
|
202
208
|
});
|
203
|
-
}
|
204
|
-
|
205
|
-
// https://github.com/cypress-io/cypress/issues/1841
|
209
|
+
} // https://github.com/cypress-io/cypress/issues/1841
|
206
210
|
// https://github.com/cypress-io/cypress/issues/5241
|
207
211
|
// In some versions of node, it will throw on windows
|
208
212
|
// when you close the parent process after piping
|
209
213
|
// into the child process. unpiping does not seem
|
210
214
|
// to have any effect. so we're just catching the
|
211
215
|
// error here and not doing anything.
|
216
|
+
|
217
|
+
|
212
218
|
process.stdin.on('error', function (err) {
|
213
219
|
if (['EPIPE', 'ENOTCONN'].includes(err.code)) {
|
214
220
|
return;
|
@@ -224,14 +230,12 @@ module.exports = {
|
|
224
230
|
};
|
225
231
|
|
226
232
|
var spawnInXvfb = function spawnInXvfb() {
|
227
|
-
return xvfb.start().then(userFriendlySpawn)
|
233
|
+
return xvfb.start().then(userFriendlySpawn)["finally"](xvfb.stop);
|
228
234
|
};
|
229
235
|
|
230
236
|
var userFriendlySpawn = function userFriendlySpawn(linuxWithDisplayEnv) {
|
231
237
|
debug('spawning, should retry on display problem?', Boolean(linuxWithDisplayEnv));
|
232
|
-
|
233
|
-
var brokenGtkDisplay = void 0;
|
234
|
-
|
238
|
+
var brokenGtkDisplay;
|
235
239
|
var overrides = {};
|
236
240
|
|
237
241
|
if (linuxWithDisplayEnv) {
|
@@ -242,11 +246,11 @@ module.exports = {
|
|
242
246
|
// then we know that's why cypress exited early
|
243
247
|
if (util.isBrokenGtkDisplay(str)) {
|
244
248
|
brokenGtkDisplay = true;
|
245
|
-
}
|
246
|
-
|
247
|
-
// we should attempt to always slurp up
|
249
|
+
} // we should attempt to always slurp up
|
248
250
|
// the stderr logs unless we've explicitly
|
249
251
|
// enabled the electron debug logging
|
252
|
+
|
253
|
+
|
250
254
|
if (!debugElectron.enabled) {
|
251
255
|
return false;
|
252
256
|
}
|
@@ -257,26 +261,25 @@ module.exports = {
|
|
257
261
|
return spawn(overrides).then(function (code) {
|
258
262
|
if (code !== 0 && brokenGtkDisplay) {
|
259
263
|
util.logBrokenGtkDisplayWarning();
|
260
|
-
|
261
264
|
return spawnInXvfb();
|
262
265
|
}
|
263
266
|
|
264
267
|
return code;
|
265
|
-
})
|
266
|
-
// we can format and handle an error message from the code above
|
268
|
+
}) // we can format and handle an error message from the code above
|
267
269
|
// prevent wrapping error again by using "known: undefined" filter
|
268
|
-
|
270
|
+
["catch"]({
|
271
|
+
known: undefined
|
272
|
+
}, errors.throwFormErrorText(errors.errors.unexpected));
|
269
273
|
};
|
270
274
|
|
271
275
|
if (needsXvfb) {
|
272
276
|
return spawnInXvfb();
|
273
|
-
}
|
274
|
-
|
275
|
-
// if we are on linux and there's already a DISPLAY
|
277
|
+
} // if we are on linux and there's already a DISPLAY
|
276
278
|
// set, then we may need to rerun cypress after
|
277
279
|
// spawning our own Xvfb server
|
278
|
-
var linuxWithDisplayEnv = util.isPossibleLinuxWithIncorrectDisplay();
|
279
280
|
|
281
|
+
|
282
|
+
var linuxWithDisplayEnv = util.isPossibleLinuxWithIncorrectDisplay();
|
280
283
|
return userFriendlySpawn(linuxWithDisplayEnv);
|
281
284
|
}
|
282
285
|
};
|
package/lib/exec/versions.js
CHANGED
@@ -1,10 +1,13 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
var Promise = require('bluebird');
|
4
|
+
|
4
5
|
var debug = require('debug')('cypress:cli');
|
6
|
+
|
5
7
|
var path = require('path');
|
6
8
|
|
7
9
|
var util = require('../util');
|
10
|
+
|
8
11
|
var state = require('../tasks/state');
|
9
12
|
|
10
13
|
var _require = require('../errors'),
|
@@ -12,19 +15,19 @@ var _require = require('../errors'),
|
|
12
15
|
errors = _require.errors;
|
13
16
|
|
14
17
|
var getVersions = function getVersions() {
|
15
|
-
return Promise
|
18
|
+
return Promise["try"](function () {
|
16
19
|
if (util.getEnv('CYPRESS_RUN_BINARY')) {
|
17
20
|
var envBinaryPath = path.resolve(util.getEnv('CYPRESS_RUN_BINARY'));
|
18
|
-
|
19
21
|
return state.parseRealPlatformBinaryFolderAsync(envBinaryPath).then(function (envBinaryDir) {
|
20
22
|
if (!envBinaryDir) {
|
21
23
|
return throwFormErrorText(errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))();
|
22
24
|
}
|
23
25
|
|
24
26
|
debug('CYPRESS_RUN_BINARY has binaryDir:', envBinaryDir);
|
25
|
-
|
26
27
|
return envBinaryDir;
|
27
|
-
})
|
28
|
+
})["catch"]({
|
29
|
+
code: 'ENOENT'
|
30
|
+
}, function (err) {
|
28
31
|
return throwFormErrorText(errors.CYPRESS_RUN_BINARY.notValid(envBinaryPath))(err.message);
|
29
32
|
});
|
30
33
|
}
|
@@ -32,7 +35,7 @@ var getVersions = function getVersions() {
|
|
32
35
|
return state.getBinaryDir();
|
33
36
|
}).then(state.getBinaryPkgVersionAsync).then(function (binaryVersion) {
|
34
37
|
return {
|
35
|
-
package: util.pkgVersion(),
|
38
|
+
"package": util.pkgVersion(),
|
36
39
|
binary: binaryVersion || 'not installed'
|
37
40
|
};
|
38
41
|
});
|
package/lib/exec/xvfb.js
CHANGED
@@ -1,17 +1,28 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
|
3
|
+
function _templateObject() {
|
4
|
+
var data = _taggedTemplateLiteral(["\n DISPLAY environment variable is set to ", " on Linux\n Assuming this DISPLAY points at working X11 server,\n Cypress will not spawn own Xvfb\n\n NOTE: if the X11 server is NOT working, Cypress will exit without explanation,\n see ", "\n Solution: Unset the DISPLAY variable and try again:\n DISPLAY= npx cypress run ...\n "]);
|
4
5
|
|
5
|
-
function
|
6
|
+
_templateObject = function _templateObject() {
|
7
|
+
return data;
|
8
|
+
};
|
9
|
+
|
10
|
+
return data;
|
11
|
+
}
|
12
|
+
|
13
|
+
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
6
14
|
|
7
15
|
var os = require('os');
|
16
|
+
|
8
17
|
var Promise = require('bluebird');
|
18
|
+
|
9
19
|
var Xvfb = require('@cypress/xvfb');
|
10
20
|
|
11
21
|
var _require = require('common-tags'),
|
12
22
|
stripIndent = _require.stripIndent;
|
13
23
|
|
14
24
|
var debug = require('debug')('cypress:cli');
|
25
|
+
|
15
26
|
var debugXvfb = require('debug')('cypress:xvfb');
|
16
27
|
|
17
28
|
var _require2 = require('../errors'),
|
@@ -21,7 +32,8 @@ var _require2 = require('../errors'),
|
|
21
32
|
var util = require('../util');
|
22
33
|
|
23
34
|
var xvfbOptions = {
|
24
|
-
timeout: 30000,
|
35
|
+
timeout: 30000,
|
36
|
+
// milliseconds
|
25
37
|
// need to explicitly define screen otherwise electron will crash
|
26
38
|
// https://github.com/cypress-io/cypress/issues/6184
|
27
39
|
xvfb_args: ['-screen', '0', '1280x1024x24'],
|
@@ -31,20 +43,19 @@ var xvfbOptions = {
|
|
31
43
|
}
|
32
44
|
}
|
33
45
|
};
|
34
|
-
|
35
46
|
var xvfb = Promise.promisifyAll(new Xvfb(xvfbOptions));
|
36
|
-
|
37
47
|
module.exports = {
|
38
|
-
_debugXvfb: debugXvfb,
|
39
|
-
|
40
|
-
_xvfb: xvfb,
|
41
|
-
|
42
|
-
_xvfbOptions: xvfbOptions,
|
43
|
-
|
48
|
+
_debugXvfb: debugXvfb,
|
49
|
+
// expose for testing
|
50
|
+
_xvfb: xvfb,
|
51
|
+
// expose for testing
|
52
|
+
_xvfbOptions: xvfbOptions,
|
53
|
+
// expose for testing
|
44
54
|
start: function start() {
|
45
55
|
debug('Starting Xvfb');
|
46
|
-
|
47
|
-
|
56
|
+
return xvfb.startAsync()["return"](null)["catch"]({
|
57
|
+
nonZeroExitCode: true
|
58
|
+
}, throwFormErrorText(errors.nonZeroExitCodeXvfb))["catch"](function (err) {
|
48
59
|
if (err.known) {
|
49
60
|
throw err;
|
50
61
|
}
|
@@ -54,9 +65,7 @@ module.exports = {
|
|
54
65
|
},
|
55
66
|
stop: function stop() {
|
56
67
|
debug('Stopping Xvfb');
|
57
|
-
|
58
|
-
return xvfb.stopAsync().return(null).catch(function () {
|
59
|
-
// noop
|
68
|
+
return xvfb.stopAsync()["return"](null)["catch"](function () {// noop
|
60
69
|
});
|
61
70
|
},
|
62
71
|
isNeeded: function isNeeded() {
|
@@ -66,27 +75,20 @@ module.exports = {
|
|
66
75
|
|
67
76
|
if (process.env.DISPLAY) {
|
68
77
|
var issueUrl = util.getGitHubIssueUrl(4034);
|
69
|
-
|
70
|
-
var message = stripIndent(_templateObject, process.env.DISPLAY, issueUrl);
|
71
|
-
|
78
|
+
var message = stripIndent(_templateObject(), process.env.DISPLAY, issueUrl);
|
72
79
|
debug(message);
|
73
|
-
|
74
80
|
return false;
|
75
81
|
}
|
76
82
|
|
77
83
|
debug('undefined DISPLAY environment variable');
|
78
84
|
debug('Cypress will spawn its own Xvfb');
|
79
|
-
|
80
85
|
return true;
|
81
86
|
},
|
82
|
-
|
83
|
-
|
84
87
|
// async method, resolved with Boolean
|
85
88
|
verify: function verify() {
|
86
|
-
return xvfb.startAsync()
|
89
|
+
return xvfb.startAsync()["return"](true)["catch"](function (err) {
|
87
90
|
debug('Could not verify xvfb: %s', err.message);
|
88
|
-
|
89
91
|
return false;
|
90
|
-
})
|
92
|
+
})["finally"](xvfb.stopAsync);
|
91
93
|
}
|
92
94
|
};
|
package/lib/fs.js
CHANGED
package/lib/logger.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
var R = require('ramda');
|
4
|
+
|
4
5
|
var chalk = require('chalk');
|
5
6
|
|
6
7
|
var logs = [];
|
@@ -10,7 +11,7 @@ var logLevel = function logLevel() {
|
|
10
11
|
};
|
11
12
|
|
12
13
|
var error = function error() {
|
13
|
-
for (var _len = arguments.length, messages = Array(_len), _key = 0; _key < _len; _key++) {
|
14
|
+
for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
|
14
15
|
messages[_key] = arguments[_key];
|
15
16
|
}
|
16
17
|
|
@@ -19,12 +20,12 @@ var error = function error() {
|
|
19
20
|
};
|
20
21
|
|
21
22
|
var warn = function warn() {
|
22
|
-
|
23
|
+
if (logLevel() === 'silent') return;
|
24
|
+
|
25
|
+
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
23
26
|
messages[_key2] = arguments[_key2];
|
24
27
|
}
|
25
28
|
|
26
|
-
if (logLevel() === 'silent') return;
|
27
|
-
|
28
29
|
logs.push(messages.join(' '));
|
29
30
|
console.log(chalk.yellow.apply(chalk, messages)); // eslint-disable-line no-console
|
30
31
|
};
|
@@ -32,32 +33,35 @@ var warn = function warn() {
|
|
32
33
|
var log = function log() {
|
33
34
|
var _console;
|
34
35
|
|
35
|
-
|
36
|
+
if (logLevel() === 'silent' || logLevel() === 'warn') return;
|
37
|
+
|
38
|
+
for (var _len3 = arguments.length, messages = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
36
39
|
messages[_key3] = arguments[_key3];
|
37
40
|
}
|
38
41
|
|
39
|
-
if (logLevel() === 'silent' || logLevel() === 'warn') return;
|
40
|
-
|
41
42
|
logs.push(messages.join(' '));
|
43
|
+
|
42
44
|
(_console = console).log.apply(_console, messages); // eslint-disable-line no-console
|
45
|
+
|
43
46
|
};
|
44
47
|
|
45
48
|
var always = function always() {
|
46
49
|
var _console2;
|
47
50
|
|
48
|
-
for (var _len4 = arguments.length, messages = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
51
|
+
for (var _len4 = arguments.length, messages = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
49
52
|
messages[_key4] = arguments[_key4];
|
50
53
|
}
|
51
54
|
|
52
55
|
logs.push(messages.join(' '));
|
56
|
+
|
53
57
|
(_console2 = console).log.apply(_console2, messages); // eslint-disable-line no-console
|
54
|
-
};
|
55
58
|
|
56
|
-
// splits long text into lines and calls log()
|
59
|
+
}; // splits long text into lines and calls log()
|
57
60
|
// on each one to allow easy unit testing for specific message
|
61
|
+
|
62
|
+
|
58
63
|
var logLines = function logLines(text) {
|
59
64
|
var lines = text.split('\n');
|
60
|
-
|
61
65
|
R.forEach(log, lines);
|
62
66
|
};
|
63
67
|
|
package/lib/tasks/cache.js
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
var state = require('./state');
|
4
|
+
|
4
5
|
var logger = require('../logger');
|
6
|
+
|
5
7
|
var fs = require('../fs');
|
8
|
+
|
6
9
|
var util = require('../util');
|
7
10
|
|
8
11
|
var _require = require('path'),
|
9
12
|
join = _require.join;
|
10
13
|
|
11
14
|
var Table = require('cli-table3');
|
15
|
+
|
12
16
|
var moment = require('moment');
|
17
|
+
|
13
18
|
var chalk = require('chalk');
|
14
|
-
var _ = require('lodash');
|
15
19
|
|
16
|
-
// output colors for the table
|
20
|
+
var _ = require('lodash'); // output colors for the table
|
21
|
+
|
22
|
+
|
17
23
|
var colors = {
|
18
24
|
titles: chalk.white,
|
19
25
|
dates: chalk.cyan,
|
@@ -22,38 +28,34 @@ var colors = {
|
|
22
28
|
|
23
29
|
var logCachePath = function logCachePath() {
|
24
30
|
logger.always(state.getCacheDir());
|
25
|
-
|
26
31
|
return undefined;
|
27
32
|
};
|
28
33
|
|
29
34
|
var clear = function clear() {
|
30
35
|
return fs.removeAsync(state.getCacheDir());
|
31
36
|
};
|
32
|
-
|
33
37
|
/**
|
34
38
|
* Collects all cached versions, finds when each was used
|
35
39
|
* and prints a table with results to the terminal
|
36
40
|
*/
|
41
|
+
|
42
|
+
|
37
43
|
var list = function list() {
|
38
44
|
return getCachedVersions().then(function (binaries) {
|
39
45
|
var table = new Table({
|
40
46
|
head: [colors.titles('version'), colors.titles('last used')]
|
41
47
|
});
|
42
|
-
|
43
48
|
binaries.forEach(function (binary) {
|
44
49
|
var versionString = colors.values(binary.version);
|
45
50
|
var lastUsed = binary.accessed ? colors.dates(binary.accessed) : 'unknown';
|
46
|
-
|
47
51
|
return table.push([versionString, lastUsed]);
|
48
52
|
});
|
49
|
-
|
50
53
|
logger.always(table.toString());
|
51
54
|
});
|
52
55
|
};
|
53
56
|
|
54
57
|
var getCachedVersions = function getCachedVersions() {
|
55
58
|
var cacheDir = state.getCacheDir();
|
56
|
-
|
57
59
|
return fs.readdirAsync(cacheDir).filter(util.isSemver).map(function (version) {
|
58
60
|
return {
|
59
61
|
version: version,
|
@@ -64,7 +66,6 @@ var getCachedVersions = function getCachedVersions() {
|
|
64
66
|
// on the Cypress binary
|
65
67
|
var binaryDir = state.getBinaryDir(binary.version);
|
66
68
|
var executable = state.getPathToExecutable(binaryDir);
|
67
|
-
|
68
69
|
return fs.statAsync(executable).then(function (stat) {
|
69
70
|
var lastAccessedTime = _.get(stat, 'atime');
|
70
71
|
|
@@ -75,9 +76,7 @@ var getCachedVersions = function getCachedVersions() {
|
|
75
76
|
}
|
76
77
|
|
77
78
|
var accessed = moment(lastAccessedTime).fromNow();
|
78
|
-
|
79
79
|
binary.accessed = accessed;
|
80
|
-
|
81
80
|
return binary;
|
82
81
|
}, function (e) {
|
83
82
|
// could not find the binary or gets its stats
|