cypress 5.2.0 → 5.6.0

Sign up to get free protection for your applications and to get access to all the features.
package/lib/fs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
 
3
- var Promise = require('bluebird');
3
+ const Promise = require('bluebird');
4
4
 
5
5
  module.exports = Promise.promisifyAll(require('fs-extra'));
package/lib/logger.js CHANGED
@@ -1,85 +1,59 @@
1
1
  "use strict";
2
2
 
3
- var R = require('ramda');
3
+ const R = require('ramda');
4
4
 
5
- var chalk = require('chalk');
5
+ const chalk = require('chalk');
6
6
 
7
- var logs = [];
7
+ let logs = [];
8
8
 
9
- var logLevel = function logLevel() {
9
+ const logLevel = () => {
10
10
  return process.env.npm_config_loglevel || 'notice';
11
11
  };
12
12
 
13
- var error = function error() {
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.apply(chalk, messages)); // eslint-disable-line no-console
15
+ console.log(chalk.red(...messages)); // eslint-disable-line no-console
20
16
  };
21
17
 
22
- var warn = function warn() {
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.apply(chalk, messages)); // eslint-disable-line no-console
21
+ console.log(chalk.yellow(...messages)); // eslint-disable-line no-console
31
22
  };
32
23
 
33
- var log = function log() {
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
- var always = function always() {
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
- var logLines = function logLines(text) {
64
- var lines = text.split('\n');
37
+ const logLines = text => {
38
+ const lines = text.split('\n');
65
39
  R.forEach(log, lines);
66
40
  };
67
41
 
68
- var print = function print() {
42
+ const print = () => {
69
43
  return logs.join('\n');
70
44
  };
71
45
 
72
- var reset = function reset() {
46
+ const reset = () => {
73
47
  logs = [];
74
48
  };
75
49
 
76
50
  module.exports = {
77
- log: log,
78
- warn: warn,
79
- error: error,
80
- always: always,
81
- logLines: logLines,
82
- print: print,
83
- reset: reset,
84
- logLevel: logLevel
51
+ log,
52
+ warn,
53
+ error,
54
+ always,
55
+ logLines,
56
+ print,
57
+ reset,
58
+ logLevel
85
59
  };
@@ -1,73 +1,121 @@
1
1
  "use strict";
2
2
 
3
- var state = require('./state');
3
+ const state = require('./state');
4
4
 
5
- var logger = require('../logger');
5
+ const logger = require('../logger');
6
6
 
7
- var fs = require('../fs');
7
+ const fs = require('../fs');
8
8
 
9
- var util = require('../util');
9
+ const util = require('../util');
10
10
 
11
- var _require = require('path'),
12
- join = _require.join;
11
+ const {
12
+ join
13
+ } = require('path');
13
14
 
14
- var Table = require('cli-table3');
15
+ const Table = require('cli-table3');
15
16
 
16
- var moment = require('moment');
17
+ const moment = require('moment');
17
18
 
18
- var chalk = require('chalk');
19
+ const chalk = require('chalk');
19
20
 
20
- var _ = require('lodash'); // output colors for the table
21
+ const _ = require('lodash');
21
22
 
23
+ const getFolderSize = require('./get-folder-size');
22
24
 
23
- var colors = {
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
- var logCachePath = function logCachePath() {
35
+ const logCachePath = () => {
30
36
  logger.always(state.getCacheDir());
31
37
  return undefined;
32
38
  };
33
39
 
34
- var clear = function clear() {
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
- var list = function list() {
44
- return getCachedVersions().then(function (binaries) {
45
- var table = new Table({
46
- head: [colors.titles('version'), colors.titles('last used')]
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(function (binary) {
49
- var versionString = colors.values(binary.version);
50
- var lastUsed = binary.accessed ? colors.dates(binary.accessed) : 'unknown';
51
- return table.push([versionString, lastUsed]);
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
- var getCachedVersions = function getCachedVersions() {
58
- var cacheDir = state.getCacheDir();
59
- return fs.readdirAsync(cacheDir).filter(util.isSemver).map(function (version) {
105
+ const getCachedVersions = showSize => {
106
+ const cacheDir = state.getCacheDir();
107
+ return fs.readdirAsync(cacheDir).filter(util.isSemver).map(version => {
60
108
  return {
61
- version: version,
109
+ version,
62
110
  folderPath: join(cacheDir, version)
63
111
  };
64
- }).mapSeries(function (binary) {
112
+ }).mapSeries(binary => {
65
113
  // last access time on the folder is different from last access time
66
114
  // on the Cypress binary
67
- var binaryDir = state.getBinaryDir(binary.version);
68
- var executable = state.getPathToExecutable(binaryDir);
69
- return fs.statAsync(executable).then(function (stat) {
70
- var lastAccessedTime = _.get(stat, 'atime');
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
- var accessed = moment(lastAccessedTime).fromNow();
126
+ const accessed = moment(lastAccessedTime).fromNow();
79
127
  binary.accessed = accessed;
80
128
  return binary;
81
- }, function (e) {
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: clear,
91
- list: list,
92
- getCachedVersions: getCachedVersions
149
+ clear,
150
+ prune,
151
+ list,
152
+ getCachedVersions
93
153
  };