escover 6.2.0 → 6.2.1
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/ChangeLog +5 -0
- package/lib/cli/cli.js +1 -1
- package/lib/formatters/responsive.js +129 -95
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/cli/cli.js
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
|
|
8
8
|
const CWD = process.cwd();
|
|
9
|
-
|
|
10
9
|
const {entries, keys} = Object;
|
|
11
10
|
|
|
12
11
|
const makeGreen = chalk.hex('#4caf50');
|
|
@@ -19,33 +18,55 @@ export default (coverageFile, {skipFull = false} = {}) => {
|
|
|
19
18
|
return '💪 coverage 100% Good Job!\n';
|
|
20
19
|
|
|
21
20
|
const totalWidth = process.stdout.columns || 80;
|
|
22
|
-
const showPercent = totalWidth >= 70;
|
|
23
21
|
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
let showPercent = false;
|
|
23
|
+
|
|
24
|
+
if (totalWidth >= 70)
|
|
25
|
+
showPercent = true;
|
|
26
26
|
|
|
27
|
+
let percentColWidth = 0;
|
|
28
|
+
|
|
29
|
+
if (showPercent)
|
|
30
|
+
percentColWidth = 8;
|
|
31
|
+
|
|
32
|
+
const fileColWidth = Math.floor(totalWidth * 0.45);
|
|
27
33
|
const linesColWidth = totalWidth - fileColWidth - percentColWidth - 6;
|
|
28
34
|
|
|
29
35
|
const tableData = buildGroupedTable(files, showPercent);
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const columns = [{
|
|
38
|
+
paddingLeft: 1,
|
|
39
|
+
paddingRight: 1,
|
|
40
|
+
width: fileColWidth,
|
|
41
|
+
wrapWord: false,
|
|
42
|
+
}];
|
|
43
|
+
|
|
44
|
+
if (showPercent)
|
|
45
|
+
columns.push({
|
|
40
46
|
alignment: 'center',
|
|
41
47
|
paddingLeft: 1,
|
|
42
48
|
paddingRight: 0,
|
|
43
49
|
width: percentColWidth,
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
columns.push({
|
|
53
|
+
paddingLeft: 1,
|
|
54
|
+
paddingRight: 0,
|
|
55
|
+
width: linesColWidth,
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const options = {
|
|
59
|
+
drawHorizontalLine: (raw) => {
|
|
60
|
+
if (!raw)
|
|
61
|
+
return true;
|
|
62
|
+
|
|
63
|
+
if (raw === 1)
|
|
64
|
+
return true;
|
|
65
|
+
|
|
66
|
+
return raw === tableData.length;
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
columns,
|
|
49
70
|
|
|
50
71
|
border: {
|
|
51
72
|
...getBorderCharacters('void'),
|
|
@@ -57,29 +78,34 @@ export default (coverageFile, {skipFull = false} = {}) => {
|
|
|
57
78
|
joinJoin: '|',
|
|
58
79
|
bodyJoin: '|',
|
|
59
80
|
},
|
|
60
|
-
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
return table(tableData, options);
|
|
61
84
|
};
|
|
62
85
|
|
|
63
|
-
/* =========================
|
|
64
|
-
GROUPING + COVERAGE
|
|
65
|
-
========================= */
|
|
66
86
|
function groupByFolder(files) {
|
|
67
87
|
const groups = new Map();
|
|
68
88
|
|
|
69
89
|
for (const f of files) {
|
|
70
90
|
const parts = f.filename.split('/');
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
91
|
+
|
|
92
|
+
let folder = '';
|
|
93
|
+
|
|
94
|
+
if (parts.length > 1)
|
|
95
|
+
folder = parts
|
|
96
|
+
.slice(0, -1)
|
|
97
|
+
.join('/');
|
|
74
98
|
|
|
75
99
|
const fileName = parts.at(-1);
|
|
76
100
|
|
|
77
|
-
|
|
78
|
-
groups.set(folder, {
|
|
79
|
-
files: [],
|
|
80
|
-
});
|
|
101
|
+
let group = groups.get(folder);
|
|
81
102
|
|
|
82
|
-
|
|
103
|
+
if (!group) {
|
|
104
|
+
group = {
|
|
105
|
+
files: [],
|
|
106
|
+
};
|
|
107
|
+
groups.set(folder, group);
|
|
108
|
+
}
|
|
83
109
|
|
|
84
110
|
group.files.push({
|
|
85
111
|
...f,
|
|
@@ -90,55 +116,81 @@ function groupByFolder(files) {
|
|
|
90
116
|
return groups;
|
|
91
117
|
}
|
|
92
118
|
|
|
93
|
-
/* =========================
|
|
94
|
-
TABLE BUILDER
|
|
95
|
-
========================= */
|
|
96
119
|
function buildGroupedTable(files, showPercent) {
|
|
97
|
-
const tableData = [
|
|
98
|
-
|
|
120
|
+
const tableData = [];
|
|
121
|
+
|
|
122
|
+
if (showPercent)
|
|
123
|
+
tableData.push([
|
|
99
124
|
'File',
|
|
100
125
|
'% Lines',
|
|
101
126
|
'Uncovered Lines #s',
|
|
102
|
-
]
|
|
127
|
+
]);
|
|
128
|
+
else
|
|
129
|
+
tableData.push([
|
|
103
130
|
'File',
|
|
104
131
|
'Uncovered Lines #s',
|
|
105
|
-
]
|
|
106
|
-
];
|
|
132
|
+
]);
|
|
107
133
|
|
|
108
134
|
const groups = groupByFolder(files);
|
|
109
135
|
|
|
110
136
|
for (const [folder, group] of groups) {
|
|
111
|
-
|
|
137
|
+
let sum = 0;
|
|
138
|
+
|
|
139
|
+
for (const f of group.files)
|
|
140
|
+
sum += f.percentLines;
|
|
141
|
+
|
|
142
|
+
let coverage = 100;
|
|
112
143
|
|
|
113
|
-
|
|
144
|
+
if (group.files.length > 0)
|
|
145
|
+
coverage = Math.round(sum / group.files.length);
|
|
114
146
|
|
|
115
|
-
|
|
147
|
+
let folderLabel = folder;
|
|
116
148
|
|
|
117
|
-
|
|
149
|
+
if (!folderLabel)
|
|
150
|
+
folderLabel = '.';
|
|
151
|
+
|
|
152
|
+
const trimmedFolder = trim(folderLabel, 25) + '/';
|
|
153
|
+
const folderName = makeRed(trimmedFolder);
|
|
118
154
|
|
|
119
155
|
const headerRow = [folderName];
|
|
120
156
|
|
|
121
|
-
if (showPercent)
|
|
122
|
-
|
|
157
|
+
if (showPercent) {
|
|
158
|
+
let color = makeRed;
|
|
159
|
+
|
|
160
|
+
if (coverage === 100)
|
|
161
|
+
color = makeGreen;
|
|
162
|
+
|
|
163
|
+
headerRow.push(color(`${coverage}%`));
|
|
164
|
+
}
|
|
123
165
|
|
|
124
166
|
headerRow.push('');
|
|
125
|
-
|
|
126
167
|
tableData.push(headerRow);
|
|
127
168
|
|
|
128
169
|
for (const f of group.files) {
|
|
129
|
-
const fileCell =
|
|
130
|
-
const uncoveredLines = formatLines(f.lines);
|
|
170
|
+
const fileCell = ' ' + trim(f.shortName, 30);
|
|
131
171
|
|
|
132
|
-
|
|
172
|
+
let fileColor = makeRed;
|
|
133
173
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
];
|
|
174
|
+
if (f.covered)
|
|
175
|
+
fileColor = makeGreen;
|
|
137
176
|
|
|
138
|
-
|
|
139
|
-
row.push(filePercentColor(`${f.percentLines}%`));
|
|
177
|
+
const row = [fileColor(fileCell)];
|
|
140
178
|
|
|
141
|
-
|
|
179
|
+
if (showPercent) {
|
|
180
|
+
let percentColor = makeRed;
|
|
181
|
+
|
|
182
|
+
if (f.percentLines === 100)
|
|
183
|
+
percentColor = makeGreen;
|
|
184
|
+
|
|
185
|
+
row.push(percentColor(`${f.percentLines}%`));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let uncovered = '';
|
|
189
|
+
|
|
190
|
+
if (!f.covered)
|
|
191
|
+
uncovered = makeRed(formatLines(f.lines));
|
|
192
|
+
|
|
193
|
+
row.push(uncovered);
|
|
142
194
|
|
|
143
195
|
tableData.push(row);
|
|
144
196
|
}
|
|
@@ -147,30 +199,29 @@ function buildGroupedTable(files, showPercent) {
|
|
|
147
199
|
return tableData;
|
|
148
200
|
}
|
|
149
201
|
|
|
150
|
-
|
|
151
|
-
PARSE
|
|
152
|
-
========================= */
|
|
153
|
-
function parseCoverageFile(coverageFile, skipFull = false) {
|
|
202
|
+
function parseCoverageFile(coverageFile, skipFull) {
|
|
154
203
|
const files = [];
|
|
155
204
|
|
|
156
205
|
for (const {name, lines} of coverageFile) {
|
|
157
|
-
const
|
|
158
|
-
const uncoveredLines = parseUncoveredLines(lines);
|
|
206
|
+
const uncovered = parseUncoveredLines(lines);
|
|
159
207
|
|
|
160
208
|
const linesCount = keys(lines).length;
|
|
161
|
-
const
|
|
209
|
+
const uncoveredCount = uncovered.length;
|
|
162
210
|
|
|
163
|
-
const percentLines = getLinesPercent(linesCount,
|
|
211
|
+
const percentLines = getLinesPercent(linesCount, uncoveredCount);
|
|
164
212
|
|
|
165
|
-
|
|
213
|
+
let covered = true;
|
|
166
214
|
|
|
167
|
-
if (
|
|
215
|
+
if (uncoveredCount > 0)
|
|
216
|
+
covered = false;
|
|
217
|
+
|
|
218
|
+
if (skipFull && covered)
|
|
168
219
|
continue;
|
|
169
220
|
|
|
170
221
|
files.push({
|
|
171
|
-
filename,
|
|
172
|
-
covered
|
|
173
|
-
lines:
|
|
222
|
+
filename: name.replace(`${CWD}/`, ''),
|
|
223
|
+
covered,
|
|
224
|
+
lines: uncovered,
|
|
174
225
|
percentLines,
|
|
175
226
|
});
|
|
176
227
|
}
|
|
@@ -178,51 +229,32 @@ function parseCoverageFile(coverageFile, skipFull = false) {
|
|
|
178
229
|
return files;
|
|
179
230
|
}
|
|
180
231
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
function formatPath(path) {
|
|
185
|
-
const max = 30;
|
|
186
|
-
|
|
187
|
-
if (path.length <= max)
|
|
188
|
-
return path;
|
|
232
|
+
function trim(str, max) {
|
|
233
|
+
if (str.length <= max)
|
|
234
|
+
return str;
|
|
189
235
|
|
|
190
|
-
return
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function formatFolder(path) {
|
|
194
|
-
const max = 25;
|
|
195
|
-
|
|
196
|
-
if (path.length <= max)
|
|
197
|
-
return path;
|
|
198
|
-
|
|
199
|
-
return `...${path.slice(-(max - 3))}`;
|
|
236
|
+
return '...' + str.slice(-(max - 3));
|
|
200
237
|
}
|
|
201
238
|
|
|
202
239
|
export function formatLines(array) {
|
|
203
|
-
const max = 30;
|
|
204
|
-
|
|
205
240
|
if (array.length <= 10) {
|
|
206
241
|
const joined = array.join(', ');
|
|
207
242
|
|
|
208
|
-
if (joined.length <=
|
|
243
|
+
if (joined.length <= 30)
|
|
209
244
|
return joined;
|
|
210
245
|
}
|
|
211
246
|
|
|
212
247
|
const [first] = array;
|
|
213
248
|
const last = array.at(-1);
|
|
214
249
|
|
|
215
|
-
const base =
|
|
250
|
+
const base = first + '..' + last;
|
|
216
251
|
|
|
217
|
-
if (base.length <=
|
|
252
|
+
if (base.length <= 30)
|
|
218
253
|
return base;
|
|
219
254
|
|
|
220
|
-
return
|
|
255
|
+
return last;
|
|
221
256
|
}
|
|
222
257
|
|
|
223
|
-
/* =========================
|
|
224
|
-
HELPERS
|
|
225
|
-
========================= */
|
|
226
258
|
function parseUncoveredLines(lines) {
|
|
227
259
|
const out = [];
|
|
228
260
|
|
|
@@ -238,5 +270,7 @@ export function getLinesPercent(linesCount, uncoveredLinesCount) {
|
|
|
238
270
|
if (!linesCount)
|
|
239
271
|
return 100;
|
|
240
272
|
|
|
241
|
-
|
|
273
|
+
const ratio = 100 / linesCount * uncoveredLinesCount;
|
|
274
|
+
|
|
275
|
+
return 100 - Math.round(ratio);
|
|
242
276
|
}
|