monocart-reporter 1.7.11 → 1.7.13

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
@@ -646,7 +646,7 @@ Attach a coverage report to a test. Arguments:
646
646
 
647
647
  ### Coverage Options
648
648
  - `title` (String) report title.
649
- - `toIstanbul` (Boolean) Whether to convert to Istanbul report from V8 list. Defaults to `html-spa` report | (String) or using `html` report. V8 only.
649
+ - `toIstanbul` (Boolean) Whether to convert to Istanbul report from V8 list. Defaults to `html-spa` report | (String) report name | (Array) multiple reports. V8 only.
650
650
  - `entryFilter` (Function) A filter function to execute for each element in the V8 list. V8 only.
651
651
  - `sourceFilter` (Function) A filter function to execute for each element in the sources which unpacked from the source map. Sourcemap only.
652
652
  - `watermarks` (Object) Istanbul watermarks, see [here](https://github.com/istanbuljs/istanbuljs/tree/master/packages/istanbul-lib-report) | (Array) V8 watermarks, Defaults to `[50, 80]`.
@@ -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,11 @@ 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
- // exporting for other test runner (issue #61)
36
- export function addGlobalCoverageReport(
37
- dataList: any[],
38
- reporterOptions: any
39
- ): Promise<any>;
31
+ export type IstanbulReportConfig = {
32
+ name: string,
33
+ options: any
34
+ }
40
35
 
41
36
  export type CoverageReportOptions = {
42
37
 
@@ -45,7 +40,7 @@ export type CoverageReportOptions = {
45
40
  outputName?: string,
46
41
 
47
42
  // Whether to convert to Istanbul report
48
- toIstanbul?: boolean | string,
43
+ toIstanbul?: boolean | string | string[] | IstanbulReportConfig[],
49
44
 
50
45
  // A filter function to execute for each element in the V8 list.
51
46
  entryFilter?: (entry: any) => boolean,
@@ -68,9 +63,22 @@ export type CoverageReportOptions = {
68
63
  },
69
64
 
70
65
  // Whether inline all scripts to the single HTML file.
71
- inline?: boolean
66
+ inline?: boolean,
67
+
68
+ logging?: string
72
69
  };
73
70
 
71
+ export function addCoverageReport(
72
+ v8list: any[],
73
+ testInfo: TestInfo,
74
+ options?: CoverageReportOptions
75
+ ): Promise<any | void>;
76
+
77
+ export function addGlobalCoverageReport(
78
+ dataList: any[],
79
+ options: CoverageReportOptions
80
+ ): Promise<any>;
81
+
74
82
  export function attachCoverageReport(
75
83
  coverage: any[] | any,
76
84
  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
  };
@@ -20,7 +20,7 @@ const defaultOptions = {
20
20
  // outputDir
21
21
  // outputName
22
22
 
23
- // (Boolean) Whether to convert to Istanbul report from V8 list. Defaults to `html-spa` report | (String) or using `html` report
23
+ // (Boolean) Whether to convert to Istanbul report from V8 list. Defaults to `html-spa` report | (String) report name | (Array) multiple reports
24
24
  toIstanbul: false,
25
25
 
26
26
  // (Function) A filter function to execute for each element in the V8 list.
@@ -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
 
@@ -10,6 +10,41 @@ const { istanbulLibReport, istanbulLibCoverage } = require('../../../runtime/mon
10
10
 
11
11
  const { initIstanbulSourcePath } = require('../converter/source-path.js');
12
12
 
13
+ const getIstanbulReportList = (toIstanbul) => {
14
+ if (typeof toIstanbul === 'boolean') {
15
+ return [{
16
+ name: 'html-spa',
17
+ options: {}
18
+ }];
19
+ }
20
+
21
+ if (typeof toIstanbul === 'string') {
22
+ return [{
23
+ name: toIstanbul,
24
+ options: {}
25
+ }];
26
+ }
27
+
28
+ if (Array.isArray(toIstanbul)) {
29
+ return toIstanbul.map((item) => {
30
+ if (typeof item === 'string') {
31
+ return {
32
+ name: item,
33
+ options: {}
34
+ };
35
+ }
36
+ if (item && item.name) {
37
+ return item;
38
+ }
39
+ }).filter((it) => it);
40
+ }
41
+
42
+ return [{
43
+ name: 'html-spa',
44
+ options: {}
45
+ }];
46
+ };
47
+
13
48
  const saveIstanbulReport = (coverageData, fileSources, options) => {
14
49
 
15
50
  const coverageMap = istanbulLibCoverage.createCoverageMap(coverageData);
@@ -67,18 +102,21 @@ const saveIstanbulReport = (coverageData, fileSources, options) => {
67
102
  // create a context for report generation
68
103
  const context = istanbulLibReport.createContext(contextOptions);
69
104
 
70
- // html
105
+ // istanbul reports
106
+ let lcovCreated = false;
71
107
  if (options.toIstanbul) {
72
- let reportName = 'html-spa';
73
- if (options.toIstanbul === 'html') {
74
- reportName = 'html';
75
- }
76
- const htmlReport = istanbulReports.create(reportName, {});
77
- htmlReport.execute(context);
108
+ const reportList = getIstanbulReportList(options.toIstanbul);
109
+ reportList.forEach((item) => {
110
+ if (item.name === 'lcovonly') {
111
+ lcovCreated = true;
112
+ }
113
+ const report = istanbulReports.create(item.name, item.options || {});
114
+ report.execute(context);
115
+ });
78
116
  }
79
117
 
80
118
  // lcov
81
- if (options.lcov) {
119
+ if (!lcovCreated && options.lcov) {
82
120
  const lcovReport = istanbulReports.create('lcovonly', {});
83
121
  lcovReport.execute(context);
84
122
  }
@@ -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.13",
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": {