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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2026.05.08, v6.2.1
2
+
3
+ feature:
4
+ - 53bbcfe escover: formatters: responsive: columns: push
5
+
1
6
  2026.05.08, v6.2.0
2
7
 
3
8
  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,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
- 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;
112
143
 
113
- const folderLabel = formatFolder(folder || '.');
144
+ if (group.files.length > 0)
145
+ coverage = Math.round(sum / group.files.length);
114
146
 
115
- const folderName = makeRed(`${folderLabel}/`);
147
+ let folderLabel = folder;
116
148
 
117
- const folderPercentColor = coverage === 100 ? makeGreen : makeRed;
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
- headerRow.push(folderPercentColor(`${coverage}%`));
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 = ` ${formatPath(f.shortName)}`;
130
- const uncoveredLines = formatLines(f.lines);
170
+ const fileCell = ' ' + trim(f.shortName, 30);
131
171
 
132
- const filePercentColor = f.percentLines === 100 ? makeGreen : makeRed;
172
+ let fileColor = makeRed;
133
173
 
134
- const row = [
135
- f.covered ? makeGreen(fileCell) : makeRed(fileCell),
136
- ];
174
+ if (f.covered)
175
+ fileColor = makeGreen;
137
176
 
138
- if (showPercent)
139
- row.push(filePercentColor(`${f.percentLines}%`));
177
+ const row = [fileColor(fileCell)];
140
178
 
141
- row.push(f.covered ? '' : makeRed(uncoveredLines));
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 filename = name.replace(`${CWD}/`, '');
158
- const uncoveredLines = parseUncoveredLines(lines);
206
+ const uncovered = parseUncoveredLines(lines);
159
207
 
160
208
  const linesCount = keys(lines).length;
161
- const uncoveredLinesCount = uncoveredLines.length;
209
+ const uncoveredCount = uncovered.length;
162
210
 
163
- const percentLines = getLinesPercent(linesCount, uncoveredLinesCount);
211
+ const percentLines = getLinesPercent(linesCount, uncoveredCount);
164
212
 
165
- const isCovered = !uncoveredLinesCount;
213
+ let covered = true;
166
214
 
167
- if (skipFull && isCovered)
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: isCovered,
173
- lines: uncoveredLines,
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
- FORMATTERS
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 `...${path.slice(-(max - 3))}`;
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 <= max)
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 = `${first}..${last}`;
250
+ const base = first + '..' + last;
216
251
 
217
- if (base.length <= max)
252
+ if (base.length <= 30)
218
253
  return base;
219
254
 
220
- return String(last);
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
- return 100 - Math.round(100 / linesCount * uncoveredLinesCount);
273
+ const ratio = 100 / linesCount * uncoveredLinesCount;
274
+
275
+ return 100 - Math.round(ratio);
242
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "escover",
3
- "version": "6.2.0",
3
+ "version": "6.2.1",
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",