escover 6.2.3 → 6.2.4

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