cypress 5.2.0 → 5.6.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 +6 -6
- package/lib/cli.js +119 -107
- package/lib/cypress.js +21 -21
- package/lib/errors.js +233 -276
- package/lib/exec/info.js +29 -32
- package/lib/exec/open.js +7 -8
- package/lib/exec/run.js +20 -20
- package/lib/exec/spawn.js +53 -49
- package/lib/exec/versions.js +18 -17
- package/lib/exec/xvfb.js +43 -37
- package/lib/fs.js +1 -1
- package/lib/logger.js +24 -50
- package/lib/tasks/cache.js +96 -36
- package/lib/tasks/download.js +113 -133
- package/lib/tasks/get-folder-size.js +41 -0
- package/lib/tasks/install.js +165 -249
- package/lib/tasks/state.js +54 -56
- package/lib/tasks/unzip.js +72 -69
- package/lib/tasks/verify.js +112 -147
- package/lib/util.js +172 -176
- package/package.json +4 -4
- package/types/cypress-npm-api.d.ts +13 -5
- package/types/cypress.d.ts +15 -15
- package/types/mocha/index.d.ts +123 -308
- package/types/net-stubbing.ts +132 -21
package/lib/fs.js
CHANGED
package/lib/logger.js
CHANGED
@@ -1,85 +1,59 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
|
3
|
+
const R = require('ramda');
|
4
4
|
|
5
|
-
|
5
|
+
const chalk = require('chalk');
|
6
6
|
|
7
|
-
|
7
|
+
let logs = [];
|
8
8
|
|
9
|
-
|
9
|
+
const logLevel = () => {
|
10
10
|
return process.env.npm_config_loglevel || 'notice';
|
11
11
|
};
|
12
12
|
|
13
|
-
|
14
|
-
for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
|
15
|
-
messages[_key] = arguments[_key];
|
16
|
-
}
|
17
|
-
|
13
|
+
const error = (...messages) => {
|
18
14
|
logs.push(messages.join(' '));
|
19
|
-
console.log(chalk.red
|
15
|
+
console.log(chalk.red(...messages)); // eslint-disable-line no-console
|
20
16
|
};
|
21
17
|
|
22
|
-
|
18
|
+
const warn = (...messages) => {
|
23
19
|
if (logLevel() === 'silent') return;
|
24
|
-
|
25
|
-
for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
26
|
-
messages[_key2] = arguments[_key2];
|
27
|
-
}
|
28
|
-
|
29
20
|
logs.push(messages.join(' '));
|
30
|
-
console.log(chalk.yellow
|
21
|
+
console.log(chalk.yellow(...messages)); // eslint-disable-line no-console
|
31
22
|
};
|
32
23
|
|
33
|
-
|
34
|
-
var _console;
|
35
|
-
|
24
|
+
const log = (...messages) => {
|
36
25
|
if (logLevel() === 'silent' || logLevel() === 'warn') return;
|
37
|
-
|
38
|
-
for (var _len3 = arguments.length, messages = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
39
|
-
messages[_key3] = arguments[_key3];
|
40
|
-
}
|
41
|
-
|
42
26
|
logs.push(messages.join(' '));
|
43
|
-
|
44
|
-
(_console = console).log.apply(_console, messages); // eslint-disable-line no-console
|
45
|
-
|
27
|
+
console.log(...messages); // eslint-disable-line no-console
|
46
28
|
};
|
47
29
|
|
48
|
-
|
49
|
-
var _console2;
|
50
|
-
|
51
|
-
for (var _len4 = arguments.length, messages = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
52
|
-
messages[_key4] = arguments[_key4];
|
53
|
-
}
|
54
|
-
|
30
|
+
const always = (...messages) => {
|
55
31
|
logs.push(messages.join(' '));
|
56
|
-
|
57
|
-
(_console2 = console).log.apply(_console2, messages); // eslint-disable-line no-console
|
58
|
-
|
32
|
+
console.log(...messages); // eslint-disable-line no-console
|
59
33
|
}; // splits long text into lines and calls log()
|
60
34
|
// on each one to allow easy unit testing for specific message
|
61
35
|
|
62
36
|
|
63
|
-
|
64
|
-
|
37
|
+
const logLines = text => {
|
38
|
+
const lines = text.split('\n');
|
65
39
|
R.forEach(log, lines);
|
66
40
|
};
|
67
41
|
|
68
|
-
|
42
|
+
const print = () => {
|
69
43
|
return logs.join('\n');
|
70
44
|
};
|
71
45
|
|
72
|
-
|
46
|
+
const reset = () => {
|
73
47
|
logs = [];
|
74
48
|
};
|
75
49
|
|
76
50
|
module.exports = {
|
77
|
-
log
|
78
|
-
warn
|
79
|
-
error
|
80
|
-
always
|
81
|
-
logLines
|
82
|
-
print
|
83
|
-
reset
|
84
|
-
logLevel
|
51
|
+
log,
|
52
|
+
warn,
|
53
|
+
error,
|
54
|
+
always,
|
55
|
+
logLines,
|
56
|
+
print,
|
57
|
+
reset,
|
58
|
+
logLevel
|
85
59
|
};
|
package/lib/tasks/cache.js
CHANGED
@@ -1,73 +1,121 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
|
3
|
+
const state = require('./state');
|
4
4
|
|
5
|
-
|
5
|
+
const logger = require('../logger');
|
6
6
|
|
7
|
-
|
7
|
+
const fs = require('../fs');
|
8
8
|
|
9
|
-
|
9
|
+
const util = require('../util');
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
const {
|
12
|
+
join
|
13
|
+
} = require('path');
|
13
14
|
|
14
|
-
|
15
|
+
const Table = require('cli-table3');
|
15
16
|
|
16
|
-
|
17
|
+
const moment = require('moment');
|
17
18
|
|
18
|
-
|
19
|
+
const chalk = require('chalk');
|
19
20
|
|
20
|
-
|
21
|
+
const _ = require('lodash');
|
21
22
|
|
23
|
+
const getFolderSize = require('./get-folder-size');
|
22
24
|
|
23
|
-
|
25
|
+
const Bluebird = require('bluebird'); // output colors for the table
|
26
|
+
|
27
|
+
|
28
|
+
const colors = {
|
24
29
|
titles: chalk.white,
|
25
30
|
dates: chalk.cyan,
|
26
|
-
values: chalk.green
|
31
|
+
values: chalk.green,
|
32
|
+
size: chalk.gray
|
27
33
|
};
|
28
34
|
|
29
|
-
|
35
|
+
const logCachePath = () => {
|
30
36
|
logger.always(state.getCacheDir());
|
31
37
|
return undefined;
|
32
38
|
};
|
33
39
|
|
34
|
-
|
40
|
+
const clear = () => {
|
35
41
|
return fs.removeAsync(state.getCacheDir());
|
36
42
|
};
|
43
|
+
|
44
|
+
const prune = () => {
|
45
|
+
const cacheDir = state.getCacheDir();
|
46
|
+
const currentVersion = util.pkgVersion();
|
47
|
+
let deletedBinary = false;
|
48
|
+
return fs.readdirAsync(cacheDir).then(versions => {
|
49
|
+
return Bluebird.all(versions.map(version => {
|
50
|
+
if (version !== currentVersion) {
|
51
|
+
deletedBinary = true;
|
52
|
+
const versionDir = join(cacheDir, version);
|
53
|
+
return fs.removeAsync(versionDir);
|
54
|
+
}
|
55
|
+
}));
|
56
|
+
}).then(() => {
|
57
|
+
if (deletedBinary) {
|
58
|
+
logger.always(`Deleted all binary caches except for the ${currentVersion} binary cache.`);
|
59
|
+
} else {
|
60
|
+
logger.always(`No binary caches found to prune.`);
|
61
|
+
}
|
62
|
+
}).catch({
|
63
|
+
code: 'ENOENT'
|
64
|
+
}, () => {
|
65
|
+
logger.always(`No Cypress cache was found at ${cacheDir}. Nothing to prune.`);
|
66
|
+
});
|
67
|
+
};
|
68
|
+
|
69
|
+
const fileSizeInMB = size => {
|
70
|
+
return `${(size / 1024 / 1024).toFixed(1)}MB`;
|
71
|
+
};
|
37
72
|
/**
|
38
73
|
* Collects all cached versions, finds when each was used
|
39
74
|
* and prints a table with results to the terminal
|
40
75
|
*/
|
41
76
|
|
42
77
|
|
43
|
-
|
44
|
-
return getCachedVersions().then(
|
45
|
-
|
46
|
-
|
78
|
+
const list = showSize => {
|
79
|
+
return getCachedVersions(showSize).then(binaries => {
|
80
|
+
const head = [colors.titles('version'), colors.titles('last used')];
|
81
|
+
|
82
|
+
if (showSize) {
|
83
|
+
head.push(colors.titles('size'));
|
84
|
+
}
|
85
|
+
|
86
|
+
const table = new Table({
|
87
|
+
head
|
47
88
|
});
|
48
|
-
binaries.forEach(
|
49
|
-
|
50
|
-
|
51
|
-
|
89
|
+
binaries.forEach(binary => {
|
90
|
+
const versionString = colors.values(binary.version);
|
91
|
+
const lastUsed = binary.accessed ? colors.dates(binary.accessed) : 'unknown';
|
92
|
+
const row = [versionString, lastUsed];
|
93
|
+
|
94
|
+
if (showSize) {
|
95
|
+
const size = colors.size(fileSizeInMB(binary.size));
|
96
|
+
row.push(size);
|
97
|
+
}
|
98
|
+
|
99
|
+
return table.push(row);
|
52
100
|
});
|
53
101
|
logger.always(table.toString());
|
54
102
|
});
|
55
103
|
};
|
56
104
|
|
57
|
-
|
58
|
-
|
59
|
-
return fs.readdirAsync(cacheDir).filter(util.isSemver).map(
|
105
|
+
const getCachedVersions = showSize => {
|
106
|
+
const cacheDir = state.getCacheDir();
|
107
|
+
return fs.readdirAsync(cacheDir).filter(util.isSemver).map(version => {
|
60
108
|
return {
|
61
|
-
version
|
109
|
+
version,
|
62
110
|
folderPath: join(cacheDir, version)
|
63
111
|
};
|
64
|
-
}).mapSeries(
|
112
|
+
}).mapSeries(binary => {
|
65
113
|
// last access time on the folder is different from last access time
|
66
114
|
// on the Cypress binary
|
67
|
-
|
68
|
-
|
69
|
-
return fs.statAsync(executable).then(
|
70
|
-
|
115
|
+
const binaryDir = state.getBinaryDir(binary.version);
|
116
|
+
const executable = state.getPathToExecutable(binaryDir);
|
117
|
+
return fs.statAsync(executable).then(stat => {
|
118
|
+
const lastAccessedTime = _.get(stat, 'atime');
|
71
119
|
|
72
120
|
if (!lastAccessedTime) {
|
73
121
|
// the test runner has never been opened
|
@@ -75,19 +123,31 @@ var getCachedVersions = function getCachedVersions() {
|
|
75
123
|
return binary;
|
76
124
|
}
|
77
125
|
|
78
|
-
|
126
|
+
const accessed = moment(lastAccessedTime).fromNow();
|
79
127
|
binary.accessed = accessed;
|
80
128
|
return binary;
|
81
|
-
},
|
129
|
+
}, e => {
|
82
130
|
// could not find the binary or gets its stats
|
83
131
|
return binary;
|
84
132
|
});
|
133
|
+
}).mapSeries(binary => {
|
134
|
+
if (showSize) {
|
135
|
+
const binaryDir = state.getBinaryDir(binary.version);
|
136
|
+
return getFolderSize(binaryDir).then(size => {
|
137
|
+
return { ...binary,
|
138
|
+
size
|
139
|
+
};
|
140
|
+
});
|
141
|
+
}
|
142
|
+
|
143
|
+
return binary;
|
85
144
|
});
|
86
145
|
};
|
87
146
|
|
88
147
|
module.exports = {
|
89
148
|
path: logCachePath,
|
90
|
-
clear
|
91
|
-
|
92
|
-
|
149
|
+
clear,
|
150
|
+
prune,
|
151
|
+
list,
|
152
|
+
getCachedVersions
|
93
153
|
};
|