monocart-reporter 2.7.1 → 2.8.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/README.md +40 -100
- package/lib/cli.js +113 -1
- package/lib/default/options.js +12 -6
- package/lib/generate-data.js +4 -14
- package/lib/generate-report.js +12 -1
- package/lib/index.d.ts +45 -33
- package/lib/index.js +29 -8
- package/lib/merge-data.js +48 -7
- package/lib/packages/monocart-reporter-vendor.js +29 -27
- package/lib/plugins/audit/audit.js +3 -1
- package/lib/plugins/coverage/coverage.js +2 -4
- package/lib/plugins/network/network.js +3 -1
- package/lib/utils/util.js +16 -18
- package/lib/visitor.js +36 -1
- package/package.json +5 -2
package/lib/index.d.ts
CHANGED
|
@@ -37,35 +37,41 @@ export interface Helper {
|
|
|
37
37
|
/** send email with nodemailer: https://nodemailer.com/ */
|
|
38
38
|
sendEmail: (emailOptions: {
|
|
39
39
|
/** email transport: https://nodemailer.com/smtp/ */
|
|
40
|
-
transport: any
|
|
40
|
+
transport: any;
|
|
41
41
|
/** email message: https://nodemailer.com/message/ */
|
|
42
|
-
message: any
|
|
42
|
+
message: any;
|
|
43
43
|
}) => Promise<void>;
|
|
44
44
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export type MonocartReporterOptions = {
|
|
48
|
+
/** logging levels: off, error, info, debug */
|
|
49
|
+
logging?: string;
|
|
50
|
+
|
|
48
51
|
/** the report name */
|
|
49
|
-
name?: string
|
|
52
|
+
name?: string;
|
|
50
53
|
|
|
51
54
|
/** the output file path (relative process.cwd) */
|
|
52
|
-
outputFile?: string
|
|
55
|
+
outputFile?: string;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* whether to copy attachments to the reporter output dir, defaults to true
|
|
59
|
+
* it is useful when there are multiple html reports being output
|
|
60
|
+
*/
|
|
61
|
+
copyAttachments?: boolean;
|
|
53
62
|
|
|
54
63
|
/** attachment path handler, for example:
|
|
55
64
|
* ```js
|
|
56
65
|
* attachmentPath: (currentPath, extras) => `https://cenfun.github.io/monocart-reporter/${currentPath}`
|
|
57
66
|
* ```
|
|
58
67
|
*/
|
|
59
|
-
attachmentPath?: (currentPath: string, extras: any) => string
|
|
68
|
+
attachmentPath?: (currentPath: string, extras: any) => string;
|
|
60
69
|
|
|
61
70
|
/** custom trace viewer url: https://github.com/cenfun/monocart-reporter?#view-trace-online */
|
|
62
|
-
traceViewerUrl?: string
|
|
63
|
-
|
|
64
|
-
/** logging levels: off, error, info, debug */
|
|
65
|
-
logging?: string,
|
|
71
|
+
traceViewerUrl?: string;
|
|
66
72
|
|
|
67
73
|
/** timezone offset in minutes, For example: GMT+0800 = -480 */
|
|
68
|
-
timezoneOffset?: number
|
|
74
|
+
timezoneOffset?: number;
|
|
69
75
|
|
|
70
76
|
/** global coverage options: https://github.com/cenfun/monocart-reporter?#code-coverage-report
|
|
71
77
|
* ```js
|
|
@@ -75,25 +81,25 @@ export type MonocartReporterOptions = {
|
|
|
75
81
|
* }
|
|
76
82
|
* ```
|
|
77
83
|
*/
|
|
78
|
-
coverage?: CoverageReportOptions
|
|
84
|
+
coverage?: CoverageReportOptions;
|
|
79
85
|
|
|
80
86
|
/** Global State Management: https://github.com/cenfun/monocart-reporter?#global-state-management */
|
|
81
87
|
state?: {
|
|
82
|
-
data?: any
|
|
88
|
+
data?: any;
|
|
83
89
|
server?: {
|
|
84
|
-
host?: string
|
|
85
|
-
port?: number
|
|
90
|
+
host?: string;
|
|
91
|
+
port?: number;
|
|
86
92
|
}
|
|
87
|
-
onReceive?: (...args: any[]) => any
|
|
88
|
-
onClose?: (data: any, config: any) => void
|
|
93
|
+
onReceive?: (...args: any[]) => any;
|
|
94
|
+
onClose?: (data: any, config: any) => void;
|
|
89
95
|
},
|
|
90
96
|
|
|
91
97
|
/** trend data handler: https://github.com/cenfun/monocart-reporter?#trend-chart
|
|
92
98
|
* ```js
|
|
93
|
-
* trend: () => './
|
|
99
|
+
* trend: () => './monocart-report/index.json'
|
|
94
100
|
* ```
|
|
95
101
|
*/
|
|
96
|
-
trend?: string | (() => Promise<string | any>)
|
|
102
|
+
trend?: string | (() => Promise<string | any>);
|
|
97
103
|
|
|
98
104
|
/** custom tags style: https://github.com/cenfun/monocart-reporter?#style-tags
|
|
99
105
|
* ```js
|
|
@@ -109,16 +115,16 @@ export type MonocartReporterOptions = {
|
|
|
109
115
|
*/
|
|
110
116
|
tags?: {
|
|
111
117
|
[key: string]: any;
|
|
112
|
-
}
|
|
118
|
+
};
|
|
113
119
|
|
|
114
120
|
/** columns data handler: https://github.com/cenfun/monocart-reporter?#style-tags */
|
|
115
|
-
columns?: (defaultColumns: any[]) => void
|
|
121
|
+
columns?: (defaultColumns: any[]) => void;
|
|
116
122
|
|
|
117
123
|
/** rows data handler (suite, case and step) https://github.com/cenfun/monocart-reporter?#custom-data-visitor */
|
|
118
|
-
visitor?: (data: any, metadata: any) => void
|
|
124
|
+
visitor?: (data: any, metadata: any) => void;
|
|
119
125
|
|
|
120
126
|
/** enable/disable custom fields in comments. Defaults to true. */
|
|
121
|
-
customFieldsInComments?: boolean
|
|
127
|
+
customFieldsInComments?: boolean;
|
|
122
128
|
|
|
123
129
|
/** mermaid options */
|
|
124
130
|
mermaid?: {
|
|
@@ -141,8 +147,14 @@ export type MonocartReporterOptions = {
|
|
|
141
147
|
merge?: boolean;
|
|
142
148
|
}
|
|
143
149
|
|
|
150
|
+
/**
|
|
151
|
+
* onData hook
|
|
152
|
+
*/
|
|
153
|
+
onData?: (reportData: any, rawData: any) => Promise<void>;
|
|
154
|
+
|
|
155
|
+
|
|
144
156
|
/** onEnd hook: https://github.com/cenfun/monocart-reporter?#onend-hook */
|
|
145
|
-
onEnd?: (reportData: any, helper: Helper) => Promise<void
|
|
157
|
+
onEnd?: (reportData: any, helper: Helper) => Promise<void>;
|
|
146
158
|
|
|
147
159
|
}
|
|
148
160
|
|
|
@@ -158,9 +170,9 @@ export function merge(
|
|
|
158
170
|
* audit
|
|
159
171
|
*/
|
|
160
172
|
export type AuditReportOptions = {
|
|
161
|
-
title?: string
|
|
162
|
-
outputDir?: string
|
|
163
|
-
outputName?: string
|
|
173
|
+
title?: string;
|
|
174
|
+
outputDir?: string;
|
|
175
|
+
outputName?: string;
|
|
164
176
|
};
|
|
165
177
|
|
|
166
178
|
export function attachAuditReport(
|
|
@@ -190,12 +202,12 @@ export function attachCoverageReport(
|
|
|
190
202
|
* network
|
|
191
203
|
*/
|
|
192
204
|
export type NetworkReportOptions = {
|
|
193
|
-
title?: string
|
|
194
|
-
outputDir?: string
|
|
195
|
-
outputName?: string
|
|
205
|
+
title?: string;
|
|
206
|
+
outputDir?: string;
|
|
207
|
+
outputName?: string;
|
|
196
208
|
|
|
197
209
|
// Whether inline all scripts to the single HTML file.
|
|
198
|
-
inline?: boolean
|
|
210
|
+
inline?: boolean;
|
|
199
211
|
};
|
|
200
212
|
|
|
201
213
|
export function attachNetworkReport(
|
|
@@ -215,9 +227,9 @@ export function setMetadata(
|
|
|
215
227
|
* state
|
|
216
228
|
*/
|
|
217
229
|
export type StateOptions = {
|
|
218
|
-
host?: string
|
|
219
|
-
port?: number
|
|
220
|
-
timeout?: number
|
|
230
|
+
host?: string;
|
|
231
|
+
port?: number;
|
|
232
|
+
timeout?: number;
|
|
221
233
|
};
|
|
222
234
|
|
|
223
235
|
export type State = {
|
package/lib/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const path = require('path');
|
|
1
2
|
const EC = require('eight-colors');
|
|
2
3
|
const { getSystemInfo, getTickInfo } = require('./utils/system.js');
|
|
3
4
|
const generateData = require('./generate-data.js');
|
|
@@ -50,16 +51,34 @@ class MonocartReporter {
|
|
|
50
51
|
this.system = getSystemInfo();
|
|
51
52
|
this.system.timestampStart = timestampStart;
|
|
52
53
|
this.system.ticks = [];
|
|
53
|
-
this.trends = [];
|
|
54
|
-
getTrends(this.options.trend).then((res) => {
|
|
55
|
-
this.trends = res;
|
|
56
|
-
});
|
|
57
54
|
|
|
58
55
|
this.tickTime = this.options.tickTime || 1000;
|
|
59
56
|
this.tickStart();
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
this.init();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async init() {
|
|
62
|
+
|
|
63
|
+
this.options.cwd = Util.formatPath(process.cwd());
|
|
64
|
+
|
|
65
|
+
// read trends from json before clean dir
|
|
66
|
+
this.trends = await getTrends(this.options.trend);
|
|
67
|
+
|
|
68
|
+
// init outputDir
|
|
69
|
+
const outputFile = await Util.resolveOutputFile(this.options.outputFile);
|
|
70
|
+
this.options.outputFile = outputFile;
|
|
71
|
+
|
|
72
|
+
const outputDir = path.dirname(outputFile);
|
|
73
|
+
|
|
74
|
+
Util.initDir(outputDir);
|
|
75
|
+
// for visitor relative path of attachments
|
|
76
|
+
this.options.outputDir = outputDir;
|
|
77
|
+
|
|
78
|
+
// init attachmentsDir
|
|
79
|
+
if (this.options.copyAttachments) {
|
|
80
|
+
this.options.attachmentsDir = path.resolve(outputDir, 'attachments');
|
|
81
|
+
}
|
|
63
82
|
|
|
64
83
|
const stateOptions = this.options.state;
|
|
65
84
|
if (stateOptions) {
|
|
@@ -119,7 +138,9 @@ class MonocartReporter {
|
|
|
119
138
|
onBegin(config, suite) {
|
|
120
139
|
this.config = config;
|
|
121
140
|
this.root = suite;
|
|
122
|
-
|
|
141
|
+
|
|
142
|
+
// output dir for test results (not reporter)
|
|
143
|
+
this.options.testOutputDir = config.projects[0].outputDir;
|
|
123
144
|
// console.log(`onBegin: ${suite.allTests().length} tests`);
|
|
124
145
|
}
|
|
125
146
|
|
|
@@ -210,7 +231,7 @@ class MonocartReporter {
|
|
|
210
231
|
trends: this.trends
|
|
211
232
|
});
|
|
212
233
|
|
|
213
|
-
return generateReport(reportData, this.options);
|
|
234
|
+
return generateReport(reportData, this.options, this.root);
|
|
214
235
|
}
|
|
215
236
|
|
|
216
237
|
}
|
package/lib/merge-data.js
CHANGED
|
@@ -33,7 +33,7 @@ const initDataList = (reportDataList) => {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// for finding attachments
|
|
36
|
-
data.jsonDir = path.dirname(item);
|
|
36
|
+
data.jsonDir = Util.relativePath(path.dirname(item));
|
|
37
37
|
|
|
38
38
|
list.push(data);
|
|
39
39
|
Util.logInfo(`report data loaded: ${item}`);
|
|
@@ -54,6 +54,17 @@ const initDataList = (reportDataList) => {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
// sort list
|
|
58
|
+
|
|
59
|
+
list.sort((a, b) => {
|
|
60
|
+
if (a.jsonDir > b.jsonDir) {
|
|
61
|
+
return 1;
|
|
62
|
+
}
|
|
63
|
+
return -1;
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// console.log(list.map((it) => it.jsonDir));
|
|
67
|
+
|
|
57
68
|
return list;
|
|
58
69
|
};
|
|
59
70
|
|
|
@@ -106,7 +117,11 @@ const mergeArtifacts = async (artifactsList, options) => {
|
|
|
106
117
|
const outputDir = options.outputDir;
|
|
107
118
|
|
|
108
119
|
const artifacts = [];
|
|
120
|
+
const coverageList = [];
|
|
109
121
|
const coverageRawList = [];
|
|
122
|
+
|
|
123
|
+
const jsonDirMap = {};
|
|
124
|
+
|
|
110
125
|
artifactsList.forEach((item) => {
|
|
111
126
|
const jsonDir = item.jsonDir;
|
|
112
127
|
let hasAssets = false;
|
|
@@ -114,13 +129,17 @@ const mergeArtifacts = async (artifactsList, options) => {
|
|
|
114
129
|
|
|
115
130
|
// merge global coverage
|
|
116
131
|
if (art.global && art.type === 'coverage') {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
132
|
+
coverageList.push({
|
|
133
|
+
jsonDir,
|
|
134
|
+
art
|
|
135
|
+
});
|
|
136
|
+
if (art.rawDir) {
|
|
137
|
+
const rawDir = path.resolve(jsonDir, art.rawDir);
|
|
138
|
+
if (fs.existsSync(rawDir)) {
|
|
139
|
+
coverageRawList.push(rawDir);
|
|
140
|
+
}
|
|
121
141
|
}
|
|
122
142
|
return;
|
|
123
|
-
|
|
124
143
|
}
|
|
125
144
|
|
|
126
145
|
const targetDirName = path.dirname(art.path);
|
|
@@ -138,15 +157,37 @@ const mergeArtifacts = async (artifactsList, options) => {
|
|
|
138
157
|
// copy assets dir
|
|
139
158
|
if (hasAssets) {
|
|
140
159
|
copyTarget('assets', jsonDir, outputDir);
|
|
160
|
+
jsonDirMap[jsonDir] = true;
|
|
141
161
|
}
|
|
142
162
|
|
|
143
163
|
});
|
|
144
164
|
|
|
165
|
+
// merge global coverage raws
|
|
145
166
|
if (coverageRawList.length) {
|
|
146
167
|
const coverage = await mergeGlobalCoverageReport(coverageRawList, options);
|
|
147
168
|
if (coverage) {
|
|
148
169
|
artifacts.push(coverage);
|
|
149
170
|
}
|
|
171
|
+
} else {
|
|
172
|
+
|
|
173
|
+
// copy single one art
|
|
174
|
+
const item = coverageList.find((it) => it.art.path);
|
|
175
|
+
if (item) {
|
|
176
|
+
const { art, jsonDir } = item;
|
|
177
|
+
|
|
178
|
+
const targetDirName = path.dirname(art.path);
|
|
179
|
+
// copy all files in art dir, like network, audit
|
|
180
|
+
copyTarget(targetDirName, jsonDir, outputDir);
|
|
181
|
+
|
|
182
|
+
if (!jsonDirMap[jsonDir]) {
|
|
183
|
+
copyTarget('assets', jsonDir, outputDir);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// update path relative to cwd/root
|
|
187
|
+
art.path = Util.relativePath(path.resolve(outputDir, art.path));
|
|
188
|
+
|
|
189
|
+
artifacts.push(art);
|
|
190
|
+
}
|
|
150
191
|
}
|
|
151
192
|
|
|
152
193
|
return artifacts;
|
|
@@ -287,6 +328,6 @@ module.exports = async (reportDataList, userOptions = {}) => {
|
|
|
287
328
|
const reportData = await mergeDataList(dataList, options);
|
|
288
329
|
// console.log(reportData.artifacts);
|
|
289
330
|
|
|
290
|
-
return generateReport(reportData, options);
|
|
331
|
+
return generateReport(reportData, options, dataList);
|
|
291
332
|
|
|
292
333
|
};
|