monocart-reporter 1.7.11 → 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.
@@ -15,12 +15,25 @@ 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
21
34
  const { coverage } = visitor.artifactDataMap;
22
35
  if (coverage) {
23
- const report = await addGlobalCoverageReport(coverage, options);
36
+ const report = await generateGlobalCoverageReport(coverage, options);
24
37
  artifacts.push(report);
25
38
  }
26
39
  return artifacts;
package/lib/index.d.ts CHANGED
@@ -27,16 +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
-
35
- // exporting for other test runner (issue #61)
36
- export function addGlobalCoverageReport(
37
- dataList: any[],
38
- reporterOptions: any
39
- ): Promise<any>;
40
30
 
41
31
  export type CoverageReportOptions = {
42
32
 
@@ -68,9 +58,22 @@ export type CoverageReportOptions = {
68
58
  },
69
59
 
70
60
  // Whether inline all scripts to the single HTML file.
71
- inline?: boolean
61
+ inline?: boolean,
62
+
63
+ logging?: string
72
64
  };
73
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
+
74
77
  export function attachCoverageReport(
75
78
  coverage: any[] | any,
76
79
  testInfo: TestInfo,
@@ -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 addGlobalCoverageReport = 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
 
@@ -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
package/lib/utils/util.js CHANGED
@@ -68,7 +68,10 @@ const Util = {
68
68
  return parsed;
69
69
  },
70
70
 
71
- resolveOutputDir: (testInfo) => {
71
+ resolveOutputDir: (testInfo, options) => {
72
+ if (options && options.outputDir) {
73
+ return options.outputDir;
74
+ }
72
75
  const outputDir = testInfo.project.outputDir || testInfo.config.outputDir;
73
76
  if (outputDir) {
74
77
  return outputDir;
@@ -76,6 +79,16 @@ const Util = {
76
79
  return path.resolve(testInfo.outputDir, '../');
77
80
  },
78
81
 
82
+ resolveGlobalOutputDir: async (testInfo, options) => {
83
+ if (options && options.outputDir) {
84
+ return options.outputDir;
85
+ }
86
+ const reporterOptions = Util.resolveReporterOptions(testInfo);
87
+ const outputFile = await Util.resolveOutputFile(reporterOptions.outputFile);
88
+ const outputDir = path.dirname(outputFile);
89
+ return outputDir;
90
+ },
91
+
79
92
  resolveOutputFile: async (outputFile) => {
80
93
  if (typeof outputFile === 'function') {
81
94
  outputFile = await outputFile();
@@ -86,6 +99,22 @@ const Util = {
86
99
  return './test-results/report.html';
87
100
  },
88
101
 
102
+ resolveLogging: (testInfo, options) => {
103
+ if (options && options.logging) {
104
+ return options.logging;
105
+ }
106
+ const reporterOptions = Util.resolveReporterOptions(testInfo);
107
+ return reporterOptions.logging;
108
+ },
109
+
110
+ resolveCoverageOptions: (testInfo, options) => {
111
+ const reporterOptions = Util.resolveReporterOptions(testInfo);
112
+ return {
113
+ ... reporterOptions.coverage,
114
+ ... options
115
+ };
116
+ },
117
+
89
118
  resolveReporterOptions: (testInfo) => {
90
119
  if (!testInfo) {
91
120
  return {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "1.7.11",
3
+ "version": "1.7.12",
4
4
  "description": "A playwright test reporter. Shows suites/cases/steps with tree style, markdown annotations, custom columns/formatters/data collection visitors, console logs, style tags, send email.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {