monocart-reporter 1.7.3 → 1.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 +136 -75
- package/lib/plugins/comments.js +12 -11
- package/lib/plugins/coverage/converter/converter.js +67 -68
- package/lib/plugins/coverage/converter/find-original-range.js +5 -0
- package/lib/plugins/coverage/coverage.js +46 -37
- package/lib/plugins/coverage/istanbul/istanbul.js +33 -1
- package/lib/plugins/state/state.js +27 -18
- package/lib/runtime/monocart-reporter.js +1 -1
- package/lib/{plugins/coverage/converter → utils}/decode-mappings.js +5 -5
- package/lib/utils/parse-source.js +20 -0
- package/package.json +2 -2
|
@@ -2,13 +2,14 @@ const fs = require('fs');
|
|
|
2
2
|
const path = require('path');
|
|
3
3
|
|
|
4
4
|
const Util = require('../../utils/util.js');
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
initIstanbulData, mergeIstanbulCoverage, saveIstanbulReport
|
|
7
|
+
} = require('./istanbul/istanbul.js');
|
|
6
8
|
const {
|
|
7
9
|
initV8ListAndSourcemap, mergeV8Coverage, saveV8Report
|
|
8
10
|
} = require('./v8/v8.js');
|
|
9
11
|
|
|
10
12
|
const { convertV8List } = require('./converter/converter.js');
|
|
11
|
-
const { initIstanbulSourcePath } = require('./converter/source-path.js');
|
|
12
13
|
|
|
13
14
|
const artifactsDirName = '.artifacts';
|
|
14
15
|
|
|
@@ -85,17 +86,9 @@ const saveReportAttachment = (testInfo, report, htmlDir) => {
|
|
|
85
86
|
|
|
86
87
|
// ========================================================================================================
|
|
87
88
|
|
|
88
|
-
const generateIstanbulReport = (
|
|
89
|
-
|
|
90
|
-
// force to istanbul, true is defaults to html-spa
|
|
91
|
-
if (!options.toIstanbul) {
|
|
92
|
-
options.toIstanbul = true;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const fileSources = options.fileSources || {};
|
|
96
|
-
|
|
97
|
-
coverageData = initIstanbulSourcePath(coverageData, fileSources, options.sourcePath);
|
|
89
|
+
const generateIstanbulReport = (istanbulData, testInfo, options) => {
|
|
98
90
|
|
|
91
|
+
const { coverageData, fileSources } = initIstanbulData(istanbulData, options);
|
|
99
92
|
const report = saveIstanbulReport(coverageData, fileSources, options);
|
|
100
93
|
|
|
101
94
|
saveReportAttachment(testInfo, report, options.htmlDir);
|
|
@@ -121,13 +114,13 @@ const generateV8Coverage = async (v8list, testInfo, options) => {
|
|
|
121
114
|
return report;
|
|
122
115
|
};
|
|
123
116
|
|
|
124
|
-
const attachCoverageReport = (
|
|
117
|
+
const attachCoverageReport = (data, testInfo, options = {}) => {
|
|
125
118
|
|
|
126
119
|
const reporterOptions = Util.resolveReporterOptions(testInfo);
|
|
127
120
|
Util.initLoggingLevel(reporterOptions.logging, 'coverage-attach');
|
|
128
121
|
|
|
129
|
-
if (!
|
|
130
|
-
Util.logError(
|
|
122
|
+
if (!data) {
|
|
123
|
+
Util.logError(`invalid coverage data: ${testInfo.title}`);
|
|
131
124
|
return;
|
|
132
125
|
}
|
|
133
126
|
|
|
@@ -152,23 +145,26 @@ const attachCoverageReport = (coverageInput, testInfo, options = {}) => {
|
|
|
152
145
|
Util.initDir(htmlDir);
|
|
153
146
|
options.htmlDir = htmlDir;
|
|
154
147
|
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
const dataType = Array.isArray(data) ? 'v8' : 'istanbul';
|
|
149
|
+
// console.log('data type', dataType);
|
|
150
|
+
|
|
151
|
+
if (dataType === 'v8') {
|
|
152
|
+
return generateV8Coverage(data, testInfo, options);
|
|
157
153
|
}
|
|
158
154
|
|
|
159
|
-
return generateIstanbulReport(
|
|
155
|
+
return generateIstanbulReport(data, testInfo, options);
|
|
160
156
|
};
|
|
161
157
|
|
|
162
158
|
// ========================================================================================================
|
|
163
159
|
|
|
164
160
|
// add coverage report to global, v8list only
|
|
165
|
-
const addCoverageReport = async (
|
|
161
|
+
const addCoverageReport = async (data, testInfo) => {
|
|
166
162
|
|
|
167
163
|
const reporterOptions = Util.resolveReporterOptions(testInfo);
|
|
168
164
|
Util.initLoggingLevel(reporterOptions.logging, 'coverage-add');
|
|
169
165
|
|
|
170
|
-
if (!
|
|
171
|
-
Util.logError(`invalid
|
|
166
|
+
if (!data) {
|
|
167
|
+
Util.logError(`invalid coverage data: ${testInfo.title}`);
|
|
172
168
|
return;
|
|
173
169
|
}
|
|
174
170
|
|
|
@@ -196,18 +192,19 @@ const addCoverageReport = async (v8list, testInfo) => {
|
|
|
196
192
|
const filename = `coverage-${Util.resolveTestIdWithRetry(testInfo)}.json`;
|
|
197
193
|
const jsonPath = path.resolve(artifactsDir, filename);
|
|
198
194
|
|
|
199
|
-
// init v8list and unpack sourcemap
|
|
200
|
-
const inlineSourceMap = false;
|
|
201
|
-
v8list = await initV8ListAndSourcemap(v8list, options, inlineSourceMap);
|
|
202
|
-
|
|
203
|
-
// console.log('addCoverageReport', coverageInput.map((it) => it.url));
|
|
204
|
-
|
|
205
195
|
const report = {
|
|
206
|
-
title: testInfo.title
|
|
207
|
-
// merge with data
|
|
208
|
-
data: v8list
|
|
196
|
+
title: testInfo.title
|
|
209
197
|
};
|
|
210
198
|
|
|
199
|
+
if (Array.isArray(data)) {
|
|
200
|
+
// init v8list and unpack sourcemap
|
|
201
|
+
const inlineSourceMap = false;
|
|
202
|
+
report.data = await initV8ListAndSourcemap(data, options, inlineSourceMap);
|
|
203
|
+
} else {
|
|
204
|
+
// istanbul
|
|
205
|
+
report.data = data;
|
|
206
|
+
}
|
|
207
|
+
|
|
211
208
|
const artifactContent = JSON.stringify({
|
|
212
209
|
type: 'coverage',
|
|
213
210
|
data: report
|
|
@@ -229,15 +226,27 @@ const addCoverageReport = async (v8list, testInfo) => {
|
|
|
229
226
|
|
|
230
227
|
const getGlobalCoverageData = async (dataList, options) => {
|
|
231
228
|
|
|
232
|
-
//
|
|
233
|
-
const
|
|
234
|
-
|
|
229
|
+
// get first and check v8list or istanbul data
|
|
230
|
+
const firstData = dataList[0].data;
|
|
231
|
+
const dataType = Array.isArray(firstData) ? 'v8' : 'istanbul';
|
|
232
|
+
// console.log('data type', dataType);
|
|
235
233
|
|
|
236
|
-
|
|
234
|
+
// v8list
|
|
235
|
+
if (dataType === 'v8') {
|
|
236
|
+
// merge v8list first
|
|
237
|
+
const v8list = await mergeV8Coverage(dataList, options);
|
|
238
|
+
// console.log('after merge', v8list.map((it) => it.url));
|
|
237
239
|
|
|
238
|
-
|
|
240
|
+
const { coverageData, fileSources } = await convertV8List(v8list, options);
|
|
241
|
+
return generateV8ListReport(v8list, coverageData, fileSources, options);
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// istanbul data
|
|
246
|
+
const istanbulData = mergeIstanbulCoverage(dataList, options);
|
|
247
|
+
const { coverageData, fileSources } = initIstanbulData(istanbulData, options);
|
|
248
|
+
return saveIstanbulReport(coverageData, fileSources, options);
|
|
239
249
|
|
|
240
|
-
return report;
|
|
241
250
|
};
|
|
242
251
|
|
|
243
252
|
// global coverage report, run different process with addCoverageReport
|
|
@@ -259,8 +268,8 @@ const generateGlobalCoverageReport = async (dataList, reporterOptions) => {
|
|
|
259
268
|
};
|
|
260
269
|
|
|
261
270
|
const reportDir = path.resolve(options.outputDir, options.outputName);
|
|
262
|
-
// empty dir except artifacts dir
|
|
263
271
|
|
|
272
|
+
// empty dir except artifacts dir
|
|
264
273
|
if (fs.existsSync(reportDir)) {
|
|
265
274
|
fs.readdirSync(reportDir).forEach((itemName) => {
|
|
266
275
|
if (itemName === artifactsDirName) {
|
|
@@ -8,6 +8,8 @@ const IstanbulSummary = require('./istanbul-summary.js');
|
|
|
8
8
|
|
|
9
9
|
const { istanbulLibReport, istanbulLibCoverage } = require('../../../runtime/monocart-coverage.js');
|
|
10
10
|
|
|
11
|
+
const { initIstanbulSourcePath } = require('../converter/source-path.js');
|
|
12
|
+
|
|
11
13
|
const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
12
14
|
|
|
13
15
|
const coverageMap = istanbulLibCoverage.createCoverageMap(coverageData);
|
|
@@ -96,6 +98,36 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
|
|
|
96
98
|
return report;
|
|
97
99
|
};
|
|
98
100
|
|
|
101
|
+
const mergeIstanbulCoverage = (dataList, options) => {
|
|
102
|
+
const coverageMap = istanbulLibCoverage.createCoverageMap();
|
|
103
|
+
dataList.forEach((item) => {
|
|
104
|
+
coverageMap.merge(item.data);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const istanbulData = coverageMap.toJSON();
|
|
108
|
+
|
|
109
|
+
return istanbulData;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const initIstanbulData = (istanbulData, options) => {
|
|
113
|
+
|
|
114
|
+
// force to istanbul, true is defaults to html-spa
|
|
115
|
+
if (!options.toIstanbul) {
|
|
116
|
+
options.toIstanbul = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const fileSources = options.fileSources || {};
|
|
120
|
+
|
|
121
|
+
const coverageData = initIstanbulSourcePath(istanbulData, fileSources, options.sourcePath);
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
fileSources,
|
|
125
|
+
coverageData
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
99
129
|
module.exports = {
|
|
100
|
-
saveIstanbulReport
|
|
130
|
+
saveIstanbulReport,
|
|
131
|
+
mergeIstanbulCoverage,
|
|
132
|
+
initIstanbulData
|
|
101
133
|
};
|
|
@@ -76,34 +76,41 @@ const getActions = (stateData) => {
|
|
|
76
76
|
};
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
+
const getResponseData = async (data, options) => {
|
|
80
|
+
let res;
|
|
81
|
+
// first argument is action name always
|
|
82
|
+
const action = data.shift();
|
|
83
|
+
if (action === 'send') {
|
|
84
|
+
// EC.logCyan('send', data[0]);
|
|
85
|
+
// send handler
|
|
86
|
+
if (typeof options.onReceive === 'function') {
|
|
87
|
+
res = await options.onReceive(... data);
|
|
88
|
+
}
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// get/set/remove handler
|
|
93
|
+
const actions = getActions(options.data);
|
|
94
|
+
const handler = actions[action];
|
|
95
|
+
if (handler) {
|
|
96
|
+
res = handler.apply(options, data);
|
|
97
|
+
}
|
|
98
|
+
return res;
|
|
99
|
+
};
|
|
100
|
+
|
|
79
101
|
const onMessage = async (ws, buf, options) => {
|
|
80
102
|
const message = JSON.parse(buf.toString());
|
|
81
103
|
if (!message) {
|
|
104
|
+
Util.logDebug(EC.red('invalid message buffer'));
|
|
82
105
|
return;
|
|
83
106
|
}
|
|
84
107
|
const { id, data } = message;
|
|
85
108
|
if (!id || !Array.isArray(data)) {
|
|
109
|
+
Util.logDebug(EC.red('invalid message id or data'));
|
|
86
110
|
return;
|
|
87
111
|
}
|
|
88
112
|
|
|
89
|
-
|
|
90
|
-
const action = data.shift();
|
|
91
|
-
|
|
92
|
-
let resData;
|
|
93
|
-
if (action === 'send') {
|
|
94
|
-
// send handler
|
|
95
|
-
if (typeof options.onReceive === 'function') {
|
|
96
|
-
resData = await options.onReceive(... data);
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// get/set/remove handler
|
|
100
|
-
const actions = getActions(options.data);
|
|
101
|
-
const handler = actions[action];
|
|
102
|
-
if (handler) {
|
|
103
|
-
resData = handler.apply(options, data);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
113
|
+
const resData = await getResponseData(data, options);
|
|
107
114
|
const response = JSON.stringify({
|
|
108
115
|
id,
|
|
109
116
|
data: resData
|
|
@@ -157,6 +164,8 @@ const createStateServer = (stateOptions) => {
|
|
|
157
164
|
|
|
158
165
|
wss.on('connection', (ws) => {
|
|
159
166
|
|
|
167
|
+
// Util.logDebug('a client connected');
|
|
168
|
+
|
|
160
169
|
// data {Buffer|ArrayBuffer|Buffer[]}
|
|
161
170
|
ws.on('message', (data) => {
|
|
162
171
|
// console.log(data, isBinary);
|