monocart-reporter 1.7.10 → 1.7.12

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.
@@ -4,7 +4,7 @@ const Util = require('./utils/util.js');
4
4
  const { getTickInfo } = require('./utils/system.js');
5
5
  const Visitor = require('./visitor.js');
6
6
  const { calculateSummary } = require('./common.js');
7
- const { generateGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
7
+ const { addGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
8
8
  const version = require('../package.json').version;
9
9
 
10
10
  const getReportName = (options, config, metadata) => {
@@ -15,6 +15,19 @@ const getReportName = (options, config, metadata) => {
15
15
  return 'Test Report';
16
16
  };
17
17
 
18
+ const generateGlobalCoverageReport = (dataList, options) => {
19
+ const {
20
+ name, outputDir, coverage
21
+ } = options;
22
+ const coverageOptions = {
23
+ title: `Coverage Report - ${name}`,
24
+ outputDir,
25
+ outputName: 'coverage',
26
+ ... coverage
27
+ };
28
+ return addGlobalCoverageReport(dataList, coverageOptions);
29
+ };
30
+
18
31
  const artifactsHandler = async (visitor, options) => {
19
32
  const artifacts = [].concat(visitor.artifacts);
20
33
  // global artifacts
package/lib/index.d.ts CHANGED
@@ -27,10 +27,6 @@ export function attachAuditReport(
27
27
  /**
28
28
  * coverage
29
29
  */
30
- export function addCoverageReport(
31
- v8list: any[],
32
- testInfo: TestInfo
33
- ): Promise<any | void>;
34
30
 
35
31
  export type CoverageReportOptions = {
36
32
 
@@ -62,9 +58,22 @@ export type CoverageReportOptions = {
62
58
  },
63
59
 
64
60
  // Whether inline all scripts to the single HTML file.
65
- inline?: boolean
61
+ inline?: boolean,
62
+
63
+ logging?: string
66
64
  };
67
65
 
66
+ export function addCoverageReport(
67
+ v8list: any[],
68
+ testInfo: TestInfo,
69
+ options?: CoverageReportOptions
70
+ ): Promise<any | void>;
71
+
72
+ export function addGlobalCoverageReport(
73
+ dataList: any[],
74
+ options: CoverageReportOptions
75
+ ): Promise<any>;
76
+
68
77
  export function attachCoverageReport(
69
78
  coverage: any[] | any,
70
79
  testInfo: TestInfo,
package/lib/index.js CHANGED
@@ -7,7 +7,9 @@ const { getTrends } = require('./common.js');
7
7
 
8
8
  const merge = require('./merge-data.js');
9
9
  const { attachAuditReport } = require('./plugins/audit/audit.js');
10
- const { addCoverageReport, attachCoverageReport } = require('./plugins/coverage/coverage.js');
10
+ const {
11
+ addCoverageReport, addGlobalCoverageReport, attachCoverageReport
12
+ } = require('./plugins/coverage/coverage.js');
11
13
  const { attachNetworkReport } = require('./plugins/network/network.js');
12
14
 
13
15
  const { createStateServer, useState } = require('./plugins/state/state.js');
@@ -22,6 +24,7 @@ class Reporter {
22
24
  static attachAuditReport = attachAuditReport;
23
25
 
24
26
  static addCoverageReport = addCoverageReport;
27
+ static addGlobalCoverageReport = addGlobalCoverageReport;
25
28
  static attachCoverageReport = attachCoverageReport;
26
29
 
27
30
  static attachNetworkReport = attachNetworkReport;
package/lib/index.mjs CHANGED
@@ -8,6 +8,7 @@ export const merge = MonocartReporter.merge;
8
8
  export const attachAuditReport = MonocartReporter.attachAuditReport;
9
9
 
10
10
  export const addCoverageReport = MonocartReporter.addCoverageReport;
11
+ export const addGlobalCoverageReport = MonocartReporter.addGlobalCoverageReport;
11
12
  export const attachCoverageReport = MonocartReporter.attachCoverageReport;
12
13
 
13
14
  export const attachNetworkReport = MonocartReporter.attachNetworkReport;
@@ -64,8 +64,8 @@ const getSummaryReport = (lhr) => {
64
64
 
65
65
  const attachAuditReport = async (runnerResult, testInfo, options = {}) => {
66
66
 
67
- const reporterOptions = Util.resolveReporterOptions(testInfo);
68
- Util.initLoggingLevel(reporterOptions.logging, 'audit');
67
+ const logging = Util.resolveLogging(testInfo, options);
68
+ Util.initLoggingLevel(logging, 'audit');
69
69
 
70
70
  if (!runnerResult || !runnerResult.lhr || !runnerResult.report) {
71
71
  Util.logError('invalid lighthouse runner result');
@@ -74,7 +74,7 @@ const attachAuditReport = async (runnerResult, testInfo, options = {}) => {
74
74
 
75
75
  options = {
76
76
  title: `Lighthouse Report - ${testInfo.title}`,
77
- outputDir: Util.resolveOutputDir(testInfo),
77
+ outputDir: Util.resolveOutputDir(testInfo, options),
78
78
  outputName: `audit-${Util.resolveTestIdWithRetry(testInfo)}`,
79
79
  ... options
80
80
  };
@@ -116,8 +116,8 @@ const generateV8Coverage = async (v8list, testInfo, options) => {
116
116
 
117
117
  const attachCoverageReport = (data, testInfo, options = {}) => {
118
118
 
119
- const reporterOptions = Util.resolveReporterOptions(testInfo);
120
- Util.initLoggingLevel(reporterOptions.logging, 'coverage-attach');
119
+ const logging = Util.resolveLogging(testInfo, options);
120
+ Util.initLoggingLevel(logging, 'coverage-attach');
121
121
 
122
122
  if (!data) {
123
123
  Util.logError(`invalid coverage data: ${testInfo.title}`);
@@ -128,7 +128,7 @@ const attachCoverageReport = (data, testInfo, options = {}) => {
128
128
  ... defaultOptions,
129
129
  // default title
130
130
  title: `Coverage Report - ${testInfo.title}`,
131
- outputDir: Util.resolveOutputDir(testInfo),
131
+ outputDir: Util.resolveOutputDir(testInfo, options),
132
132
  outputName: `coverage-${Util.resolveTestIdWithRetry(testInfo)}`,
133
133
  ... options
134
134
  };
@@ -158,23 +158,22 @@ const attachCoverageReport = (data, testInfo, options = {}) => {
158
158
  // ========================================================================================================
159
159
 
160
160
  // add coverage report to global, v8list only
161
- const addCoverageReport = async (data, testInfo) => {
161
+ const addCoverageReport = async (data, testInfo, options = {}) => {
162
162
 
163
- const reporterOptions = Util.resolveReporterOptions(testInfo);
164
- Util.initLoggingLevel(reporterOptions.logging, 'coverage-add');
163
+ const logging = Util.resolveLogging(testInfo, options);
164
+ Util.initLoggingLevel(logging, 'coverage-add');
165
165
 
166
166
  if (!data) {
167
167
  Util.logError(`invalid coverage data: ${testInfo.title}`);
168
168
  return;
169
169
  }
170
170
 
171
- const coverageOptions = reporterOptions.coverage || {};
171
+ // global outputDir
172
+ const outputDir = await Util.resolveGlobalOutputDir(testInfo, options);
172
173
 
173
- // reporter outputFile
174
- const outputFile = await Util.resolveOutputFile(reporterOptions.outputFile);
175
- const outputDir = path.dirname(outputFile);
174
+ const coverageOptions = Util.resolveCoverageOptions(testInfo, options);
176
175
 
177
- const options = {
176
+ options = {
178
177
  ... defaultOptions,
179
178
  // use reporter dir as output dir, NOT test output dir
180
179
  outputDir,
@@ -250,20 +249,12 @@ const getGlobalCoverageData = async (dataList, options) => {
250
249
  };
251
250
 
252
251
  // global coverage report, run different process with addCoverageReport
253
- const generateGlobalCoverageReport = async (dataList, reporterOptions) => {
252
+ const addGlobalCoverageReport = async (dataList, coverageOptions) => {
254
253
 
255
254
  Util.logInfo('generating global coverage report ...');
256
255
 
257
- // reporter outputFile
258
- const outputFile = await Util.resolveOutputFile(reporterOptions.outputFile);
259
- const outputDir = path.dirname(outputFile);
260
-
261
- const coverageOptions = reporterOptions.coverage || {};
262
256
  const options = {
263
257
  ... defaultOptions,
264
- title: `Coverage Report - ${reporterOptions.name}`,
265
- outputDir,
266
- outputName: 'coverage',
267
258
  ... coverageOptions
268
259
  };
269
260
 
@@ -306,6 +297,6 @@ const generateGlobalCoverageReport = async (dataList, reporterOptions) => {
306
297
 
307
298
  module.exports = {
308
299
  addCoverageReport,
309
- generateGlobalCoverageReport,
300
+ addGlobalCoverageReport,
310
301
  attachCoverageReport
311
302
  };
@@ -120,8 +120,8 @@ const saveNetworkHtmlReport = async (reportData, _options) => {
120
120
 
121
121
  const attachNetworkReport = async (har, testInfo, options = {}) => {
122
122
 
123
- const reporterOptions = Util.resolveReporterOptions(testInfo);
124
- Util.initLoggingLevel(reporterOptions.logging, 'network');
123
+ const logging = Util.resolveLogging(testInfo, options);
124
+ Util.initLoggingLevel(logging, 'network');
125
125
 
126
126
  const harData = getHarData(har);
127
127
  if (!harData || !harData.log) {
@@ -132,7 +132,7 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
132
132
  options = {
133
133
  // default title
134
134
  title: `Network Report - ${testInfo.title}`,
135
- outputDir: Util.resolveOutputDir(testInfo),
135
+ outputDir: Util.resolveOutputDir(testInfo, options),
136
136
  outputName: `network-${Util.resolveTestIdWithRetry(testInfo)}`,
137
137
  inline: false,
138
138
  ... options