monocart-reporter 1.7.1 → 1.7.2
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 +7 -5
- package/lib/cli.js +1 -1
- package/lib/common.js +2 -3
- package/lib/default/options.js +4 -1
- package/lib/generate-data.js +2 -7
- package/lib/generate-report.js +10 -11
- package/lib/index.d.ts +2 -4
- package/lib/index.js +6 -0
- package/lib/merge-data.js +7 -6
- package/lib/plugins/audit/audit.js +4 -2
- package/lib/plugins/comments.js +2 -3
- package/lib/plugins/coverage/converter/collect-source-maps.js +194 -0
- package/lib/plugins/coverage/converter/converter.js +547 -0
- package/lib/plugins/coverage/converter/decode-mappings.js +49 -0
- package/lib/plugins/coverage/{v8 → converter}/dedupe.js +8 -1
- package/lib/plugins/coverage/converter/find-original-range.js +576 -0
- package/lib/plugins/coverage/converter/info-branch.js +30 -0
- package/lib/plugins/coverage/converter/info-function.js +29 -0
- package/lib/plugins/coverage/converter/info-line.js +20 -0
- package/lib/plugins/coverage/converter/position-mapping.js +183 -0
- package/lib/plugins/coverage/{coverage-utils.js → converter/source-path.js} +26 -42
- package/lib/plugins/coverage/coverage.js +51 -67
- package/lib/plugins/coverage/istanbul/istanbul.js +15 -174
- package/lib/plugins/coverage/v8/v8.js +22 -13
- package/lib/plugins/network/network.js +4 -13
- package/lib/plugins/state/client.js +3 -4
- package/lib/plugins/state/state.js +6 -3
- package/lib/runtime/monocart-code-viewer.js +1 -1
- package/lib/runtime/monocart-coverage.js +13 -14
- package/lib/runtime/monocart-formatter.js +1 -1
- package/lib/runtime/monocart-network.js +1 -1
- package/lib/runtime/monocart-reporter.js +1 -1
- package/lib/runtime/monocart-v8.js +1 -1
- package/lib/runtime/monocart-vendor.js +13 -13
- package/lib/utils/util.js +97 -3
- package/package.json +4 -5
- package/lib/plugins/coverage/v8/position-mapping.js +0 -92
- package/lib/plugins/coverage/v8/source-map.js +0 -451
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const EC = require('eight-colors');
|
|
4
3
|
|
|
5
4
|
const istanbulReports = require('istanbul-reports');
|
|
6
5
|
|
|
7
6
|
const Util = require('../../../utils/util.js');
|
|
8
7
|
const IstanbulSummary = require('./istanbul-summary.js');
|
|
9
8
|
|
|
10
|
-
const {
|
|
11
|
-
V8toIstanbul,
|
|
12
|
-
istanbulLibReport,
|
|
13
|
-
istanbulLibCoverage,
|
|
14
|
-
convertSourceMap
|
|
15
|
-
} = require('../../../runtime/monocart-coverage.js');
|
|
16
|
-
|
|
17
|
-
const { initSourceMapRootAndUrl } = require('../coverage-utils.js');
|
|
18
|
-
|
|
19
|
-
// const V8toIstanbul = require('v8-to-istanbul');
|
|
20
|
-
// const istanbulLibCoverage = require('istanbul-lib-coverage');
|
|
21
|
-
// const istanbulLibReport = require('istanbul-lib-report');
|
|
9
|
+
const { istanbulLibReport, istanbulLibCoverage } = require('../../../runtime/monocart-coverage.js');
|
|
22
10
|
|
|
23
11
|
const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
24
12
|
|
|
25
|
-
|
|
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 s = fileSources[sourcePath];
|
|
32
|
-
const newSourcePath = options.sourcePath(sourcePath);
|
|
33
|
-
if (newSourcePath && newSourcePath !== sourcePath) {
|
|
34
|
-
sourcePath = newSourcePath;
|
|
35
|
-
// related updates
|
|
36
|
-
fileSources[sourcePath] = s;
|
|
37
|
-
d.path = sourcePath;
|
|
38
|
-
}
|
|
39
|
-
data[sourcePath] = d;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap(data);
|
|
13
|
+
const coverageMap = istanbulLibCoverage.createCoverageMap(coverageData);
|
|
45
14
|
|
|
46
15
|
const { watermarks, defaultSummarizer } = options;
|
|
47
16
|
const istanbulOptions = {
|
|
@@ -96,16 +65,24 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
|
96
65
|
// create a context for report generation
|
|
97
66
|
const context = istanbulLibReport.createContext(contextOptions);
|
|
98
67
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
68
|
+
// html
|
|
69
|
+
if (options.toIstanbul) {
|
|
70
|
+
let reportName = 'html-spa';
|
|
71
|
+
if (options.toIstanbul === 'html') {
|
|
72
|
+
reportName = 'html';
|
|
73
|
+
}
|
|
74
|
+
const htmlReport = istanbulReports.create(reportName, {});
|
|
75
|
+
htmlReport.execute(context);
|
|
76
|
+
}
|
|
103
77
|
|
|
78
|
+
// lcov
|
|
104
79
|
if (options.lcov) {
|
|
105
80
|
const lcovReport = istanbulReports.create('lcovonly', {});
|
|
106
81
|
lcovReport.execute(context);
|
|
107
82
|
}
|
|
108
83
|
|
|
84
|
+
const htmlPath = Util.relativePath(path.resolve(options.htmlDir, 'index.html'));
|
|
85
|
+
|
|
109
86
|
// add watermarks and color
|
|
110
87
|
const coverageReport = new IstanbulSummary();
|
|
111
88
|
coverageReport.execute(context);
|
|
@@ -119,142 +96,6 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
|
119
96
|
return report;
|
|
120
97
|
};
|
|
121
98
|
|
|
122
|
-
// ===================================================================================================
|
|
123
|
-
|
|
124
|
-
const getConversionSources = (item, fileSources) => {
|
|
125
|
-
|
|
126
|
-
const { source, sourceMap } = item;
|
|
127
|
-
|
|
128
|
-
fileSources[item.sourcePath] = source;
|
|
129
|
-
|
|
130
|
-
const sources = {
|
|
131
|
-
// remove map file
|
|
132
|
-
source: convertSourceMap.removeComments(source)
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
if (!sourceMap) {
|
|
136
|
-
return sources;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// =======================================================
|
|
140
|
-
// append sourceMap
|
|
141
|
-
|
|
142
|
-
// 'webpack://monocart-v8/external umd "monocart-code-viewer"'
|
|
143
|
-
// format the url to sourcePath
|
|
144
|
-
|
|
145
|
-
const fileUrls = {};
|
|
146
|
-
initSourceMapRootAndUrl(sourceMap, fileUrls, fileSources);
|
|
147
|
-
|
|
148
|
-
// console.log(sourceMap.sources);
|
|
149
|
-
|
|
150
|
-
// =======================================================
|
|
151
|
-
sources.sourceMap = {
|
|
152
|
-
sourcemap: sourceMap
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
return sources;
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const convertV8ToIstanbul = async (v8list, options) => {
|
|
159
|
-
|
|
160
|
-
// console.log('v8list before', v8list.map((it) => it.url));
|
|
161
|
-
|
|
162
|
-
// only js with source (without css)
|
|
163
|
-
v8list = v8list.filter((item) => item.type === 'js');
|
|
164
|
-
|
|
165
|
-
// console.log('v8list after', v8list.map((it) => it.url));
|
|
166
|
-
// console.log('has map', v8list.filter((it) => it.sourceMap));
|
|
167
|
-
|
|
168
|
-
// sourceFilter to excludePath
|
|
169
|
-
const excludePath = typeof options.sourceFilter === 'function' ? (sourceName) => {
|
|
170
|
-
return !options.sourceFilter(sourceName);
|
|
171
|
-
} : () => {
|
|
172
|
-
return false;
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// file sources for istanbul html report sourceFinder in memory
|
|
176
|
-
const fileSources = {};
|
|
177
|
-
|
|
178
|
-
// https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-coverage
|
|
179
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
180
|
-
|
|
181
|
-
for (const item of v8list) {
|
|
182
|
-
|
|
183
|
-
const sources = getConversionSources(item, fileSources);
|
|
184
|
-
|
|
185
|
-
// console.log('sources', Object.keys(sources));
|
|
186
|
-
|
|
187
|
-
const v8toIstanbul = new V8toIstanbul(item.sourcePath, 0, sources, excludePath);
|
|
188
|
-
// stop resolve source path, already resolved
|
|
189
|
-
v8toIstanbul._resolveSource = (m, p) => {
|
|
190
|
-
return p;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
let failed = false;
|
|
194
|
-
await v8toIstanbul.load().catch((e) => {
|
|
195
|
-
EC.logRed(`[MCR] ${item.sourcePath} v8toIstanbul.load:`, e.message);
|
|
196
|
-
failed = true;
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
if (failed) {
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
try {
|
|
204
|
-
v8toIstanbul.applyCoverage(item.functions);
|
|
205
|
-
} catch (e) {
|
|
206
|
-
EC.logRed(`[MCR] ${item.sourcePath} v8toIstanbul.applyCoverage:`, e.message);
|
|
207
|
-
failed = true;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (failed) {
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const istanbulData = v8toIstanbul.toIstanbul();
|
|
215
|
-
// console.log('istanbulData', istanbulData);
|
|
216
|
-
|
|
217
|
-
coverageMap.merge(istanbulData);
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const coverageData = coverageMap.toJSON();
|
|
222
|
-
|
|
223
|
-
// console.log('coverageData', Object.keys(coverageData));
|
|
224
|
-
|
|
225
|
-
return {
|
|
226
|
-
coverageData,
|
|
227
|
-
fileSources
|
|
228
|
-
};
|
|
229
|
-
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
// ===================================================================================================
|
|
233
|
-
|
|
234
|
-
const mergeIstanbulList = (istanbulList) => {
|
|
235
|
-
|
|
236
|
-
const fileSources = {};
|
|
237
|
-
|
|
238
|
-
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
239
|
-
for (const item of istanbulList) {
|
|
240
|
-
Object.assign(fileSources, item.fileSources);
|
|
241
|
-
coverageMap.merge(item.coverageData);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
const coverageData = coverageMap.toJSON();
|
|
245
|
-
|
|
246
|
-
// console.log('merged data', coverageData);
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
coverageData,
|
|
250
|
-
fileSources
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
|
|
256
99
|
module.exports = {
|
|
257
|
-
saveIstanbulReport
|
|
258
|
-
convertV8ToIstanbul,
|
|
259
|
-
mergeIstanbulList
|
|
100
|
+
saveIstanbulReport
|
|
260
101
|
};
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
const EC = require('eight-colors');
|
|
2
|
-
|
|
3
1
|
const Util = require('../../../utils/util.js');
|
|
4
2
|
const { getV8Summary } = require('./v8-summary.js');
|
|
5
|
-
const { dedupeRanges } = require('
|
|
6
|
-
const { getSourcePath } = require('../
|
|
7
|
-
const { collectSourceMaps } = require('./source-map.js');
|
|
3
|
+
const { dedupeRanges } = require('../converter/dedupe.js');
|
|
4
|
+
const { getSourcePath } = require('../converter/source-path.js');
|
|
8
5
|
const { mergeScriptCovs } = require('../../../runtime/monocart-coverage.js');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// ========================================================================================================
|
|
6
|
+
const collectSourceMaps = require('../converter/collect-source-maps.js');
|
|
12
7
|
|
|
13
8
|
const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
|
|
14
9
|
|
|
@@ -30,13 +25,15 @@ const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
|
|
|
30
25
|
return true;
|
|
31
26
|
}
|
|
32
27
|
// 404 css, text will be empty
|
|
33
|
-
//
|
|
28
|
+
// Util.logError(`Invalid source: ${item.url}`);
|
|
34
29
|
// console.log(item);
|
|
35
30
|
});
|
|
36
31
|
|
|
37
32
|
|
|
38
33
|
// do not change original v8list, to work for multiple APIs
|
|
39
34
|
|
|
35
|
+
const sourcePathHandler = options.sourcePath;
|
|
36
|
+
|
|
40
37
|
// init id, sourcePath
|
|
41
38
|
v8list = v8list.map((item, i) => {
|
|
42
39
|
|
|
@@ -57,13 +54,26 @@ const initV8ListAndSourcemap = async (v8list, options, inlineSourceMap) => {
|
|
|
57
54
|
}
|
|
58
55
|
|
|
59
56
|
data.id = Util.calculateSha1(data.url + data.source);
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
let sourcePath = getSourcePath(data.url, i + 1, data.type);
|
|
59
|
+
if (typeof sourcePathHandler === 'function') {
|
|
60
|
+
const newSourcePath = sourcePathHandler(sourcePath);
|
|
61
|
+
if (typeof newSourcePath === 'string' && newSourcePath) {
|
|
62
|
+
sourcePath = newSourcePath;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
data.sourcePath = sourcePath;
|
|
61
67
|
|
|
62
68
|
return data;
|
|
63
69
|
});
|
|
64
70
|
|
|
65
71
|
// collect sourcemap first
|
|
66
|
-
|
|
72
|
+
const time_start = Date.now();
|
|
73
|
+
const count = await collectSourceMaps(v8list, options, inlineSourceMap);
|
|
74
|
+
if (count) {
|
|
75
|
+
Util.logTime(`loaded ${count} sourcemaps`, time_start);
|
|
76
|
+
}
|
|
67
77
|
|
|
68
78
|
return v8list;
|
|
69
79
|
};
|
|
@@ -146,7 +156,7 @@ const mergeV8Coverage = async (dataList, options) => {
|
|
|
146
156
|
item.source = json.source;
|
|
147
157
|
item.sourceMap = json.sourceMap;
|
|
148
158
|
} else {
|
|
149
|
-
|
|
159
|
+
Util.logError(`failed to read source: ${item.url}`);
|
|
150
160
|
item.source = '';
|
|
151
161
|
}
|
|
152
162
|
}
|
|
@@ -171,7 +181,6 @@ const saveV8HtmlReport = async (reportData, _options) => {
|
|
|
171
181
|
|
|
172
182
|
outputDir,
|
|
173
183
|
reportDataFile: 'coverage-data.js',
|
|
174
|
-
assetsName: 'assets',
|
|
175
184
|
assetsRelative: '../'
|
|
176
185
|
};
|
|
177
186
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
|
-
const EC = require('eight-colors');
|
|
4
3
|
const Util = require('../../utils/util.js');
|
|
5
4
|
|
|
6
5
|
const getHarData = (har) => {
|
|
@@ -121,9 +120,12 @@ const saveNetworkHtmlReport = async (reportData, _options) => {
|
|
|
121
120
|
|
|
122
121
|
const attachNetworkReport = async (har, testInfo, options = {}) => {
|
|
123
122
|
|
|
123
|
+
const reporterOptions = Util.resolveReporterOptions(testInfo);
|
|
124
|
+
Util.initLoggingLevel(reporterOptions.logging, 'network');
|
|
125
|
+
|
|
124
126
|
const harData = getHarData(har);
|
|
125
127
|
if (!harData || !harData.log) {
|
|
126
|
-
|
|
128
|
+
Util.logError(`failed to load HAR: ${har}`);
|
|
127
129
|
return;
|
|
128
130
|
}
|
|
129
131
|
|
|
@@ -177,17 +179,6 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
|
|
|
177
179
|
return report;
|
|
178
180
|
};
|
|
179
181
|
|
|
180
|
-
// TODO
|
|
181
|
-
const addNetworkReport = async () => {
|
|
182
|
-
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const generateGlobalNetworkReport = async () => {
|
|
186
|
-
|
|
187
|
-
};
|
|
188
|
-
|
|
189
182
|
module.exports = {
|
|
190
|
-
addNetworkReport,
|
|
191
|
-
generateGlobalNetworkReport,
|
|
192
183
|
attachNetworkReport
|
|
193
184
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const EC = require('eight-colors');
|
|
2
1
|
const { WebSocket } = require('../../runtime/monocart-vendor.js');
|
|
3
2
|
const Util = require('../../utils/util.js');
|
|
4
3
|
|
|
@@ -29,7 +28,7 @@ class Client {
|
|
|
29
28
|
});
|
|
30
29
|
this.resolves = null;
|
|
31
30
|
} else {
|
|
32
|
-
|
|
31
|
+
Util.logError(`websocket error: ${err.message}`);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
});
|
|
@@ -63,7 +62,7 @@ class Client {
|
|
|
63
62
|
reject
|
|
64
63
|
});
|
|
65
64
|
} else {
|
|
66
|
-
reject(new Error('
|
|
65
|
+
reject(new Error('an error occurs when connecting websocket server'));
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
}
|
|
@@ -108,7 +107,7 @@ class Client {
|
|
|
108
107
|
const timeout = this.options.timeout;
|
|
109
108
|
const timeout_id = setTimeout(() => {
|
|
110
109
|
this.requests.delete(id);
|
|
111
|
-
reject(new Error(`
|
|
110
|
+
reject(new Error(`timed out receiving message from websocket server: ${timeout}ms`));
|
|
112
111
|
}, timeout);
|
|
113
112
|
|
|
114
113
|
this.requests.set(id, {
|
|
@@ -40,6 +40,9 @@ const useState = (options = {}) => {
|
|
|
40
40
|
... options
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
+
// when used in global-setup will be override reporter (main process)
|
|
44
|
+
Util.initLoggingLevel(clientOptions.logging, 'state');
|
|
45
|
+
|
|
43
46
|
const clientKey = Object.keys(defaultClientOptions).map((k) => clientOptions[k]).join('-');
|
|
44
47
|
// console.log('client key', clientKey);
|
|
45
48
|
|
|
@@ -142,10 +145,10 @@ const createStateServer = (stateOptions) => {
|
|
|
142
145
|
const wss = new WebSocketServer(serverOptions);
|
|
143
146
|
|
|
144
147
|
wss.on('error', (e) => {
|
|
145
|
-
|
|
148
|
+
Util.logError(`websocket server error: ${e.message}`);
|
|
146
149
|
});
|
|
147
150
|
wss.on('wsClientError', (e) => {
|
|
148
|
-
|
|
151
|
+
Util.logError(`websocket client error: ${e.message}`);
|
|
149
152
|
});
|
|
150
153
|
|
|
151
154
|
wss.on('connection', (ws) => {
|
|
@@ -159,7 +162,7 @@ const createStateServer = (stateOptions) => {
|
|
|
159
162
|
|
|
160
163
|
wss.on('listening', () => {
|
|
161
164
|
const serverUrl = getServerUrl(serverOptions);
|
|
162
|
-
|
|
165
|
+
Util.logInfo(`state websocket server listening on ${EC.cyan(serverUrl)}`);
|
|
163
166
|
});
|
|
164
167
|
|
|
165
168
|
return {
|