monocart-reporter 1.6.34 → 1.6.36

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
@@ -159,7 +159,11 @@ Separated metadata file (Already included in the above HTML and compressed, it c
159
159
  ## View Trace Online
160
160
  > The [Trace Viewer](https://trace.playwright.dev/) requires that the trace file must be loaded over the http:// or https:// protocols without [CORS](https://developer.mozilla.org/en-US/docs/Glossary/CORS) issue, try following start a local web server:
161
161
  ```sh
162
+ # serve and open report
162
163
  npx monocart show-report <your-outputFile-path>
164
+
165
+ # serve report
166
+ npx monocart serve-report <your-outputFile-path>
163
167
  ```
164
168
  Or customize your own trace viewer url with option `traceViewerUrl` defaults to `https://trace.playwright.dev/?trace={traceUrl}`
165
169
 
package/lib/cli.js CHANGED
@@ -35,7 +35,7 @@ const openUrl = async (p) => {
35
35
  };
36
36
 
37
37
 
38
- const showReport = async (list) => {
38
+ const serveReport = async (list, openReport) => {
39
39
  if (!list.length) {
40
40
  list.push(defaultOptions.outputFile);
41
41
  }
@@ -83,7 +83,9 @@ const showReport = async (list) => {
83
83
 
84
84
  server.listen(port, function() {
85
85
  EC.logCyan(`${new Date().toLocaleString()} server listening on ${url}`);
86
- openUrl(url);
86
+ if (openReport) {
87
+ openUrl(url);
88
+ }
87
89
  });
88
90
 
89
91
  };
@@ -93,7 +95,12 @@ const start = function() {
93
95
  const command = args.shift();
94
96
  // console.log(command, args);
95
97
  if (command === 'show-report') {
96
- showReport(args);
98
+ serveReport(args, true);
99
+ return;
100
+ }
101
+
102
+ if (command === 'serve-report') {
103
+ serveReport(args, false);
97
104
  }
98
105
  };
99
106
 
@@ -6,6 +6,7 @@ const Visitor = require('./visitor.js');
6
6
  const { calculateSummary } = require('./common.js');
7
7
  const { generateGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
8
8
  const { generateGlobalNetworkReport } = require('./plugins/network/network.js');
9
+ const version = require('../package.json').version;
9
10
 
10
11
  const getReportName = (options, config, metadata) => {
11
12
  const reportName = options.name || config.name || metadata.name;
@@ -92,6 +93,8 @@ const generateData = async (results) => {
92
93
  system.configFile = Util.relativePath(config.configFile);
93
94
  // playwright version
94
95
  system.playwright = config.version;
96
+ // monocart version
97
+ system.monocart = version;
95
98
 
96
99
  // test root dir
97
100
  system.testDir = Util.relativePath(config.rootDir);
@@ -70,13 +70,10 @@ const attachAuditReport = async (runnerResult, testInfo, options = {}) => {
70
70
  return;
71
71
  }
72
72
 
73
- const title = options.title || `Lighthouse Report - ${testInfo.title}`;
74
-
75
73
  options = {
76
- title,
74
+ title: `Lighthouse Report - ${testInfo.title}`,
77
75
  outputDir: Util.resolveOutputDir(testInfo),
78
- outputName: `audit-${Util.shortTestId(testInfo.testId)}`,
79
-
76
+ outputName: `audit-${Util.resolveTestIdWithRetry(testInfo)}`,
80
77
  ... options
81
78
  };
82
79
 
@@ -90,7 +87,7 @@ const attachAuditReport = async (runnerResult, testInfo, options = {}) => {
90
87
 
91
88
  // `.lhr` is the Lighthouse Result as a JS object
92
89
  const report = {
93
- title,
90
+ title: options.title,
94
91
  ... getSummaryReport(runnerResult.lhr)
95
92
  };
96
93
 
@@ -140,15 +140,15 @@ const attachCoverageReport = (coverageInput, testInfo, options = {}) => {
140
140
  return;
141
141
  }
142
142
 
143
- const title = options.title || `Coverage Report - ${testInfo.title}`;
144
-
145
143
  options = {
146
- title,
144
+ // default title
145
+ title: `Coverage Report - ${testInfo.title}`,
147
146
  outputDir: Util.resolveOutputDir(testInfo),
148
- outputName: `coverage-${Util.shortTestId(testInfo.testId)}`,
147
+ outputName: `coverage-${Util.resolveTestIdWithRetry(testInfo)}`,
149
148
  ... options
150
149
  };
151
150
 
151
+ // support multiple calls
152
152
  let htmlDir = path.resolve(options.outputDir, options.outputName);
153
153
  let i = 1;
154
154
  while (fs.existsSync(htmlDir)) {
@@ -200,8 +200,7 @@ const addCoverageReport = async (v8list, testInfo) => {
200
200
  const artifactsDir = path.resolve(reportDir, '.artifacts');
201
201
  options.artifactsDir = artifactsDir;
202
202
 
203
- const id = Util.shortTestId(testInfo.testId);
204
- const filename = `coverage-${id}.json`;
203
+ const filename = `coverage-${Util.resolveTestIdWithRetry(testInfo)}.json`;
205
204
  const jsonPath = path.resolve(artifactsDir, filename);
206
205
 
207
206
  // init v8list and unpack sourcemap
@@ -128,14 +128,14 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
128
128
  }
129
129
 
130
130
  options = {
131
+ // default title
132
+ title: `Network Report - ${testInfo.title}`,
131
133
  outputDir: Util.resolveOutputDir(testInfo),
132
- outputName: `network-${Util.shortTestId(testInfo.testId)}`,
134
+ outputName: `network-${Util.resolveTestIdWithRetry(testInfo)}`,
133
135
  inline: false,
134
136
  ... options
135
137
  };
136
138
 
137
- const title = options.title || `Network Report - ${testInfo.title}`;
138
-
139
139
  const htmlDir = path.resolve(options.outputDir, options.outputName);
140
140
  if (!fs.existsSync(htmlDir)) {
141
141
  fs.mkdirSync(htmlDir, {
@@ -148,7 +148,7 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
148
148
 
149
149
  // save har
150
150
  const reportData = {
151
- title,
151
+ title: options.title,
152
152
  summary,
153
153
  ... harData
154
154
  };
@@ -156,7 +156,7 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
156
156
  const htmlPath = await saveNetworkHtmlReport(reportData, options);
157
157
 
158
158
  const report = {
159
- title,
159
+ title: options.title,
160
160
  ... harData.log,
161
161
  htmlPath,
162
162
  summary