escover 6.2.0 → 6.2.2

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,13 @@
1
+ 2026.05.08, v6.2.2
2
+
3
+ fix:
4
+ - 3b5e98e formatters: responsive: directory green when 100%
5
+
6
+ 2026.05.08, v6.2.1
7
+
8
+ feature:
9
+ - 53bbcfe escover: formatters: responsive: columns: push
10
+
1
11
  2026.05.08, v6.2.0
2
12
 
3
13
  fix:
package/lib/cli/cli.js CHANGED
@@ -42,7 +42,7 @@ export const cli = ({argv, exit, readCoverage}) => {
42
42
  console.log(`v${version()}`);
43
43
  return exit();
44
44
  }
45
-
45
+
46
46
  if (args.help) {
47
47
  console.log(help());
48
48
  return exit();
@@ -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
- const percentColWidth = showPercent ? 8 : 0;
25
- const fileColWidth = Math.floor(totalWidth * 0.45);
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
- return table(tableData, {
32
- drawHorizontalLine: (raw) => !raw || raw === 1 || raw === tableData.length,
33
-
34
- columns: [{
35
- paddingLeft: 1,
36
- paddingRight: 1,
37
- width: fileColWidth,
38
- wrapWord: false, // 🔥 ключевой фикс — без переносов
39
- }, ...showPercent ? [{
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
- paddingLeft: 1,
46
- paddingRight: 0,
47
- width: linesColWidth,
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
- const folder = parts.length > 1 ? parts
72
- .slice(0, -1)
73
- .join('/') : '';
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
- if (!groups.has(folder))
78
- groups.set(folder, {
79
- files: [],
80
- });
101
+ let group = groups.get(folder);
81
102
 
82
- const group = groups.get(folder);
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,87 @@ 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
- showPercent ? [
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
- const coverage = group.files.length ? Math.round(group.files.reduce((sum, f) => sum + f.percentLines, 0) / group.files.length) : 100;
137
+ let sum = 0;
138
+
139
+ for (const f of group.files)
140
+ sum += f.percentLines;
141
+
142
+ let coverage = 100;
143
+
144
+ if (group.files.length > 0)
145
+ coverage = Math.round(sum / group.files.length);
112
146
 
113
- const folderLabel = formatFolder(folder || '.');
147
+ let folderLabel = folder;
114
148
 
115
- const folderName = makeRed(`${folderLabel}/`);
149
+ if (!folderLabel)
150
+ folderLabel = '.';
116
151
 
117
- const folderPercentColor = coverage === 100 ? makeGreen : makeRed;
152
+ const trimmedFolder = trim(folderLabel, 25) + '/';
153
+
154
+ let folderColor = makeRed;
155
+
156
+ if (coverage === 100)
157
+ folderColor = makeGreen;
158
+
159
+ const folderName = folderColor(trimmedFolder);
118
160
 
119
161
  const headerRow = [folderName];
120
162
 
121
- if (showPercent)
122
- headerRow.push(folderPercentColor(`${coverage}%`));
163
+ if (showPercent) {
164
+ let color = makeRed;
165
+
166
+ if (coverage === 100)
167
+ color = makeGreen;
168
+
169
+ headerRow.push(color(`${coverage}%`));
170
+ }
123
171
 
124
172
  headerRow.push('');
125
-
126
173
  tableData.push(headerRow);
127
174
 
128
175
  for (const f of group.files) {
129
- const fileCell = ` ${formatPath(f.shortName)}`;
130
- const uncoveredLines = formatLines(f.lines);
176
+ const fileCell = ' ' + trim(f.shortName, 30);
177
+
178
+ let fileColor = makeRed;
179
+
180
+ if (f.covered)
181
+ fileColor = makeGreen;
131
182
 
132
- const filePercentColor = f.percentLines === 100 ? makeGreen : makeRed;
183
+ const row = [fileColor(fileCell)];
133
184
 
134
- const row = [
135
- f.covered ? makeGreen(fileCell) : makeRed(fileCell),
136
- ];
185
+ if (showPercent) {
186
+ let percentColor = makeRed;
187
+
188
+ if (f.percentLines === 100)
189
+ percentColor = makeGreen;
190
+
191
+ row.push(percentColor(`${f.percentLines}%`));
192
+ }
137
193
 
138
- if (showPercent)
139
- row.push(filePercentColor(`${f.percentLines}%`));
194
+ let uncovered = '';
140
195
 
141
- row.push(f.covered ? '' : makeRed(uncoveredLines));
196
+ if (!f.covered)
197
+ uncovered = makeRed(formatLines(f.lines));
198
+
199
+ row.push(uncovered);
142
200
 
143
201
  tableData.push(row);
144
202
  }
@@ -147,30 +205,29 @@ function buildGroupedTable(files, showPercent) {
147
205
  return tableData;
148
206
  }
149
207
 
150
- /* =========================
151
- PARSE
152
- ========================= */
153
- function parseCoverageFile(coverageFile, skipFull = false) {
208
+ function parseCoverageFile(coverageFile, skipFull) {
154
209
  const files = [];
155
210
 
156
211
  for (const {name, lines} of coverageFile) {
157
- const filename = name.replace(`${CWD}/`, '');
158
- const uncoveredLines = parseUncoveredLines(lines);
212
+ const uncovered = parseUncoveredLines(lines);
159
213
 
160
214
  const linesCount = keys(lines).length;
161
- const uncoveredLinesCount = uncoveredLines.length;
215
+ const uncoveredCount = uncovered.length;
216
+
217
+ const percentLines = getLinesPercent(linesCount, uncoveredCount);
162
218
 
163
- const percentLines = getLinesPercent(linesCount, uncoveredLinesCount);
219
+ let covered = true;
164
220
 
165
- const isCovered = !uncoveredLinesCount;
221
+ if (uncoveredCount > 0)
222
+ covered = false;
166
223
 
167
- if (skipFull && isCovered)
224
+ if (skipFull && covered)
168
225
  continue;
169
226
 
170
227
  files.push({
171
- filename,
172
- covered: isCovered,
173
- lines: uncoveredLines,
228
+ filename: name.replace(`${CWD}/`, ''),
229
+ covered,
230
+ lines: uncovered,
174
231
  percentLines,
175
232
  });
176
233
  }
@@ -178,51 +235,32 @@ function parseCoverageFile(coverageFile, skipFull = false) {
178
235
  return files;
179
236
  }
180
237
 
181
- /* =========================
182
- FORMATTERS
183
- ========================= */
184
- function formatPath(path) {
185
- const max = 30;
186
-
187
- if (path.length <= max)
188
- return path;
189
-
190
- return `...${path.slice(-(max - 3))}`;
191
- }
192
-
193
- function formatFolder(path) {
194
- const max = 25;
238
+ function trim(str, max) {
239
+ if (str.length <= max)
240
+ return str;
195
241
 
196
- if (path.length <= max)
197
- return path;
198
-
199
- return `...${path.slice(-(max - 3))}`;
242
+ return '...' + str.slice(-(max - 3));
200
243
  }
201
244
 
202
245
  export function formatLines(array) {
203
- const max = 30;
204
-
205
246
  if (array.length <= 10) {
206
247
  const joined = array.join(', ');
207
248
 
208
- if (joined.length <= max)
249
+ if (joined.length <= 30)
209
250
  return joined;
210
251
  }
211
252
 
212
253
  const [first] = array;
213
254
  const last = array.at(-1);
214
255
 
215
- const base = `${first}..${last}`;
256
+ const base = first + '..' + last;
216
257
 
217
- if (base.length <= max)
258
+ if (base.length <= 30)
218
259
  return base;
219
260
 
220
- return String(last);
261
+ return last;
221
262
  }
222
263
 
223
- /* =========================
224
- HELPERS
225
- ========================= */
226
264
  function parseUncoveredLines(lines) {
227
265
  const out = [];
228
266
 
@@ -238,5 +276,7 @@ export function getLinesPercent(linesCount, uncoveredLinesCount) {
238
276
  if (!linesCount)
239
277
  return 100;
240
278
 
241
- return 100 - Math.round(100 / linesCount * uncoveredLinesCount);
279
+ const ratio = 100 / linesCount * uncoveredLinesCount;
280
+
281
+ return 100 - Math.round(ratio);
242
282
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "6.2.0",
3
+ "version": "6.2.2",
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",