monocart-reporter 1.6.28 → 1.6.30

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
@@ -126,7 +126,7 @@ Separated metadata file (Already included in the above HTML and compressed, it c
126
126
  // entryFilter: (entry) => true,
127
127
  // unpackSourceMap: true,
128
128
  // excludeDistFile: true,
129
- // sourceFilter: (sourceName) => sourceName.search(/\/src\/.+/) !== -1,
129
+ // sourceFilter: (sourceName) => sourceName.search(/src\/.+/) !== -1,
130
130
  // },
131
131
 
132
132
  // trend data handler
@@ -493,6 +493,7 @@ module.exports = {
493
493
  ]
494
494
  };
495
495
  ```
496
+ see example [remove-secrets](https://github.com/cenfun/monocart-reporter-test/tree/main/tests/remove-secrets)
496
497
 
497
498
  ## Style Tags
498
499
  * Add tag to test/describe title ( starts with `@` )
@@ -742,7 +743,8 @@ const report = await attachCoverageReport(coverageList, test.info(), {
742
743
  | Input data format | Istanbul (Object) | V8 (Array) | V8 (Array) |
743
744
  | Options | `watermarks: {}` | `watermarks: [50, 80]` | `toIstanbul: true, watermarks: {}` |
744
745
  | Output report | [Istanbul HTML report](https://cenfun.github.io/monocart-reporter/coverage-4ffdff9b89e7b58476cf/index.html) | [V8 HTML report](https://cenfun.github.io/monocart-reporter/coverage-f8ad4b6741d60f9e7b81/index.html) | [Istanbul HTML report](https://cenfun.github.io/monocart-reporter/coverage-391e7054ca1e6d944895/index.html) |
745
- | Indicators | Covered Lines, Branches, Statements and Functions, Execution Counts | Covered Bytes, Execution Counts | Covered Lines, Branches, Statements and Functions, Execution Counts |
746
+ | Indicators | Covered Lines, Branches, Statements and Functions, Execution Counts | Covered Bytes, Lines (after formatted) Execution Counts | Covered Lines, Branches, Statements and Functions, Execution Counts |
747
+ | Source code without [instrumentation](https://github.com/istanbuljs/babel-plugin-istanbul) | ❌ | ✅ | ✅ |
746
748
  | CSS coverage | ❌ | ✅ | ❌ |
747
749
  | Minified code | N/A | ✅ | ❌ |
748
750
  | Code formatting | N/A | ✅ | ❌ |
@@ -761,7 +763,7 @@ module.exports = {
761
763
  entryFilter: (entry) => true,
762
764
  unpackSourceMap: true,
763
765
  excludeDistFile: true,
764
- sourceFilter: (sourceName) => sourceName.search(/\/src\/.+/) !== -1,
766
+ sourceFilter: (sourceName) => sourceName.search(/src\/.+/) !== -1,
765
767
  }
766
768
  }]
767
769
  ]
@@ -17,7 +17,7 @@ module.exports = {
17
17
  // entryFilter: (entry) => true,
18
18
  // unpackSourceMap: true,
19
19
  // excludeDistFile: true,
20
- // sourceFilter: (sourceName) => sourceName.search(/\/src\/.+/) !== -1,
20
+ // sourceFilter: (sourceName) => sourceName.search(/src\/.+/) !== -1,
21
21
  // },
22
22
 
23
23
  // trend data handler
@@ -55,22 +55,26 @@ const showTestResults = (reportData) => {
55
55
 
56
56
  const summary = reportData.summary;
57
57
 
58
- const colorHandler = (item, v) => {
59
- if (item.id === 'failed') {
60
- if (item.value > 0) {
61
- v = EC.red(v);
62
- }
58
+ const colorHandler = (item, row) => {
63
59
 
64
- } else if (item.id === 'flaky') {
65
- if (item.value > 0) {
66
- v = EC.yellow(v);
67
- }
68
- } else if (item.id === 'passed') {
60
+ if (['failed', 'errors'].includes(item.id) && item.value > 0) {
61
+ row.name = EC.red(row.name);
62
+ row.value = EC.red(row.value);
63
+ return;
64
+ }
65
+
66
+ if (['flaky', 'retries'].includes(item.id) && item.value > 0) {
67
+ row.name = EC.yellow(row.name);
68
+ row.value = EC.yellow(row.value);
69
+ return;
70
+ }
71
+
72
+ if (item.id === 'passed') {
69
73
  if (summary.failed.value === 0 && summary.passed.value > 0) {
70
- v = EC.green(v);
74
+ row.name = EC.green(row.name);
75
+ row.value = EC.green(row.value);
71
76
  }
72
77
  }
73
- return v;
74
78
  };
75
79
 
76
80
  let rows = [];
@@ -82,9 +86,12 @@ const showTestResults = (reportData) => {
82
86
  if (caseTypes.includes(item.id) || suiteSubs.includes(item.id)) {
83
87
  return;
84
88
  }
85
- rows.push({
89
+
90
+ const row = {
86
91
  ... item
87
- });
92
+ };
93
+ colorHandler(item, row);
94
+ rows.push(row);
88
95
  });
89
96
 
90
97
  const tests = rows.find((it) => it.id === 'tests');
@@ -94,10 +101,12 @@ const showTestResults = (reportData) => {
94
101
  };
95
102
  const value = `${item.value}`.padEnd(`${tests.value}`.length, ' ');
96
103
  const percent = `(${item.percent})`;
97
- return {
98
- name: colorHandler(item, item.name),
99
- value: colorHandler(item, `${value} ${percent}`)
104
+ const row = {
105
+ name: item.name,
106
+ value: `${value} ${percent}`
100
107
  };
108
+ colorHandler(item, row);
109
+ return row;
101
110
  });
102
111
 
103
112
  const suites = rows.find((it) => it.id === 'suites');
package/lib/index.js CHANGED
@@ -43,6 +43,10 @@ class Reporter {
43
43
  this.tickStart();
44
44
  }
45
45
 
46
+ printsToStdio() {
47
+ return false;
48
+ }
49
+
46
50
  tickStart() {
47
51
  this.tick_time_id = setTimeout(async () => {
48
52
  const tickInfo = await getTickInfo();
@@ -67,6 +67,13 @@ const getSourcePath = (url, index = '', type = '') => {
67
67
  return filterPath(relPath);
68
68
  };
69
69
 
70
+ const mergeSourceRoot = (sourceRoot, sourceName) => {
71
+ if (sourceName.startsWith(sourceRoot)) {
72
+ return sourceName;
73
+ }
74
+ return sourceRoot + sourceName;
75
+ };
76
+
70
77
  // ================================================================================================
71
78
 
72
79
  const request = async (options) => {
@@ -150,5 +157,6 @@ const collectSourceMaps = async (v8list) => {
150
157
  module.exports = {
151
158
  sortRanges,
152
159
  getSourcePath,
160
+ mergeSourceRoot,
153
161
  collectSourceMaps
154
162
  };
@@ -18,7 +18,9 @@ const {
18
18
  // const istanbulLibCoverage = require('istanbul-lib-coverage');
19
19
  // const istanbulLibReport = require('istanbul-lib-report');
20
20
 
21
- const { getSourcePath, collectSourceMaps } = require('../coverage-utils.js');
21
+ const {
22
+ getSourcePath, mergeSourceRoot, collectSourceMaps
23
+ } = require('../coverage-utils.js');
22
24
 
23
25
 
24
26
  const saveIstanbulReport = (coverageData, fileSources, options) => {
@@ -149,9 +151,14 @@ const getConversionSources = (item, fileSources) => {
149
151
  // 'webpack://monocart-v8/external umd "monocart-code-viewer"'
150
152
  // format the url to sourcePath
151
153
 
154
+ // reset sourceRoot
155
+ const sourceRoot = sourceMap.sourceRoot || '';
156
+ sourceMap.sourceRoot = '';
157
+
152
158
  // resolve source path and add to file sources cache for html report sourceFinder
153
159
  sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
154
- const newSourceName = getSourcePath(sourceName, i + 1);
160
+ const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
161
+ const newSourceName = getSourcePath(sourceUrl, i + 1);
155
162
  fileSources[newSourceName] = sourceMap.sourcesContent[i];
156
163
  return newSourceName;
157
164
  });
@@ -29,10 +29,6 @@ class PositionMapping {
29
29
  this.sourceName = sourceName;
30
30
  this.lines = this.getLines(source);
31
31
  this.ranges = [];
32
- this.range = {
33
- start: 0,
34
- end: 0
35
- };
36
32
  }
37
33
 
38
34
  // =============================================================================
@@ -4,8 +4,12 @@ const { SourceMapConsumer } = require('source-map');
4
4
 
5
5
  const PositionMapping = require('./position-mapping.js');
6
6
  const { dedupeCountRanges } = require('./dedupe.js');
7
- const { getSourcePath, collectSourceMaps } = require('../coverage-utils.js');
7
+ const {
8
+ getSourcePath, mergeSourceRoot, collectSourceMaps
9
+ } = require('../coverage-utils.js');
8
10
 
11
+ // SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
12
+ // SourceMapConsumer.LEAST_UPPER_BOUND = 2;
9
13
  const BIAS = {
10
14
  left: SourceMapConsumer.GREATEST_LOWER_BOUND,
11
15
  right: SourceMapConsumer.LEAST_UPPER_BOUND
@@ -13,7 +17,7 @@ const BIAS = {
13
17
 
14
18
  // =========================================================================================================
15
19
 
16
- const getOriginalPosition = (consumer, line, column, sides) => {
20
+ const findOriginalPosition = (consumer, line, column, sides) => {
17
21
  let original;
18
22
  for (const side of sides) {
19
23
  original = consumer.originalPositionFor({
@@ -30,42 +34,58 @@ const getOriginalPosition = (consumer, line, column, sides) => {
30
34
  }
31
35
  };
32
36
 
33
- const getOriginalStartPosition = (consumer, line, column) => {
34
- return getOriginalPosition(consumer, line, column, ['right', 'left']);
37
+ const findOriginalStartPosition = (consumer, sLoc) => {
38
+ const { line, column } = sLoc;
39
+ return findOriginalPosition(consumer, line, column, ['right', 'left']);
35
40
  };
36
41
 
37
- const getOriginalEndPosition = (consumer, line, column) => {
42
+ const findOriginalEndInRange = (consumer, generatedMapping, range) => {
43
+ const { start, end } = range;
44
+ // from -2 (already -1)
45
+ // > start (no need equal)
46
+ for (let i = end - 2; i > start; i--) {
47
+ const loc = generatedMapping.offsetToLocation(i);
48
+ const op = findOriginalPosition(consumer, loc.line, loc.column, ['left', 'right']);
49
+ if (op) {
50
+ return op;
51
+ }
52
+ }
53
+ };
54
+
55
+ const findOriginalEndPosition = (consumer, eLoc, generatedMapping, range) => {
56
+ const { line, column } = eLoc;
38
57
 
39
58
  // before end column must be >= 0
40
- if (column > 0) {
41
- column -= 1;
42
- }
59
+ const currentColumn = Math.max(column - 1, 0);
43
60
 
44
- const beforeEnd = getOriginalPosition(consumer, line, column, ['left', 'right']);
45
- if (!beforeEnd) {
46
- return;
61
+ let ep = findOriginalPosition(consumer, line, currentColumn, ['left', 'right']);
62
+ if (!ep) {
63
+ ep = findOriginalEndInRange(consumer, generatedMapping, range);
64
+ if (!ep) {
65
+ return;
66
+ }
47
67
  }
48
68
 
49
69
  const afterEndMapping = consumer.generatedPositionFor({
50
- source: beforeEnd.source,
51
- line: beforeEnd.line,
52
- column: beforeEnd.column + 1,
70
+ source: ep.source,
71
+ line: ep.line,
72
+ column: ep.column + 1,
53
73
  bias: BIAS.right
54
74
  });
55
75
 
56
76
  if (afterEndMapping.line === null) {
57
77
  return {
58
- source: beforeEnd.source,
59
- line: beforeEnd.line,
78
+ source: ep.source,
79
+ line: ep.line,
60
80
  column: Infinity
61
81
  };
62
82
  }
63
83
 
64
84
  const mapping = consumer.originalPositionFor(afterEndMapping);
65
- if (mapping.line !== beforeEnd.line) {
85
+ if (mapping.line !== ep.line) {
66
86
  return {
67
- source: beforeEnd.source,
68
- line: beforeEnd.line,
87
+ source: ep.source,
88
+ line: ep.line,
69
89
  column: Infinity
70
90
  };
71
91
  }
@@ -75,98 +95,6 @@ const getOriginalEndPosition = (consumer, line, column) => {
75
95
 
76
96
  // =========================================================================================================
77
97
 
78
- const getOriginalFileStart = (consumer, sourceName, lines) => {
79
- const len = lines.length;
80
- for (let i = 0; i < len; i++) {
81
- const list = consumer.allGeneratedPositionsFor({
82
- source: sourceName,
83
- line: i + 1
84
- });
85
- if (list.length) {
86
- return list[0];
87
- }
88
- }
89
- };
90
-
91
- const getOriginalFileEnd = (consumer, sourceName, lines) => {
92
- const len = lines.length;
93
- for (let i = len - 1; i >= 0; i--) {
94
- const list = consumer.allGeneratedPositionsFor({
95
- source: sourceName,
96
- line: i + 1
97
- });
98
- if (list.length) {
99
- return list[list.length - 1];
100
- }
101
- }
102
- };
103
-
104
- const calculateOriginalFileRange = (generatedMapping, consumer, originalMapping) => {
105
- const { sourceName, lines } = originalMapping;
106
-
107
- // consumer.computeColumnSpans();
108
-
109
- const gs = getOriginalFileStart(consumer, sourceName, lines);
110
- const ge = getOriginalFileEnd(consumer, sourceName, lines);
111
-
112
- // console.log('file range', sourceName, sLoc, eLoc);
113
-
114
- if (!gs || !ge) {
115
- // console.log('failed to get file range', sourceName, sLoc, eLoc);
116
- return;
117
- }
118
-
119
- const generatedStart = generatedMapping.locationToOffset({
120
- line: gs.line,
121
- column: gs.column
122
- });
123
- const generatedEnd = generatedMapping.locationToOffset({
124
- line: ge.line,
125
- column: ge.column
126
- });
127
-
128
- const os = consumer.originalPositionFor({
129
- line: gs.line,
130
- column: gs.column
131
- });
132
- const oe = consumer.originalPositionFor({
133
- line: ge.line,
134
- column: ge.column
135
- });
136
- const originalStart = originalMapping.locationToOffset({
137
- line: os.line,
138
- column: os.column
139
- });
140
- const originalEnd = originalMapping.locationToOffset({
141
- line: oe.line,
142
- column: oe.column
143
- });
144
-
145
- const range = {
146
- generatedStart,
147
- generatedEnd,
148
- originalStart,
149
- originalEnd
150
- };
151
-
152
- if (generatedStart > generatedEnd) {
153
- range.generatedStart = generatedEnd;
154
- range.generatedEnd = generatedStart;
155
- }
156
-
157
- if (originalStart > originalEnd) {
158
- range.originalStart = originalEnd;
159
- range.originalEnd = originalStart;
160
- }
161
-
162
- originalMapping.range = range;
163
-
164
- // console.log('file range', sourceName, range);
165
-
166
- // EC.logCyan(JSON.stringify(generatedMapping.getSlice(range.start, range.end)));
167
-
168
- };
169
-
170
98
  const getOriginalMappings = (generatedMapping, consumer, options) => {
171
99
 
172
100
  // source filter
@@ -188,7 +116,6 @@ const getOriginalMappings = (generatedMapping, consumer, options) => {
188
116
  }
189
117
 
190
118
  const mapping = new PositionMapping(sourceContent, sourceName);
191
- calculateOriginalFileRange(generatedMapping, consumer, mapping);
192
119
  originalMappings.set(sourceName, mapping);
193
120
  }
194
121
 
@@ -213,10 +140,16 @@ const unpackJsSourceMap = async (item, v8list, options) => {
213
140
  // console.log(Object.keys(item));
214
141
 
215
142
  const sourceMap = item.sourceMap;
143
+
144
+ // reset sourceRoot
145
+ const sourceRoot = sourceMap.sourceRoot || '';
146
+ sourceMap.sourceRoot = '';
147
+
216
148
  const urlMap = {};
217
149
  sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
218
- const newSourceName = getSourcePath(sourceName, i + 1);
219
- urlMap[newSourceName] = sourceName;
150
+ const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
151
+ const newSourceName = getSourcePath(sourceUrl, i + 1);
152
+ urlMap[newSourceName] = sourceUrl;
220
153
  return newSourceName;
221
154
  });
222
155
 
@@ -226,12 +159,16 @@ const unpackJsSourceMap = async (item, v8list, options) => {
226
159
 
227
160
  // generated ranges to original ranges
228
161
  item.ranges.forEach((range) => {
162
+
163
+ // find start location
229
164
  const sLoc = generatedMapping.offsetToLocation(range.start);
230
- const oSLoc = getOriginalStartPosition(consumer, sLoc.line, sLoc.column);
165
+ const oSLoc = findOriginalStartPosition(consumer, sLoc);
231
166
  if (!oSLoc) {
167
+ // not found start
232
168
  return;
233
169
  }
234
170
 
171
+ // if source excluded
235
172
  const currentSource = oSLoc.source;
236
173
  const originalMapping = originalMappings.get(currentSource);
237
174
  if (!originalMapping) {
@@ -242,16 +179,18 @@ const unpackJsSourceMap = async (item, v8list, options) => {
242
179
 
243
180
  const originalStart = originalMapping.locationToOffset(oSLoc);
244
181
 
182
+ // find end location
245
183
  const eLoc = generatedMapping.offsetToLocation(range.end);
246
- const oELoc = getOriginalEndPosition(consumer, eLoc.line, eLoc.column);
247
-
184
+ const oELoc = findOriginalEndPosition(consumer, eLoc, generatedMapping, range);
248
185
  if (!oELoc) {
249
186
 
250
- // console.log('not found end', originalMapping.sourceName, eLoc);
187
+ // console.log(EC.red('not found end'));
188
+ // console.log(item.url);
189
+ // console.log(originalMapping.sourceName);
190
+ // console.log('generated start', sLoc.line, sLoc.column, 'original start', oSLoc.line, oSLoc.column);
191
+ // console.log('generated end', eLoc.line, eLoc.column);
251
192
 
252
- // to original end
253
- const originalEnd = originalMapping.range.originalEnd;
254
- addOriginalRange(originalMapping, originalStart, originalEnd, range.count);
193
+ // can NOT use file end
255
194
 
256
195
  return;
257
196
  }
@@ -277,10 +216,13 @@ const unpackJsSourceMap = async (item, v8list, options) => {
277
216
  // append to v8list
278
217
  originalMappings.forEach((originalMapping, currentSource) => {
279
218
 
219
+ const url = urlMap[currentSource] || currentSource;
280
220
  const ranges = dedupeCountRanges(originalMapping.ranges);
281
221
 
222
+ // console.log('add source url', url);
223
+
282
224
  v8list.push({
283
- url: urlMap[currentSource],
225
+ url,
284
226
  type: item.type,
285
227
  sourcePath: currentSource,
286
228
  distFile: item.sourceMap.file,