monocart-reporter 1.6.26 → 1.6.27

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 CHANGED
@@ -992,18 +992,11 @@ Please create an [Incoming Webhooks](https://learn.microsoft.com/en-us/microsoft
992
992
  - [weixin-webhook.js](/tests/common/weixin-webhook.js)
993
993
  - [feishu-webhook.js](/tests/common/feishu-webhook.js)
994
994
 
995
- ## Dependencies and Packages
995
+ ## Dependencies
996
996
  - UI Framework [Vue 3](https://github.com/vuejs/core)
997
997
  - Lightweight UI Components [vine-ui](https://github.com/cenfun/vine-ui)
998
998
  - High Performance Grid [turbogrid](https://github.com/cenfun/turbogrid)
999
999
  - String compress/decompress [lz-utils](https://github.com/cenfun/lz-utils)
1000
- - Packages
1001
- - `packages/app` Monocart report UI
1002
- - `packages/coverage` Coverage report libs
1003
- - `packages/network` Network HAR report libs
1004
- - `packages/v8` V8 HTML report UI
1005
- - `packages/vendor` Third-party libs
1006
-
1007
1000
 
1008
1001
  ## Contributing
1009
1002
  ```sh
@@ -1,15 +1,14 @@
1
- const fs = require('fs');
2
1
  const path = require('path');
3
2
  const EC = require('eight-colors');
4
3
  const CG = require('console-grid');
5
- const { deflateSync } = require('lz-utils');
6
4
  const { nodemailer } = require('./runtime/monocart-vendor.js');
7
5
  const Util = require('./utils/util.js');
8
6
  const emailPlugin = require('./plugins/email.js');
9
7
 
10
8
  // ===========================================================================
11
9
 
12
- const generateJson = (outputDir, filename, reportData) => {
10
+ const generateJson = (outputDir, htmlFile, reportData) => {
11
+ const filename = path.basename(htmlFile, '.html');
13
12
  let jsonPath = path.resolve(outputDir, `${filename}.json`);
14
13
  Util.writeJSONSync(jsonPath, reportData);
15
14
  jsonPath = Util.relativePath(jsonPath);
@@ -17,30 +16,22 @@ const generateJson = (outputDir, filename, reportData) => {
17
16
  return jsonPath;
18
17
  };
19
18
 
20
- const generateHtml = (outputDir, filename, reportData) => {
21
- const reportDistPath = path.resolve(__dirname, 'runtime/monocart-reporter.js');
22
- const errMsg = `Not found runtime lib: ${Util.formatPath(reportDistPath)}`;
19
+ const generateHtml = async (outputDir, htmlFile, reportData, inline) => {
23
20
 
24
- let reportJs = `console.error("${errMsg}");`;
25
- if (fs.existsSync(reportDistPath)) {
26
- reportJs = Util.readFileSync(reportDistPath);
27
- } else {
28
- EC.logRed(errMsg);
29
- }
30
-
31
- const reportDataStr = deflateSync(JSON.stringify(reportData));
32
- const content = `<script>\nwindow.reportData = '${reportDataStr}';\n${reportJs}\n</script>`;
21
+ const options = {
22
+ inline,
23
+ reportData,
24
+ jsFiles: ['monocart-common.js', 'monocart-reporter.js'],
25
+ htmlDir: outputDir,
26
+ htmlFile,
33
27
 
34
- // replace template
35
- let html = Util.getTemplate(path.resolve(__dirname, 'default/template.html'));
36
- html = Util.replace(html, {
37
- title: reportData.name,
38
- content: content
39
- });
28
+ outputDir,
29
+ reportDataFile: 'report-data.js',
30
+ assetsName: 'assets',
31
+ assetsRelative: ''
32
+ };
40
33
 
41
- let htmlPath = path.resolve(outputDir, `${filename}.html`);
42
- Util.writeFileSync(htmlPath, html);
43
- htmlPath = Util.relativePath(htmlPath);
34
+ const htmlPath = await Util.saveHtmlReport(options);
44
35
  console.log(`[MCR] html report: ${EC.cyan(htmlPath)}`);
45
36
 
46
37
  const cmd = `npx monocart show-report ${htmlPath}`;
@@ -141,7 +132,7 @@ const showTestResults = (reportData) => {
141
132
  };
142
133
 
143
134
 
144
- const generateReport = (reportData, onEnd) => {
135
+ const generateReport = async (reportData, options) => {
145
136
 
146
137
  console.log('[MCR] generating test report ...');
147
138
  showTestResults(reportData);
@@ -161,20 +152,26 @@ const generateReport = (reportData, onEnd) => {
161
152
  }
162
153
 
163
154
  // console.log(reportData);
164
- const filename = path.basename(outputFile, '.html');
155
+ const htmlFile = path.basename(outputFile);
156
+
165
157
  // generate json
166
- const jsonPath = generateJson(outputDir, filename, reportData);
158
+ const jsonPath = await generateJson(outputDir, htmlFile, reportData);
159
+
167
160
  // generate html
168
- const htmlPath = generateHtml(outputDir, filename, reportData);
161
+ let inline = true;
162
+ if (typeof options.inline === 'boolean') {
163
+ inline = options.inline;
164
+ }
165
+ const htmlPath = await generateHtml(outputDir, htmlFile, reportData, inline);
169
166
 
170
167
  // onEnd callback
168
+ const onEnd = options.onEnd;
171
169
  if (typeof onEnd !== 'function') {
172
170
  return;
173
171
  }
174
172
 
175
173
  // for onEnd after saved
176
174
  Object.assign(reportData, {
177
- filename,
178
175
  htmlPath,
179
176
  jsonPath
180
177
  });
package/lib/index.js CHANGED
@@ -131,7 +131,7 @@ class Reporter {
131
131
  trends: this.trends
132
132
  });
133
133
 
134
- return generateReport(reportData, this.options.onEnd);
134
+ return generateReport(reportData, this.options);
135
135
  }
136
136
 
137
137
  }
package/lib/merge-data.js CHANGED
@@ -178,6 +178,6 @@ module.exports = async (reportDataList, userOptions = {}) => {
178
178
 
179
179
  const reportData = await mergeDataList(dataList, options);
180
180
 
181
- return generateReport(reportData, options.onEnd);
181
+ return generateReport(reportData, options);
182
182
 
183
183
  };
@@ -132,12 +132,26 @@ const mergeV8List = async (v8list, options) => {
132
132
 
133
133
  // ============================================================
134
134
 
135
- const saveV8HtmlReport = async (reportData, options) => {
136
-
137
- const reportDataFile = 'coverage-data.js';
138
- const jsFiles = ['monocart-code-viewer.js', 'monocart-formatter.js', 'monocart-v8.js'];
135
+ const saveV8HtmlReport = async (reportData, _options) => {
136
+
137
+ const {
138
+ htmlDir, outputDir, inline
139
+ } = _options;
140
+
141
+ const options = {
142
+ inline,
143
+ reportData,
144
+ jsFiles: ['monocart-code-viewer.js', 'monocart-formatter.js', 'monocart-common.js', 'monocart-v8.js'],
145
+ htmlDir,
146
+ htmlFile: 'index.html',
147
+
148
+ outputDir,
149
+ reportDataFile: 'coverage-data.js',
150
+ assetsName: 'assets',
151
+ assetsRelative: '../'
152
+ };
139
153
 
140
- const htmlPath = await Util.saveAttachmentHtmlReport(reportData, options, reportDataFile, jsFiles);
154
+ const htmlPath = await Util.saveHtmlReport(options);
141
155
 
142
156
  return htmlPath;
143
157
  };
@@ -95,12 +95,26 @@ const getNetworkSummary = (log) => {
95
95
  return summary;
96
96
  };
97
97
 
98
- const saveNetworkHtmlReport = async (reportData, options) => {
99
-
100
- const reportDataFile = 'network-data.js';
101
- const jsFiles = ['monocart-code-viewer.js', 'monocart-formatter.js', 'monocart-network.js'];
98
+ const saveNetworkHtmlReport = async (reportData, _options) => {
99
+
100
+ const {
101
+ htmlDir, outputDir, inline
102
+ } = _options;
103
+
104
+ const options = {
105
+ inline,
106
+ reportData,
107
+ jsFiles: ['monocart-code-viewer.js', 'monocart-formatter.js', 'monocart-common.js', 'monocart-network.js'],
108
+ htmlDir,
109
+ htmlFile: 'index.html',
110
+
111
+ outputDir,
112
+ reportDataFile: 'network-data.js',
113
+ assetsName: 'assets',
114
+ assetsRelative: '../'
115
+ };
102
116
 
103
- const htmlPath = await Util.saveAttachmentHtmlReport(reportData, options, reportDataFile, jsFiles);
117
+ const htmlPath = await Util.saveHtmlReport(options);
104
118
 
105
119
  return htmlPath;
106
120
  };