monocart-coverage-reports 2.5.9 → 2.6.0
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/LICENSE +21 -21
- package/README.md +787 -778
- package/lib/cli.js +215 -215
- package/lib/converter/ast-visitor.js +675 -666
- package/lib/converter/ast.js +353 -353
- package/lib/converter/collect-source-maps.js +201 -201
- package/lib/converter/converter.js +1487 -1429
- package/lib/converter/find-original-range.js +737 -737
- package/lib/converter/ignore.js +163 -163
- package/lib/converter/info-branch.js +93 -93
- package/lib/converter/info-function.js +63 -63
- package/lib/converter/info-statement.js +43 -43
- package/lib/default/options.js +84 -84
- package/lib/default/template.html +47 -47
- package/lib/generate.js +720 -532
- package/lib/index.d.ts +360 -324
- package/lib/index.js +183 -180
- package/lib/index.mjs +5 -3
- package/lib/istanbul/istanbul-summary.js +70 -63
- package/lib/istanbul/istanbul.js +146 -146
- package/lib/packages/monocart-coverage-v8.js +1 -1
- package/lib/platform/concurrency.js +74 -74
- package/lib/platform/share.js +484 -484
- package/lib/utils/dedupe.js +118 -118
- package/lib/utils/request.js +62 -62
- package/lib/utils/snapshot.js +381 -0
- package/lib/utils/source-path.js +179 -179
- package/lib/utils/util.js +526 -526
- package/lib/v8/v8-summary.js +138 -138
- package/lib/v8/v8.js +399 -630
- package/package.json +81 -80
package/lib/istanbul/istanbul.js
CHANGED
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const istanbulReports = require('istanbul-reports');
|
|
4
|
-
const istanbulLibCoverage = require('istanbul-lib-coverage');
|
|
5
|
-
const istanbulLibReport = require('istanbul-lib-report');
|
|
6
|
-
|
|
7
|
-
const Util = require('../utils/util.js');
|
|
8
|
-
const IstanbulSummary = require('./istanbul-summary.js');
|
|
9
|
-
|
|
10
|
-
const { getSourcePathHandler, initIstanbulSourcePath } = require('../utils/source-path.js');
|
|
11
|
-
|
|
12
|
-
const findHtmlPath = (outputDir) => {
|
|
13
|
-
const defaultHtml = path.resolve(outputDir, 'index.html');
|
|
14
|
-
if (fs.existsSync(defaultHtml)) {
|
|
15
|
-
return defaultHtml;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const htmlList = [];
|
|
19
|
-
Util.forEachFile(outputDir, ['.html'], (name, dir) => {
|
|
20
|
-
const htmlPath = path.resolve(dir, name);
|
|
21
|
-
if (name === 'index.html') {
|
|
22
|
-
htmlList.unshift(htmlPath);
|
|
23
|
-
return 'break';
|
|
24
|
-
}
|
|
25
|
-
htmlList.push(htmlPath);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (htmlList.length) {
|
|
29
|
-
return htmlList[0];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return defaultHtml;
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const saveIstanbulReports = (coverageData, fileSources, options) => {
|
|
37
|
-
|
|
38
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap(coverageData);
|
|
39
|
-
|
|
40
|
-
const defaultWatermarks = {
|
|
41
|
-
statements: [50, 80],
|
|
42
|
-
branches: [50, 80],
|
|
43
|
-
functions: [50, 80],
|
|
44
|
-
lines: [50, 80]
|
|
45
|
-
};
|
|
46
|
-
const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);
|
|
47
|
-
|
|
48
|
-
// https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report
|
|
49
|
-
|
|
50
|
-
// defaultSummarizer and sourceFinder can be passed from options
|
|
51
|
-
const contextOptions = {
|
|
52
|
-
coverageMap,
|
|
53
|
-
// The summarizer to default to (may be overridden by some reports)
|
|
54
|
-
// values can be nested/flat/pkg. Defaults to 'pkg'
|
|
55
|
-
defaultSummarizer: options.defaultSummarizer || 'nested',
|
|
56
|
-
|
|
57
|
-
dir: options.outputDir,
|
|
58
|
-
watermarks,
|
|
59
|
-
sourceFinder: (filePath) => {
|
|
60
|
-
|
|
61
|
-
// console.log(`find file source: ${filePath}`);
|
|
62
|
-
|
|
63
|
-
if (fileSources) {
|
|
64
|
-
const source = fileSources[filePath];
|
|
65
|
-
if (source) {
|
|
66
|
-
return source;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (typeof options.sourceFinder === 'function') {
|
|
71
|
-
const source = options.sourceFinder(filePath);
|
|
72
|
-
if (source) {
|
|
73
|
-
return source;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (fs.existsSync(filePath)) {
|
|
78
|
-
return fs.readFileSync(filePath, 'utf8');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// console.log('Not found source file:', filePath);
|
|
82
|
-
|
|
83
|
-
return `Not found source file: ${filePath}`;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// create a context for report generation
|
|
88
|
-
const context = istanbulLibReport.createContext(contextOptions);
|
|
89
|
-
|
|
90
|
-
const istanbulGroup = options.reportGroup.istanbul;
|
|
91
|
-
Object.keys(istanbulGroup).forEach((reportName) => {
|
|
92
|
-
const reportOptions = istanbulGroup[reportName];
|
|
93
|
-
const report = istanbulReports.create(reportName, reportOptions);
|
|
94
|
-
report.execute(context);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// add watermarks and color
|
|
98
|
-
const coverageReport = new IstanbulSummary();
|
|
99
|
-
coverageReport.execute(context);
|
|
100
|
-
|
|
101
|
-
const reportPath = Util.resolveReportPath(options, () => {
|
|
102
|
-
// find first index.html path for preview
|
|
103
|
-
const htmlPath = findHtmlPath(options.outputDir);
|
|
104
|
-
return Util.relativePath(htmlPath);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
const coverageResults = {
|
|
108
|
-
type: 'istanbul',
|
|
109
|
-
reportPath,
|
|
110
|
-
name: options.name,
|
|
111
|
-
watermarks: contextOptions.watermarks,
|
|
112
|
-
// summary and files
|
|
113
|
-
... coverageReport.getReport()
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
return coverageResults;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const mergeIstanbulCoverage = (dataList) => {
|
|
120
|
-
const istanbulCoverageList = dataList.map((it) => it.data);
|
|
121
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
122
|
-
istanbulCoverageList.forEach((coverage) => {
|
|
123
|
-
coverageMap.merge(coverage);
|
|
124
|
-
});
|
|
125
|
-
const istanbulData = coverageMap.toJSON();
|
|
126
|
-
return istanbulData;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const initIstanbulData = (istanbulData, options) => {
|
|
130
|
-
|
|
131
|
-
const fileSources = options.fileSources || {};
|
|
132
|
-
const sourcePathHandler = getSourcePathHandler(options);
|
|
133
|
-
|
|
134
|
-
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);
|
|
135
|
-
|
|
136
|
-
return {
|
|
137
|
-
fileSources,
|
|
138
|
-
coverageData
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
module.exports = {
|
|
143
|
-
saveIstanbulReports,
|
|
144
|
-
mergeIstanbulCoverage,
|
|
145
|
-
initIstanbulData
|
|
146
|
-
};
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const istanbulReports = require('istanbul-reports');
|
|
4
|
+
const istanbulLibCoverage = require('istanbul-lib-coverage');
|
|
5
|
+
const istanbulLibReport = require('istanbul-lib-report');
|
|
6
|
+
|
|
7
|
+
const Util = require('../utils/util.js');
|
|
8
|
+
const IstanbulSummary = require('./istanbul-summary.js');
|
|
9
|
+
|
|
10
|
+
const { getSourcePathHandler, initIstanbulSourcePath } = require('../utils/source-path.js');
|
|
11
|
+
|
|
12
|
+
const findHtmlPath = (outputDir) => {
|
|
13
|
+
const defaultHtml = path.resolve(outputDir, 'index.html');
|
|
14
|
+
if (fs.existsSync(defaultHtml)) {
|
|
15
|
+
return defaultHtml;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const htmlList = [];
|
|
19
|
+
Util.forEachFile(outputDir, ['.html'], (name, dir) => {
|
|
20
|
+
const htmlPath = path.resolve(dir, name);
|
|
21
|
+
if (name === 'index.html') {
|
|
22
|
+
htmlList.unshift(htmlPath);
|
|
23
|
+
return 'break';
|
|
24
|
+
}
|
|
25
|
+
htmlList.push(htmlPath);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (htmlList.length) {
|
|
29
|
+
return htmlList[0];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return defaultHtml;
|
|
33
|
+
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const saveIstanbulReports = (coverageData, fileSources, options) => {
|
|
37
|
+
|
|
38
|
+
const coverageMap = istanbulLibCoverage.createCoverageMap(coverageData);
|
|
39
|
+
|
|
40
|
+
const defaultWatermarks = {
|
|
41
|
+
statements: [50, 80],
|
|
42
|
+
branches: [50, 80],
|
|
43
|
+
functions: [50, 80],
|
|
44
|
+
lines: [50, 80]
|
|
45
|
+
};
|
|
46
|
+
const watermarks = Util.resolveWatermarks(defaultWatermarks, options.watermarks);
|
|
47
|
+
|
|
48
|
+
// https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report
|
|
49
|
+
|
|
50
|
+
// defaultSummarizer and sourceFinder can be passed from options
|
|
51
|
+
const contextOptions = {
|
|
52
|
+
coverageMap,
|
|
53
|
+
// The summarizer to default to (may be overridden by some reports)
|
|
54
|
+
// values can be nested/flat/pkg. Defaults to 'pkg'
|
|
55
|
+
defaultSummarizer: options.defaultSummarizer || 'nested',
|
|
56
|
+
|
|
57
|
+
dir: options.outputDir,
|
|
58
|
+
watermarks,
|
|
59
|
+
sourceFinder: (filePath) => {
|
|
60
|
+
|
|
61
|
+
// console.log(`find file source: ${filePath}`);
|
|
62
|
+
|
|
63
|
+
if (fileSources) {
|
|
64
|
+
const source = fileSources[filePath];
|
|
65
|
+
if (source) {
|
|
66
|
+
return source;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (typeof options.sourceFinder === 'function') {
|
|
71
|
+
const source = options.sourceFinder(filePath);
|
|
72
|
+
if (source) {
|
|
73
|
+
return source;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (fs.existsSync(filePath)) {
|
|
78
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// console.log('Not found source file:', filePath);
|
|
82
|
+
|
|
83
|
+
return `Not found source file: ${filePath}`;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// create a context for report generation
|
|
88
|
+
const context = istanbulLibReport.createContext(contextOptions);
|
|
89
|
+
|
|
90
|
+
const istanbulGroup = options.reportGroup.istanbul;
|
|
91
|
+
Object.keys(istanbulGroup).forEach((reportName) => {
|
|
92
|
+
const reportOptions = istanbulGroup[reportName];
|
|
93
|
+
const report = istanbulReports.create(reportName, reportOptions);
|
|
94
|
+
report.execute(context);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// add watermarks and color
|
|
98
|
+
const coverageReport = new IstanbulSummary();
|
|
99
|
+
coverageReport.execute(context);
|
|
100
|
+
|
|
101
|
+
const reportPath = Util.resolveReportPath(options, () => {
|
|
102
|
+
// find first index.html path for preview
|
|
103
|
+
const htmlPath = findHtmlPath(options.outputDir);
|
|
104
|
+
return Util.relativePath(htmlPath);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const coverageResults = {
|
|
108
|
+
type: 'istanbul',
|
|
109
|
+
reportPath,
|
|
110
|
+
name: options.name,
|
|
111
|
+
watermarks: contextOptions.watermarks,
|
|
112
|
+
// summary and files
|
|
113
|
+
... coverageReport.getReport()
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
return coverageResults;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const mergeIstanbulCoverage = (dataList) => {
|
|
120
|
+
const istanbulCoverageList = dataList.map((it) => it.data);
|
|
121
|
+
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
122
|
+
istanbulCoverageList.forEach((coverage) => {
|
|
123
|
+
coverageMap.merge(coverage);
|
|
124
|
+
});
|
|
125
|
+
const istanbulData = coverageMap.toJSON();
|
|
126
|
+
return istanbulData;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const initIstanbulData = (istanbulData, options) => {
|
|
130
|
+
|
|
131
|
+
const fileSources = options.fileSources || {};
|
|
132
|
+
const sourcePathHandler = getSourcePathHandler(options);
|
|
133
|
+
|
|
134
|
+
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, sourcePathHandler);
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
fileSources,
|
|
138
|
+
coverageData
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
module.exports = {
|
|
143
|
+
saveIstanbulReports,
|
|
144
|
+
mergeIstanbulCoverage,
|
|
145
|
+
initIstanbulData
|
|
146
|
+
};
|