monocart-coverage-reports 2.8.3 → 2.8.5

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.
@@ -204,34 +204,24 @@ const Util = {
204
204
  return;
205
205
  }
206
206
 
207
- const quickFindRange = (position, ranges) => {
208
- let start = 0;
209
- let end = ranges.length - 1;
210
- while (end - start > 1) {
211
- const i = Math.floor((start + end) * 0.5);
212
- const item = ranges[i];
213
- if (position < item[startKey]) {
214
- end = i;
215
- continue;
216
- }
217
- if (position > item[endKey]) {
218
- start = i;
219
- continue;
220
- }
221
- return ranges[i];
222
- }
223
- // last two items, less is start
224
- const endItem = ranges[end];
225
- if (position < endItem[startKey]) {
226
- return ranges[start];
227
- }
228
- return ranges[end];
229
- };
207
+ // rangeList should be sorted by startKey, but seems useless here
230
208
 
231
- const range = quickFindRange(startPos, rangeList);
232
- if (startPos >= range[startKey] && endPos <= range[endKey]) {
233
- return range;
209
+ const listStart = rangeList.filter((it) => startPos >= it[startKey]);
210
+ if (!listStart.length) {
211
+ return;
234
212
  }
213
+
214
+ const list = listStart.filter((it) => endPos <= it[endKey]);
215
+ if (!list.length) {
216
+ return;
217
+ }
218
+
219
+ // could be multiple results, but seems no case for now
220
+ // if (list.length > 1) {
221
+ // console.log('==============', list);
222
+ // }
223
+
224
+ return list[0];
235
225
  },
236
226
 
237
227
  getRangeLines: (sLoc, eLoc) => {
@@ -338,6 +328,37 @@ const Util = {
338
328
  return lines;
339
329
  },
340
330
 
331
+ updateLinesCoverage: (lines, count, lineMap) => {
332
+ lines.forEach((it) => {
333
+ const lineItem = lineMap.get(it.line);
334
+ if (!lineItem) {
335
+ // not found line, could be comment or blank line
336
+ return;
337
+ }
338
+
339
+ if (lineItem.ignored) {
340
+ return;
341
+ }
342
+
343
+ it.count = count;
344
+
345
+ // default is covered, so only focus on
346
+ // 1, biggest covered count
347
+ // 2, uncovered entire and pieces
348
+ if (count > 0) {
349
+ lineItem.coveredCount = Math.max(lineItem.coveredCount, count);
350
+ } else {
351
+ if (it.entire) {
352
+ lineItem.uncoveredEntire = it;
353
+ } else {
354
+ lineItem.uncoveredPieces.push(it);
355
+ }
356
+ }
357
+
358
+ });
359
+
360
+ },
361
+
341
362
  // =============================================================================
342
363
  // svg
343
364
 
@@ -1,4 +1,4 @@
1
- const { register } = require('module');
2
- const { pathToFileURL } = require('url');
3
-
4
- register('./hooks.js', pathToFileURL(__filename));
1
+ const { register } = require('module');
2
+ const { pathToFileURL } = require('url');
3
+
4
+ register('./hooks.js', pathToFileURL(__filename));
@@ -1,3 +1,3 @@
1
- import { register } from 'module';
2
-
3
- register('./hooks.mjs', import.meta.url);
1
+ import { register } from 'module';
2
+
3
+ register('./hooks.mjs', import.meta.url);