monocart-coverage-reports 2.7.3 → 2.7.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/README.md CHANGED
@@ -42,6 +42,7 @@
42
42
  - [CodeceptJS](#codeceptjs)
43
43
  - [WebdriverIO](#webdriverio)
44
44
  - [Storybook Test Runner](#storybook-test-runner)
45
+ - [TestCafe](#testcafe)
45
46
  - [Codecov](#codecov)
46
47
  - [Coveralls](#coveralls)
47
48
  - [Sonar Cloud](#sonar-cloud)
@@ -829,6 +830,9 @@ const coverageOptions = {
829
830
  ### [Storybook Test Runner](https://github.com/storybookjs/test-runner)
830
831
  - [storybook-monocart-coverage](https://github.com/cenfun/storybook-monocart-coverage) - Storybook V8 Coverage Example
831
832
 
833
+ ### [TestCafe](https://github.com/DevExpress/testcafe)
834
+ - [testcafe-reporter-coverage](https://github.com/cenfun/testcafe-reporter-coverage) - A TestCafe custom reporter for coverage reports
835
+
832
836
  ### [Codecov](https://codecov.com/)
833
837
  [![codecov](https://codecov.io/gh/cenfun/monocart-coverage-reports/graph/badge.svg?token=H0LW7UKYU3)](https://codecov.io/gh/cenfun/monocart-coverage-reports)
834
838
  - Supports native `codecov` built-in report ([specification](https://docs.codecov.com/docs/codecov-custom-coverage-format))
@@ -1405,7 +1405,7 @@ const convertV8List = (v8list, options) => {
1405
1405
  // console.log([item.id]);
1406
1406
 
1407
1407
  const {
1408
- type, source, sourcePath
1408
+ type, source, fake, sourcePath
1409
1409
  } = item;
1410
1410
 
1411
1411
  // for source file, type could be ts or vue as extname, but js = true
@@ -1454,6 +1454,7 @@ const convertV8List = (v8list, options) => {
1454
1454
  js,
1455
1455
  type,
1456
1456
  source,
1457
+ fake,
1457
1458
  sourcePath,
1458
1459
  sourceMap,
1459
1460
  locator,
@@ -1,3 +1,4 @@
1
+ const { diff } = require('../packages/monocart-coverage-vendor');
1
2
  const Util = require('../utils/util.js');
2
3
  const EC = Util.EC;
3
4
 
@@ -38,6 +39,133 @@ const findMapping = (list, offset) => {
38
39
 
39
40
  // ========================================================================================================
40
41
 
42
+ const alignText = (gt, ot) => {
43
+
44
+ const toList = (s) => {
45
+ return s.split('').map((v, i) => {
46
+ return {
47
+ index: i,
48
+ value: v
49
+ };
50
+ });
51
+ };
52
+
53
+ const mergeList = (gList, oList) => {
54
+ const oLen = oList.length;
55
+ if (!oLen) {
56
+ return;
57
+ }
58
+ const gLen = gList.length;
59
+ if (gLen === oLen) {
60
+ gList.forEach((item, i) => {
61
+ item.original = oList[i];
62
+ });
63
+ }
64
+ };
65
+
66
+ const gl = toList(gt);
67
+ const ol = toList(ot);
68
+
69
+ // console.log(gl);
70
+ // console.log(ol);
71
+
72
+ const commonItems = [];
73
+ diff(gl.length, ol.length, (gi, oi) => {
74
+ return gl[gi].value === ol[oi].value;
75
+ }, (len, gi, oi) => {
76
+ commonItems.push([gi, oi, len]);
77
+ });
78
+
79
+ // console.log(commonItems);
80
+ // console.log('================================================================');
81
+ // merge list
82
+ // previous index
83
+ let gpi = 0;
84
+ let opi = 0;
85
+ commonItems.forEach(([gi, oi, len]) => {
86
+
87
+ if (gpi !== gi) {
88
+ const gList = gl.slice(gpi, gi);
89
+ const oList = ol.slice(opi, oi);
90
+ mergeList(gList, oList);
91
+ }
92
+
93
+ for (let i = 0; i < len; i++) {
94
+
95
+ const gii = gi + i;
96
+ const oii = oi + i;
97
+ const gItem = gl[gii];
98
+ gItem.original = ol[oii];
99
+
100
+ // matching a word end
101
+ if (i === len - 1 && len > 1) {
102
+ gItem.wordEnd = true;
103
+ }
104
+
105
+ }
106
+ gpi = gi + len;
107
+ opi = oi + len;
108
+ });
109
+
110
+ // console.log(JSON.stringify(data.gt));
111
+ // console.log(JSON.stringify(data.ot));
112
+ if (gpi < gl.length && opi < ol.length) {
113
+ const gList = gl.slice(gpi);
114
+ const oList = ol.slice(opi);
115
+ mergeList(gList, oList);
116
+ }
117
+
118
+ // console.log(gl);
119
+ return gl;
120
+ };
121
+
122
+ const getAlignPosition = (gt, gp, ot, direction) => {
123
+
124
+ // generatedText: '"false";\n',
125
+ // originalText: "'false';\r\n ",
126
+ // generatedPos: 7
127
+
128
+ // left matched
129
+
130
+ // originalText: '1;',
131
+ // generatedText: '1;else',
132
+ // generatedLeft: '1;'
133
+
134
+ // generatedText: ' var id = options.base ? item[0] + options.base : item[0];\r\n',
135
+ // originalText: ' var id = options.base ? item[0] + options.base : item[0];\n',
136
+
137
+ // right matched
138
+ // only for original first line text
139
+
140
+ // exclusive
141
+ const list = alignText(gt, ot);
142
+ const item = list[gp];
143
+ if (item && item.original) {
144
+ return {
145
+ pos: item.original.index
146
+ };
147
+ }
148
+
149
+ // inclusive, for end only
150
+ if (gp && direction === 'end') {
151
+ const prev = list[gp - 1];
152
+ if (prev && prev.original && prev.wordEnd) {
153
+ // console.log(direction, '=====================================================================');
154
+ const op = prev.original.index + 1;
155
+ // console.log(gp, JSON.stringify(gt));
156
+ // console.log(op, JSON.stringify(ot));
157
+
158
+ return {
159
+ pos: op
160
+ };
161
+
162
+ }
163
+ }
164
+
165
+ };
166
+
167
+ // ========================================================================================================
168
+
41
169
  const getBlockStartPosition = (originalLineText) => {
42
170
  // originalText: 'argument) {',
43
171
  // generatedLeft: 'o',
@@ -117,32 +245,42 @@ const getBlockEndPosition = (originalLineText) => {
117
245
 
118
246
  };
119
247
 
248
+ // ========================================================================================================
249
+
120
250
  const getComparedPosition = (info, direction) => {
121
251
 
122
- let gt = info.generatedText;
252
+ const gt = info.generatedText;
123
253
  const gp = info.generatedPos;
124
- let ot = info.originalText;
254
+ const ot = info.originalText;
125
255
 
126
- // before trim
127
- const oLen = ot.length;
256
+ // whole generated text
257
+ if (gp >= gt.length) {
258
+ // console.log(JSON.stringify(gt), gt.length, gp);
259
+ // console.log(JSON.stringify(ot));
260
+ return {
261
+ pos: info.originalLineText.length
262
+ };
263
+ }
128
264
 
129
- gt = gt.trimEnd();
130
- ot = ot.trimEnd();
265
+ // =============================
266
+ // trim right
267
+ const gtt = gt.trimEnd();
268
+ const ott = ot.trimEnd();
131
269
 
132
270
  // no original content after trim
133
- if (!ot) {
271
+ if (!ott) {
134
272
  return {
135
- pos: direction === 'start' ? oLen : 0
273
+ pos: direction === 'start' ? ot.length : 0
136
274
  };
137
275
  }
138
276
 
139
277
  // no generated content after trim
140
- if (!gt) {
278
+ if (!gtt) {
141
279
  return;
142
280
  }
143
281
 
144
282
  // same content
145
- if (gt === ot) {
283
+ if (gtt === ott) {
146
284
  return {
147
285
  pos: gp
148
286
  };
@@ -150,54 +288,13 @@ const getComparedPosition = (info, direction) => {
150
288
 
151
289
  // =============================
152
290
 
153
- // generatedText: '"false";\n',
154
- // originalText: "'false';\r\n ",
155
- // generatedPos: 7
156
-
157
- // length not change, replace " to '
158
- gt = gt.replace(/"/g, "'");
159
- ot = ot.replace(/"/g, "'");
160
-
161
-
162
- // same content too
163
- if (gt === ot) {
164
- return {
165
- pos: gp
166
- };
167
- }
168
-
169
- // ============================
170
- // left matched
171
-
172
- // originalText: '1;',
173
- // generatedText: '1;else',
174
- // generatedLeft: '1;'
175
-
176
- // generatedText: ' var id = options.base ? item[0] + options.base : item[0];\r\n',
177
- // originalText: ' var id = options.base ? item[0] + options.base : item[0];\n',
178
-
179
- const left = gt.slice(0, gp);
180
- if (ot.startsWith(left)) {
181
- return {
182
- pos: gp
183
- };
184
- }
291
+ return getAlignPosition(gt, gp, ot, direction);
185
292
 
186
- // ============================
187
- // right matched
188
- // only for original first line text
293
+ };
189
294
 
190
- const olt = info.originalLineText;
191
- const right = gt.slice(gp);
192
- if (olt.endsWith(right)) {
193
- return {
194
- pos: olt.length - right.length
195
- };
196
- }
197
295
 
198
- };
296
+ const getSimilarPosition = (info, direction) => {
199
297
 
200
- const initOriginalLineText = (info) => {
201
298
  const originalText = info.originalText;
202
299
  // never cross line, using first line of original text
203
300
  // trim end remove \r\n and \n
@@ -205,44 +302,27 @@ const initOriginalLineText = (info) => {
205
302
  if (originalLines.length === 1) {
206
303
  // already single line
207
304
  info.originalLineText = originalText.trimEnd();
208
- info.originalSingle = true;
209
- return;
305
+ } else {
306
+ // multiple liens
307
+ info.originalLineText = originalLines[0].trimEnd();
210
308
  }
211
- // multiple liens
212
- info.originalLineText = originalLines[0].trimEnd();
213
- };
214
309
 
215
- const getSimilarPosition = (info, direction) => {
216
-
217
- initOriginalLineText(info);
310
+ // no need comparison for fake source
311
+ if (info.fake) {
312
+ return;
313
+ }
218
314
 
219
315
  const textPos = getComparedPosition(info, direction);
220
316
  if (textPos) {
221
317
  return textPos;
222
318
  }
223
319
 
224
- if (info.originalSingle) {
225
- return;
226
- }
227
-
228
- // multiple lines
229
- const { generatedPos, originalLineText } = info;
230
- // generatedPos not in first line
231
- if (generatedPos > originalLineText.length) {
232
- return;
233
- }
234
-
235
- const linePos = getComparedPosition(info, direction);
236
- if (linePos) {
237
- return linePos;
238
- }
239
-
240
320
  // console.log('====================================================================');
241
- // console.log(`${EC.magenta(direction)} similar position can NOT be fixed`);
321
+ // console.log(`${EC.magenta(direction)} similar position can NOT be fixed`, info.originalState.sourcePath);
242
322
  // console.log({
243
- // sourcePath: info.originalState.sourcePath,
244
- // generatedText,
245
- // generatedPos,
323
+ // direction,
324
+ // generatedText: info.generatedText,
325
+ // generatedPos: info.generatedPos,
246
326
  // originalText
247
327
  // });
248
328
 
@@ -402,11 +482,13 @@ const getFixedOriginalStart = (start, mappings, state, cache) => {
402
482
  };
403
483
  }
404
484
 
405
- const direction = 'start';
485
+
406
486
  const { originalText, originalOffset } = getOriginalText(m1, m2, cache);
407
487
  const { generatedText, generatedPos } = getGeneratedText(m1, m2, state, start);
488
+ const direction = 'start';
408
489
 
409
490
  const info = {
491
+ fake: state.fake,
410
492
  generatedText,
411
493
  generatedPos,
412
494
  originalText,
@@ -453,11 +535,13 @@ const getFixedOriginalEnd = (end, mappings, state, cache) => {
453
535
  };
454
536
  }
455
537
 
456
- const direction = 'end';
538
+
457
539
  const { originalText, originalOffset } = getOriginalText(m1, m2, cache);
458
540
  const { generatedText, generatedPos } = getGeneratedText(m1, m2, state, end);
541
+ const direction = 'end';
459
542
 
460
543
  const info = {
544
+ fake: state.fake,
461
545
  offset: end,
462
546
  generatedText,
463
547
  generatedPos,