monocart-reporter 1.6.33 → 1.6.34
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 +46 -53
- package/lib/generate-data.js +4 -4
- package/lib/plugins/coverage/coverage-utils.js +33 -71
- package/lib/plugins/coverage/coverage.js +80 -56
- package/lib/plugins/coverage/istanbul/istanbul.js +25 -51
- package/lib/plugins/coverage/v8/dedupe.js +8 -17
- package/lib/plugins/coverage/v8/source-map.js +187 -21
- package/lib/plugins/coverage/v8/v8.js +132 -91
- package/lib/plugins/network/network.js +2 -2
- package/lib/runtime/monocart-common.js +1 -1
- package/lib/runtime/monocart-coverage.js +14 -11
- package/lib/runtime/monocart-reporter.js +1 -1
- package/lib/runtime/monocart-v8.js +1 -1
- package/lib/utils/util.js +6 -0
- package/lib/visitor.js +0 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -627,6 +627,7 @@ Attach a code coverage report with API `attachCoverageReport(data, testInfo, opt
|
|
|
627
627
|
- Istanbul only:
|
|
628
628
|
- `watermarks` (Object) Istanbul watermarks, see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report)
|
|
629
629
|
- `lcov` (Boolean) Whether to create `lcov.info`
|
|
630
|
+
- `sourcePath` (Function) source path handler, return a new source path
|
|
630
631
|
- V8 only:
|
|
631
632
|
- `toIstanbul` (Boolean) Whether to convert to Istanbul report
|
|
632
633
|
- `watermarks` (Array) Defaults to `[50, 80]`
|
|
@@ -642,30 +643,27 @@ Attach a code coverage report with API `attachCoverageReport(data, testInfo, opt
|
|
|
642
643
|
```js
|
|
643
644
|
import { test, expect } from '@playwright/test';
|
|
644
645
|
import { attachCoverageReport } from 'monocart-reporter';
|
|
645
|
-
test.describe.configure({
|
|
646
|
-
mode: 'serial'
|
|
647
|
-
});
|
|
648
|
-
let page;
|
|
649
|
-
test.describe('take Istanbul coverage', () => {
|
|
650
|
-
test('first, open page', async ({ browser }) => {
|
|
651
|
-
page = await browser.newPage();
|
|
652
|
-
await page.goto(pageUrl);
|
|
653
|
-
});
|
|
654
646
|
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
647
|
+
test('Take Istanbul coverage report', async ({ page }) => {
|
|
648
|
+
|
|
649
|
+
await page.goto('http://localhost:8090/coverage/istanbul.html');
|
|
650
|
+
|
|
651
|
+
// delay for mock code execution
|
|
652
|
+
await new Promise((resolve) => {
|
|
653
|
+
setTimeout(resolve, 500);
|
|
659
654
|
});
|
|
660
655
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
656
|
+
// take Istanbul coverage
|
|
657
|
+
const coverageData = await page.evaluate(() => window.__coverage__);
|
|
658
|
+
await page.close();
|
|
659
|
+
expect(coverageData, 'expect found Istanbul data: __coverage__').toBeTruthy();
|
|
660
|
+
|
|
661
|
+
// coverage report
|
|
662
|
+
const report = await attachCoverageReport(coverageData, test.info(), {
|
|
663
|
+
lcov: true
|
|
668
664
|
});
|
|
665
|
+
console.log(report.summary);
|
|
666
|
+
|
|
669
667
|
});
|
|
670
668
|
```
|
|
671
669
|
|
|
@@ -675,43 +673,38 @@ test.describe('take Istanbul coverage', () => {
|
|
|
675
673
|
```js
|
|
676
674
|
import { test, expect } from '@playwright/test';
|
|
677
675
|
import { attachCoverageReport } from 'monocart-reporter';
|
|
678
|
-
test.describe.configure({
|
|
679
|
-
mode: 'serial'
|
|
680
|
-
});
|
|
681
|
-
let page;
|
|
682
|
-
test.describe('take V8 coverage', () => {
|
|
683
|
-
test('first, open page', async ({ browser }) => {
|
|
684
|
-
page = await browser.newPage();
|
|
685
|
-
await Promise.all([
|
|
686
|
-
page.coverage.startJSCoverage(),
|
|
687
|
-
page.coverage.startCSSCoverage()
|
|
688
|
-
]);
|
|
689
|
-
await page.goto(pageUrl);
|
|
690
|
-
});
|
|
691
676
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
677
|
+
test('Take V8 and Istanbul coverage report', async ({ page }) => {
|
|
678
|
+
|
|
679
|
+
await Promise.all([
|
|
680
|
+
page.coverage.startJSCoverage({
|
|
681
|
+
resetOnNavigation: false
|
|
682
|
+
}),
|
|
683
|
+
page.coverage.startCSSCoverage({
|
|
684
|
+
resetOnNavigation: false
|
|
685
|
+
})
|
|
686
|
+
]);
|
|
687
|
+
|
|
688
|
+
await page.goto('http://localhost:8090/coverage/v8.html');
|
|
689
|
+
|
|
690
|
+
// delay for mock code execution
|
|
691
|
+
await new Promise((resolve) => {
|
|
692
|
+
setTimeout(resolve, 500);
|
|
696
693
|
});
|
|
697
694
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
// }
|
|
709
|
-
// });
|
|
710
|
-
expect(coverageList.length).toBeGreaterThan(0);
|
|
711
|
-
// coverage report
|
|
712
|
-
const report = await attachCoverageReport(coverageList, test.info());
|
|
713
|
-
console.log(report.summary);
|
|
695
|
+
const [jsCoverage, cssCoverage] = await Promise.all([
|
|
696
|
+
page.coverage.stopJSCoverage(),
|
|
697
|
+
page.coverage.stopCSSCoverage()
|
|
698
|
+
]);
|
|
699
|
+
await page.close();
|
|
700
|
+
|
|
701
|
+
const coverageList = [... jsCoverage, ... cssCoverage];
|
|
702
|
+
|
|
703
|
+
const v8 = await attachCoverageReport(coverageList, test.info(), {
|
|
704
|
+
excludeDistFile: false
|
|
714
705
|
});
|
|
706
|
+
console.log(v8.summary);
|
|
707
|
+
|
|
715
708
|
});
|
|
716
709
|
```
|
|
717
710
|
|
package/lib/generate-data.js
CHANGED
|
@@ -4,8 +4,8 @@ const Util = require('./utils/util.js');
|
|
|
4
4
|
const { getTickInfo } = require('./utils/system.js');
|
|
5
5
|
const Visitor = require('./visitor.js');
|
|
6
6
|
const { calculateSummary } = require('./common.js');
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
7
|
+
const { generateGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
|
|
8
|
+
const { generateGlobalNetworkReport } = require('./plugins/network/network.js');
|
|
9
9
|
|
|
10
10
|
const getReportName = (options, config, metadata) => {
|
|
11
11
|
const reportName = options.name || config.name || metadata.name;
|
|
@@ -20,11 +20,11 @@ const artifactsHandler = async (visitor, options) => {
|
|
|
20
20
|
// global artifacts
|
|
21
21
|
const { coverage, network } = visitor.artifactDataMap;
|
|
22
22
|
if (coverage) {
|
|
23
|
-
const report = await
|
|
23
|
+
const report = await generateGlobalCoverageReport(coverage, options);
|
|
24
24
|
artifacts.push(report);
|
|
25
25
|
}
|
|
26
26
|
if (network) {
|
|
27
|
-
const report = await
|
|
27
|
+
const report = await generateGlobalNetworkReport(coverage, options);
|
|
28
28
|
artifacts.push(report);
|
|
29
29
|
}
|
|
30
30
|
return artifacts;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
const Util = require('../../utils/util.js');
|
|
2
|
-
const Concurrency = require('../../platform/concurrency.js');
|
|
3
|
-
const { convertSourceMap, axios } = require('../../runtime/monocart-coverage.js');
|
|
4
2
|
|
|
5
3
|
const sortRanges = (ranges) => {
|
|
6
4
|
ranges.sort((a, b) => {
|
|
@@ -67,6 +65,8 @@ const getSourcePath = (url, index = '', type = '') => {
|
|
|
67
65
|
return filterPath(relPath);
|
|
68
66
|
};
|
|
69
67
|
|
|
68
|
+
// ========================================================================================================
|
|
69
|
+
|
|
70
70
|
const mergeSourceRoot = (sourceRoot, sourceName) => {
|
|
71
71
|
if (sourceName.startsWith(sourceRoot)) {
|
|
72
72
|
return sourceName;
|
|
@@ -74,89 +74,51 @@ const mergeSourceRoot = (sourceRoot, sourceName) => {
|
|
|
74
74
|
return sourceRoot + sourceName;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
77
|
+
const initSourceMapRootAndUrl = (sourceMap, fileUrls, fileSources) => {
|
|
78
|
+
// reset sourceRoot
|
|
79
|
+
const sourceRoot = sourceMap.sourceRoot || '';
|
|
80
|
+
sourceMap.sourceRoot = '';
|
|
81
|
+
|
|
82
|
+
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
83
|
+
const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
|
|
84
|
+
const sourcePath = getSourcePath(sourceUrl, i + 1);
|
|
85
|
+
fileUrls[sourcePath] = sourceUrl;
|
|
86
|
+
fileSources[sourcePath] = sourceMap.sourcesContent[i];
|
|
87
|
+
return sourcePath;
|
|
88
88
|
});
|
|
89
|
-
return [err, res];
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const getSourceMapUrl = (content, url) => {
|
|
93
89
|
|
|
94
|
-
|
|
95
|
-
if (!m) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
90
|
+
};
|
|
98
91
|
|
|
99
|
-
|
|
100
|
-
const r = convertSourceMap.mapFileCommentRegex.exec(comment);
|
|
101
|
-
// for some odd reason //# .. captures in 1 and /* .. */ in 2
|
|
102
|
-
const filename = r[1] || r[2];
|
|
92
|
+
// ================================================================================================
|
|
103
93
|
|
|
104
|
-
|
|
94
|
+
const convertFunctionsToRanges = (functions) => {
|
|
105
95
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
} catch (e) {
|
|
109
|
-
// console.log(e)
|
|
110
|
-
}
|
|
111
|
-
if (mapUrl) {
|
|
112
|
-
return mapUrl.toString();
|
|
96
|
+
if (!Util.isList(functions)) {
|
|
97
|
+
return [];
|
|
113
98
|
}
|
|
114
|
-
};
|
|
115
99
|
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
100
|
+
const ranges = [];
|
|
101
|
+
for (const fun of functions) {
|
|
102
|
+
if (fun.ranges) {
|
|
103
|
+
for (const range of fun.ranges) {
|
|
104
|
+
// rename startOffset/endOffset to start/end, keep count
|
|
105
|
+
ranges.push({
|
|
106
|
+
start: range.startOffset,
|
|
107
|
+
end: range.endOffset,
|
|
108
|
+
count: range.count
|
|
109
|
+
});
|
|
110
|
+
}
|
|
121
111
|
}
|
|
122
|
-
return data;
|
|
123
112
|
}
|
|
124
|
-
};
|
|
125
113
|
|
|
126
|
-
|
|
127
|
-
const concurrency = new Concurrency();
|
|
128
|
-
for (const item of v8list) {
|
|
129
|
-
// useless for css
|
|
130
|
-
if (item.type === 'css') {
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
114
|
+
sortRanges(ranges);
|
|
133
115
|
|
|
134
|
-
|
|
135
|
-
const converter = convertSourceMap.fromSource(source);
|
|
136
|
-
if (converter) {
|
|
137
|
-
item.sourceMap = resolveSourceMap(converter.sourcemap);
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const sourceMapUrl = getSourceMapUrl(source, item.url);
|
|
141
|
-
if (sourceMapUrl) {
|
|
142
|
-
item.sourceMapUrl = sourceMapUrl;
|
|
143
|
-
concurrency.addItem(item);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
await concurrency.start(async (item) => {
|
|
147
|
-
const [err, res] = await request({
|
|
148
|
-
url: item.sourceMapUrl
|
|
149
|
-
});
|
|
150
|
-
if (!err && res) {
|
|
151
|
-
item.sourceMap = resolveSourceMap(res.data);
|
|
152
|
-
}
|
|
153
|
-
});
|
|
116
|
+
return ranges;
|
|
154
117
|
};
|
|
155
118
|
|
|
156
|
-
|
|
157
119
|
module.exports = {
|
|
158
120
|
sortRanges,
|
|
159
121
|
getSourcePath,
|
|
160
|
-
|
|
161
|
-
|
|
122
|
+
initSourceMapRootAndUrl,
|
|
123
|
+
convertFunctionsToRanges
|
|
162
124
|
};
|
|
@@ -3,13 +3,9 @@ const path = require('path');
|
|
|
3
3
|
const EC = require('eight-colors');
|
|
4
4
|
|
|
5
5
|
const Util = require('../../utils/util.js');
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
convertV8ToIstanbul, mergeIstanbulList, saveIstanbulReport
|
|
9
|
-
} = require('./istanbul/istanbul.js');
|
|
10
|
-
|
|
6
|
+
const { convertV8ToIstanbul, saveIstanbulReport } = require('./istanbul/istanbul.js');
|
|
11
7
|
const {
|
|
12
|
-
|
|
8
|
+
initV8ListAndSourcemap, unpackV8List, mergeV8Coverage, saveV8Report
|
|
13
9
|
} = require('./v8/v8.js');
|
|
14
10
|
|
|
15
11
|
// ========================================================================================================
|
|
@@ -48,6 +44,9 @@ const defaultIstanbulOptions = {
|
|
|
48
44
|
unpackSourceMap: true,
|
|
49
45
|
sourceFilter: null,
|
|
50
46
|
|
|
47
|
+
// source path handler
|
|
48
|
+
sourcePath: null,
|
|
49
|
+
|
|
51
50
|
// (usually not used) source finder for Istanbul HTML report
|
|
52
51
|
sourceFinder: null,
|
|
53
52
|
|
|
@@ -101,6 +100,10 @@ const generateV8Coverage = async (v8list, testInfo, options) => {
|
|
|
101
100
|
... options
|
|
102
101
|
};
|
|
103
102
|
|
|
103
|
+
// init v8list and unpack sourcemap
|
|
104
|
+
const inlineSourceMap = true;
|
|
105
|
+
v8list = await initV8ListAndSourcemap(v8list, options, inlineSourceMap);
|
|
106
|
+
|
|
104
107
|
// ================================================================
|
|
105
108
|
|
|
106
109
|
if (options.toIstanbul) {
|
|
@@ -120,7 +123,8 @@ const generateV8Coverage = async (v8list, testInfo, options) => {
|
|
|
120
123
|
|
|
121
124
|
// ================================================================
|
|
122
125
|
|
|
123
|
-
|
|
126
|
+
// functions to ranges, and unpack source maps
|
|
127
|
+
await unpackV8List(v8list, options);
|
|
124
128
|
|
|
125
129
|
const report = await saveV8Report(v8list, options);
|
|
126
130
|
|
|
@@ -145,12 +149,17 @@ const attachCoverageReport = (coverageInput, testInfo, options = {}) => {
|
|
|
145
149
|
... options
|
|
146
150
|
};
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
152
|
+
let htmlDir = path.resolve(options.outputDir, options.outputName);
|
|
153
|
+
let i = 1;
|
|
154
|
+
while (fs.existsSync(htmlDir)) {
|
|
155
|
+
const outputName = `${options.outputName}-${i}`;
|
|
156
|
+
htmlDir = path.resolve(options.outputDir, outputName);
|
|
157
|
+
i += 1;
|
|
153
158
|
}
|
|
159
|
+
|
|
160
|
+
fs.mkdirSync(htmlDir, {
|
|
161
|
+
recursive: true
|
|
162
|
+
});
|
|
154
163
|
options.htmlDir = htmlDir;
|
|
155
164
|
|
|
156
165
|
if (Array.isArray(coverageInput)) {
|
|
@@ -162,26 +171,11 @@ const attachCoverageReport = (coverageInput, testInfo, options = {}) => {
|
|
|
162
171
|
|
|
163
172
|
// ========================================================================================================
|
|
164
173
|
|
|
165
|
-
const generateArtifactData = (v8list, options) => {
|
|
166
|
-
options = {
|
|
167
|
-
... defaultV8Options,
|
|
168
|
-
... options
|
|
169
|
-
};
|
|
170
|
-
if (options.toIstanbul) {
|
|
171
|
-
options = {
|
|
172
|
-
... defaultIstanbulOptions,
|
|
173
|
-
... options
|
|
174
|
-
};
|
|
175
|
-
return convertV8ToIstanbul(v8list, options);
|
|
176
|
-
}
|
|
177
|
-
return initV8List(v8list, options);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
174
|
// add coverage report to global, v8list only
|
|
181
|
-
const addCoverageReport = async (
|
|
175
|
+
const addCoverageReport = async (v8list, testInfo) => {
|
|
182
176
|
|
|
183
|
-
if (!
|
|
184
|
-
EC.logRed(
|
|
177
|
+
if (!Util.isList(v8list)) {
|
|
178
|
+
EC.logRed(`[MCR] invalid v8 list for test: ${testInfo.title}`);
|
|
185
179
|
return;
|
|
186
180
|
}
|
|
187
181
|
|
|
@@ -193,25 +187,34 @@ const addCoverageReport = async (coverageInput, testInfo) => {
|
|
|
193
187
|
const outputDir = path.dirname(outputFile);
|
|
194
188
|
|
|
195
189
|
const options = {
|
|
190
|
+
... defaultV8Options,
|
|
196
191
|
// use reporter dir as output dir, NOT test output dir
|
|
197
192
|
outputDir,
|
|
198
193
|
outputName: 'coverage',
|
|
199
194
|
... coverageOptions
|
|
200
195
|
};
|
|
201
196
|
|
|
197
|
+
const reportDir = path.resolve(options.outputDir, options.outputName);
|
|
198
|
+
|
|
199
|
+
// artifactsDir for temp artifact files
|
|
200
|
+
const artifactsDir = path.resolve(reportDir, '.artifacts');
|
|
201
|
+
options.artifactsDir = artifactsDir;
|
|
202
|
+
|
|
202
203
|
const id = Util.shortTestId(testInfo.testId);
|
|
203
|
-
const filename = `
|
|
204
|
-
const
|
|
205
|
-
const jsonPath = path.resolve(jsonDir, filename);
|
|
204
|
+
const filename = `coverage-${id}.json`;
|
|
205
|
+
const jsonPath = path.resolve(artifactsDir, filename);
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
// init v8list and unpack sourcemap
|
|
208
|
+
const inlineSourceMap = false;
|
|
209
|
+
v8list = await initV8ListAndSourcemap(v8list, options, inlineSourceMap);
|
|
208
210
|
|
|
209
|
-
// console.log('addCoverageReport
|
|
211
|
+
// console.log('addCoverageReport', coverageInput.map((it) => it.url));
|
|
210
212
|
|
|
211
213
|
const report = {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
data
|
|
214
|
+
// title for debug
|
|
215
|
+
title: testInfo.title,
|
|
216
|
+
// merge with data
|
|
217
|
+
data: v8list
|
|
215
218
|
};
|
|
216
219
|
|
|
217
220
|
const artifactContent = JSON.stringify({
|
|
@@ -233,34 +236,43 @@ const addCoverageReport = async (coverageInput, testInfo) => {
|
|
|
233
236
|
|
|
234
237
|
// ========================================================================================================
|
|
235
238
|
|
|
236
|
-
const
|
|
239
|
+
const getGlobalCoverageData = async (dataList, options) => {
|
|
237
240
|
|
|
238
241
|
options = {
|
|
239
242
|
... defaultV8Options,
|
|
240
243
|
... options
|
|
241
244
|
};
|
|
242
245
|
|
|
246
|
+
// merge v8list first
|
|
247
|
+
const v8list = await mergeV8Coverage(dataList, options);
|
|
248
|
+
// console.log('after merge', v8list.map((it) => it.url));
|
|
249
|
+
|
|
243
250
|
if (options.toIstanbul) {
|
|
251
|
+
|
|
244
252
|
options = {
|
|
245
253
|
... defaultIstanbulOptions,
|
|
246
254
|
... options
|
|
247
255
|
};
|
|
248
|
-
|
|
249
|
-
const { coverageData, fileSources } =
|
|
250
|
-
|
|
256
|
+
|
|
257
|
+
const { coverageData, fileSources } = await convertV8ToIstanbul(v8list, options);
|
|
258
|
+
|
|
259
|
+
const report = await saveIstanbulReport(coverageData, fileSources, options);
|
|
260
|
+
|
|
261
|
+
// console.log(report);
|
|
262
|
+
|
|
263
|
+
return report;
|
|
251
264
|
}
|
|
252
265
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
return saveV8Report(v8list, options);
|
|
266
|
+
// functions to ranges, and unpack source maps
|
|
267
|
+
await unpackV8List(v8list, options);
|
|
268
|
+
|
|
269
|
+
const report = await saveV8Report(v8list, options);
|
|
270
|
+
|
|
271
|
+
return report;
|
|
260
272
|
};
|
|
261
273
|
|
|
262
274
|
// global coverage report, run different process with addCoverageReport
|
|
263
|
-
const
|
|
275
|
+
const generateGlobalCoverageReport = async (dataList, reporterOptions) => {
|
|
264
276
|
|
|
265
277
|
// reporter outputFile
|
|
266
278
|
const outputFile = await Util.resolveOutputFile(reporterOptions.outputFile);
|
|
@@ -274,15 +286,27 @@ const generateCoverageReport = async (dataList, reporterOptions) => {
|
|
|
274
286
|
... coverageOptions
|
|
275
287
|
};
|
|
276
288
|
|
|
277
|
-
const
|
|
278
|
-
if (!fs.existsSync(
|
|
279
|
-
fs.mkdirSync(
|
|
289
|
+
const reportDir = path.resolve(options.outputDir, options.outputName);
|
|
290
|
+
if (!fs.existsSync(reportDir)) {
|
|
291
|
+
fs.mkdirSync(reportDir, {
|
|
280
292
|
recursive: true
|
|
281
293
|
});
|
|
282
294
|
}
|
|
283
|
-
options.htmlDir =
|
|
295
|
+
options.htmlDir = reportDir;
|
|
296
|
+
|
|
297
|
+
// artifactsDir for temp artifact files
|
|
298
|
+
const artifactsDir = path.resolve(reportDir, '.artifacts');
|
|
299
|
+
options.artifactsDir = artifactsDir;
|
|
284
300
|
|
|
285
|
-
const report = await
|
|
301
|
+
const report = await getGlobalCoverageData(dataList, options);
|
|
302
|
+
// console.log(report);
|
|
303
|
+
|
|
304
|
+
// =============================================================
|
|
305
|
+
// remove artifacts dir after report generated
|
|
306
|
+
if (!options.debug) {
|
|
307
|
+
Util.rmSync(artifactsDir);
|
|
308
|
+
}
|
|
309
|
+
// =============================================================
|
|
286
310
|
|
|
287
311
|
return {
|
|
288
312
|
global: true,
|
|
@@ -295,6 +319,6 @@ const generateCoverageReport = async (dataList, reporterOptions) => {
|
|
|
295
319
|
|
|
296
320
|
module.exports = {
|
|
297
321
|
addCoverageReport,
|
|
298
|
-
|
|
322
|
+
generateGlobalCoverageReport,
|
|
299
323
|
attachCoverageReport
|
|
300
324
|
};
|
|
@@ -14,18 +14,31 @@ const {
|
|
|
14
14
|
convertSourceMap
|
|
15
15
|
} = require('../../../runtime/monocart-coverage.js');
|
|
16
16
|
|
|
17
|
+
const { initSourceMapRootAndUrl } = require('../coverage-utils.js');
|
|
18
|
+
|
|
17
19
|
// const V8toIstanbul = require('v8-to-istanbul');
|
|
18
20
|
// const istanbulLibCoverage = require('istanbul-lib-coverage');
|
|
19
21
|
// const istanbulLibReport = require('istanbul-lib-report');
|
|
20
22
|
|
|
21
|
-
const {
|
|
22
|
-
getSourcePath, mergeSourceRoot, collectSourceMaps
|
|
23
|
-
} = require('../coverage-utils.js');
|
|
23
|
+
const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
24
24
|
|
|
25
|
+
// source path handler
|
|
26
|
+
let data = coverageData;
|
|
27
|
+
if (typeof options.sourcePath === 'function') {
|
|
28
|
+
data = {};
|
|
29
|
+
Object.keys(coverageData).forEach((sourcePath) => {
|
|
30
|
+
const d = coverageData[sourcePath];
|
|
31
|
+
const newSourcePath = options.sourcePath(sourcePath, fileSources);
|
|
32
|
+
if (newSourcePath) {
|
|
33
|
+
sourcePath = newSourcePath;
|
|
34
|
+
}
|
|
35
|
+
d.path = sourcePath;
|
|
36
|
+
data[sourcePath] = d;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
25
39
|
|
|
26
|
-
const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
27
40
|
|
|
28
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap(
|
|
41
|
+
const coverageMap = istanbulLibCoverage.createCoverageMap(data);
|
|
29
42
|
|
|
30
43
|
// https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report
|
|
31
44
|
const contextOptions = {
|
|
@@ -99,46 +112,15 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
|
99
112
|
|
|
100
113
|
// ===================================================================================================
|
|
101
114
|
|
|
102
|
-
const initIstanbulV8List = async (v8list, options) => {
|
|
103
|
-
|
|
104
|
-
// filter list
|
|
105
|
-
const entryFilter = options.entryFilter;
|
|
106
|
-
if (typeof entryFilter === 'function') {
|
|
107
|
-
v8list = v8list.filter(entryFilter);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// only js with source (without css)
|
|
111
|
-
v8list = v8list.filter((item) => {
|
|
112
|
-
if (typeof item.source === 'string' && item.functions) {
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// collect source maps
|
|
118
|
-
if (options.unpackSourceMap) {
|
|
119
|
-
await collectSourceMaps(v8list);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// init list properties
|
|
123
|
-
v8list.forEach((item, i) => {
|
|
124
|
-
const sourcePath = getSourcePath(item.url, i + 1, 'js');
|
|
125
|
-
const filename = path.basename(sourcePath);
|
|
126
|
-
item.filename = filename;
|
|
127
|
-
item.sourcePath = sourcePath;
|
|
128
|
-
// console.log(sourcePath);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
return v8list;
|
|
132
|
-
};
|
|
133
|
-
|
|
134
115
|
const getConversionSources = (item, fileSources) => {
|
|
116
|
+
|
|
135
117
|
const { source, sourceMap } = item;
|
|
136
118
|
|
|
137
119
|
fileSources[item.sourcePath] = source;
|
|
138
120
|
|
|
139
121
|
const sources = {
|
|
140
122
|
// remove map file
|
|
141
|
-
source: convertSourceMap.
|
|
123
|
+
source: convertSourceMap.removeComments(source)
|
|
142
124
|
};
|
|
143
125
|
|
|
144
126
|
if (!sourceMap) {
|
|
@@ -151,17 +133,8 @@ const getConversionSources = (item, fileSources) => {
|
|
|
151
133
|
// 'webpack://monocart-v8/external umd "monocart-code-viewer"'
|
|
152
134
|
// format the url to sourcePath
|
|
153
135
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
sourceMap.sourceRoot = '';
|
|
157
|
-
|
|
158
|
-
// resolve source path and add to file sources cache for html report sourceFinder
|
|
159
|
-
sourceMap.sources = sourceMap.sources.map((sourceName, i) => {
|
|
160
|
-
const sourceUrl = mergeSourceRoot(sourceRoot, sourceName);
|
|
161
|
-
const newSourceName = getSourcePath(sourceUrl, i + 1);
|
|
162
|
-
fileSources[newSourceName] = sourceMap.sourcesContent[i];
|
|
163
|
-
return newSourceName;
|
|
164
|
-
});
|
|
136
|
+
const fileUrls = {};
|
|
137
|
+
initSourceMapRootAndUrl(sourceMap, fileUrls, fileSources);
|
|
165
138
|
|
|
166
139
|
// console.log(sourceMap.sources);
|
|
167
140
|
|
|
@@ -177,7 +150,8 @@ const convertV8ToIstanbul = async (v8list, options) => {
|
|
|
177
150
|
|
|
178
151
|
// console.log('v8list before', v8list.map((it) => it.url));
|
|
179
152
|
|
|
180
|
-
|
|
153
|
+
// only js with source (without css)
|
|
154
|
+
v8list = v8list.filter((item) => item.type === 'js');
|
|
181
155
|
|
|
182
156
|
// console.log('v8list after', v8list.map((it) => it.url));
|
|
183
157
|
// console.log('has map', v8list.filter((it) => it.sourceMap));
|
|
@@ -226,7 +200,7 @@ const convertV8ToIstanbul = async (v8list, options) => {
|
|
|
226
200
|
|
|
227
201
|
const coverageData = coverageMap.toJSON();
|
|
228
202
|
|
|
229
|
-
// console.log('
|
|
203
|
+
// console.log('coverageData', Object.keys(coverageData));
|
|
230
204
|
|
|
231
205
|
return {
|
|
232
206
|
coverageData,
|