monocart-reporter 2.9.6 → 2.9.8

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.
@@ -1,169 +1,169 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const MCR = require('monocart-coverage-reports');
4
- const Util = require('../../utils/util.js');
5
-
6
- const attachCoverageReport = async (data, testInfo, options = {}) => {
7
-
8
- const outputDir = Util.resolveOutputDir(testInfo);
9
- const folderName = `coverage-${Util.resolveTestIdWithRetry(testInfo)}`;
10
-
11
- // support multiple calls
12
- let outputName = folderName;
13
- let htmlDir = path.resolve(outputDir, outputName);
14
- let i = 0;
15
- while (fs.existsSync(htmlDir)) {
16
- i += 1;
17
- outputName = `${folderName}-${i}`;
18
- htmlDir = path.resolve(outputDir, outputName);
19
- }
20
-
21
- const coverageOptions = {
22
- logging: Util.resolveLogging(testInfo, options),
23
- outputDir: htmlDir,
24
- name: `Coverage Report - ${testInfo.title}`,
25
- assetsPath: '../assets',
26
- ... options
27
- };
28
-
29
- const coverageReport = MCR(coverageOptions);
30
- await coverageReport.add(data);
31
- const coverageResults = await coverageReport.generate();
32
-
33
- const reportPath = coverageResults.reportPath;
34
- if (reportPath && fs.existsSync(reportPath)) {
35
- // save report json
36
- const definition = Util.attachments.coverage;
37
- const reportJsonPath = path.resolve(htmlDir, definition.reportFile);
38
- // only for summary, clean useless data
39
- const coverageSummary = {
40
- type: coverageResults.type,
41
- name: coverageResults.name,
42
- // requires summary
43
- summary: coverageResults.summary,
44
- // only requires files count
45
- files: coverageResults.files.length
46
- };
47
- Util.writeJSONSync(reportJsonPath, coverageSummary);
48
-
49
- // save attachments html link
50
- testInfo.attachments.push({
51
- name: definition.name,
52
- contentType: definition.contentType,
53
- path: reportPath
54
- });
55
- }
56
-
57
- return coverageResults;
58
- };
59
-
60
- // ========================================================================================================
61
-
62
- const getGlobalCoverageOptions = (reporterOptions) => {
63
-
64
- const reporterOutputFile = Util.resolveOutputFile(reporterOptions.outputFile);
65
- const outputDir = path.dirname(reporterOutputFile);
66
- const htmlDir = path.resolve(outputDir, 'coverage');
67
-
68
- const coverageOptions = {
69
- logging: reporterOptions.logging,
70
- outputDir: htmlDir,
71
- name: `Coverage Report - ${reporterOptions.name}`,
72
- assetsPath: '../assets',
73
- // merge all global coverage options
74
- ... reporterOptions.coverage
75
- };
76
-
77
- return coverageOptions;
78
- };
79
-
80
- // add coverage report to global, v8list only
81
- const addCoverageReport = async (data, testInfo) => {
82
-
83
- const reporterOptions = Util.resolveReporterOptions(testInfo);
84
- const coverageOptions = getGlobalCoverageOptions(reporterOptions);
85
-
86
- const coverageReport = MCR(coverageOptions);
87
- const results = await coverageReport.add(data);
88
-
89
- return results;
90
- };
91
-
92
- const generateGlobalCoverageReport = async (reporterOptions) => {
93
-
94
- const coverageOptions = getGlobalCoverageOptions(reporterOptions);
95
-
96
- const coverageReport = MCR(coverageOptions);
97
-
98
- // check if has cache
99
- if (!coverageReport.hasCache()) {
100
- return;
101
- }
102
-
103
- const coverageResults = await coverageReport.generate();
104
- if (!coverageResults) {
105
- return;
106
- }
107
-
108
- // coverageResults: type, reportPath, name, watermarks, summary, files
109
- // showing list props: global, name, path, title
110
-
111
- // there is no reportPath if only raw
112
- const reportPath = coverageResults.reportPath;
113
-
114
- const artifact = {
115
- global: true,
116
- type: 'coverage',
117
- name: coverageResults.name,
118
- path: reportPath
119
- };
120
-
121
- const reports = {};
122
- const { reportGroup, outputDir } = coverageReport.options;
123
- if (reportGroup) {
124
- reportGroup.forEach((group) => {
125
- group.forEach((o, k) => {
126
- reports[k] = o;
127
- });
128
- });
129
- }
130
-
131
- if (reports.raw) {
132
- let rawDir = path.resolve(outputDir, reports.raw.outputDir || 'raw');
133
- if (reports.raw.zip) {
134
- rawDir += '.zip';
135
- }
136
- artifact.rawDir = Util.relativePath(rawDir, reporterOptions.outputDir);
137
- }
138
-
139
- return artifact;
140
- };
141
-
142
- const mergeGlobalCoverageReport = async (coverageRawList, reporterOptions) => {
143
- const coverageOptions = getGlobalCoverageOptions(reporterOptions);
144
- coverageOptions.inputDir = coverageRawList;
145
-
146
- const coverageReport = MCR(coverageOptions);
147
- const coverageResults = await coverageReport.generate();
148
- if (!coverageResults) {
149
- return;
150
- }
151
-
152
- const reportPath = coverageResults.reportPath;
153
- if (reportPath && fs.existsSync(reportPath)) {
154
- return {
155
- global: true,
156
- type: 'coverage',
157
- name: coverageResults.name,
158
- path: reportPath
159
- };
160
- }
161
-
162
- };
163
-
164
- module.exports = {
165
- addCoverageReport,
166
- attachCoverageReport,
167
- generateGlobalCoverageReport,
168
- mergeGlobalCoverageReport
169
- };
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const MCR = require('monocart-coverage-reports');
4
+ const Util = require('../../utils/util.js');
5
+
6
+ const attachCoverageReport = async (data, testInfo, options = {}) => {
7
+
8
+ const outputDir = Util.resolveOutputDir(testInfo);
9
+ const folderName = `coverage-${Util.resolveTestIdWithRetry(testInfo)}`;
10
+
11
+ // support multiple calls
12
+ let outputName = folderName;
13
+ let htmlDir = path.resolve(outputDir, outputName);
14
+ let i = 0;
15
+ while (fs.existsSync(htmlDir)) {
16
+ i += 1;
17
+ outputName = `${folderName}-${i}`;
18
+ htmlDir = path.resolve(outputDir, outputName);
19
+ }
20
+
21
+ const coverageOptions = {
22
+ logging: Util.resolveLogging(testInfo, options),
23
+ outputDir: htmlDir,
24
+ name: `Coverage Report - ${testInfo.title}`,
25
+ assetsPath: '../assets',
26
+ ... options
27
+ };
28
+
29
+ const coverageReport = MCR(coverageOptions);
30
+ await coverageReport.add(data);
31
+ const coverageResults = await coverageReport.generate();
32
+
33
+ const reportPath = coverageResults.reportPath;
34
+ if (reportPath && fs.existsSync(reportPath)) {
35
+ // save report json
36
+ const definition = Util.attachments.coverage;
37
+ const reportJsonPath = path.resolve(htmlDir, definition.reportFile);
38
+ // only for summary, clean useless data
39
+ const coverageSummary = {
40
+ type: coverageResults.type,
41
+ name: coverageResults.name,
42
+ // requires summary
43
+ summary: coverageResults.summary,
44
+ // only requires files count
45
+ files: coverageResults.files.length
46
+ };
47
+ Util.writeJSONSync(reportJsonPath, coverageSummary);
48
+
49
+ // save attachments html link
50
+ testInfo.attachments.push({
51
+ name: definition.name,
52
+ contentType: definition.contentType,
53
+ path: reportPath
54
+ });
55
+ }
56
+
57
+ return coverageResults;
58
+ };
59
+
60
+ // ========================================================================================================
61
+
62
+ const getGlobalCoverageOptions = (reporterOptions) => {
63
+
64
+ const reporterOutputFile = Util.resolveOutputFile(reporterOptions.outputFile);
65
+ const outputDir = path.dirname(reporterOutputFile);
66
+ const htmlDir = path.resolve(outputDir, 'coverage');
67
+
68
+ const coverageOptions = {
69
+ logging: reporterOptions.logging,
70
+ outputDir: htmlDir,
71
+ name: `Coverage Report - ${reporterOptions.name}`,
72
+ assetsPath: '../assets',
73
+ // merge all global coverage options
74
+ ... reporterOptions.coverage
75
+ };
76
+
77
+ return coverageOptions;
78
+ };
79
+
80
+ // add coverage report to global, v8list only
81
+ const addCoverageReport = async (data, testInfo) => {
82
+
83
+ const reporterOptions = Util.resolveReporterOptions(testInfo);
84
+ const coverageOptions = getGlobalCoverageOptions(reporterOptions);
85
+
86
+ const coverageReport = MCR(coverageOptions);
87
+ const results = await coverageReport.add(data);
88
+
89
+ return results;
90
+ };
91
+
92
+ const generateGlobalCoverageReport = async (reporterOptions) => {
93
+
94
+ const coverageOptions = getGlobalCoverageOptions(reporterOptions);
95
+
96
+ const coverageReport = MCR(coverageOptions);
97
+
98
+ // check if has cache
99
+ if (!coverageReport.hasCache()) {
100
+ return;
101
+ }
102
+
103
+ const coverageResults = await coverageReport.generate();
104
+ if (!coverageResults) {
105
+ return;
106
+ }
107
+
108
+ // coverageResults: type, reportPath, name, watermarks, summary, files
109
+ // showing list props: global, name, path, title
110
+
111
+ // there is no reportPath if only raw
112
+ const reportPath = coverageResults.reportPath;
113
+
114
+ const artifact = {
115
+ global: true,
116
+ type: 'coverage',
117
+ name: coverageResults.name,
118
+ path: reportPath
119
+ };
120
+
121
+ const reports = {};
122
+ const { reportGroup, outputDir } = coverageReport.options;
123
+ if (reportGroup) {
124
+ reportGroup.forEach((group) => {
125
+ group.forEach((o, k) => {
126
+ reports[k] = o;
127
+ });
128
+ });
129
+ }
130
+
131
+ if (reports.raw) {
132
+ let rawDir = path.resolve(outputDir, reports.raw.outputDir || 'raw');
133
+ if (reports.raw.zip) {
134
+ rawDir += '.zip';
135
+ }
136
+ artifact.rawDir = Util.relativePath(rawDir, reporterOptions.outputDir);
137
+ }
138
+
139
+ return artifact;
140
+ };
141
+
142
+ const mergeGlobalCoverageReport = async (coverageRawList, reporterOptions) => {
143
+ const coverageOptions = getGlobalCoverageOptions(reporterOptions);
144
+ coverageOptions.inputDir = coverageRawList;
145
+
146
+ const coverageReport = MCR(coverageOptions);
147
+ const coverageResults = await coverageReport.generate();
148
+ if (!coverageResults) {
149
+ return;
150
+ }
151
+
152
+ const reportPath = coverageResults.reportPath;
153
+ if (reportPath && fs.existsSync(reportPath)) {
154
+ return {
155
+ global: true,
156
+ type: 'coverage',
157
+ name: coverageResults.name,
158
+ path: reportPath
159
+ };
160
+ }
161
+
162
+ };
163
+
164
+ module.exports = {
165
+ addCoverageReport,
166
+ attachCoverageReport,
167
+ generateGlobalCoverageReport,
168
+ mergeGlobalCoverageReport
169
+ };
@@ -1,76 +1,76 @@
1
- const Table = require('../utils/table.js');
2
-
3
- const generateSummaryTable = (reportData) => {
4
-
5
- const summary = reportData.summary;
6
-
7
- const columnMap = {};
8
- Object.values(summary).filter((it) => it.nav).map((item) => {
9
- columnMap[item.id] = {
10
- id: item.id,
11
- name: item.name
12
- };
13
- });
14
-
15
- columnMap.passed.formatter = function(v, row, column) {
16
- if (summary.failed.value === 0) {
17
- return `<span style="color:green;">${v}</span>`;
18
- }
19
- return v;
20
- };
21
- columnMap.failed.formatter = function(v, row, column) {
22
- if (summary.failed.value > 0) {
23
- return `<span style="color:red;">${v}</span>`;
24
- }
25
- return v;
26
- };
27
- columnMap.flaky.formatter = function(v, row, column) {
28
- if (summary.flaky.value > 0) {
29
- return `<span style="color:orange;">${v}</span>`;
30
- }
31
- return v;
32
- };
33
-
34
- const columns = Object.values(columnMap);
35
- columns.push({
36
- id: 'chart',
37
- name: ''
38
- });
39
-
40
- const rowValue = {};
41
- Object.values(summary).map((item) => {
42
- rowValue[item.id] = item.value;
43
- });
44
-
45
- rowValue.chart = Table.generateBarChart(rowValue.tests, rowValue.passed, rowValue.failed, rowValue.flaky);
46
- rowValue.chart_rowspan = 2;
47
-
48
- const rowPercent = {};
49
- Object.values(summary).map((item) => {
50
- rowPercent[item.id] = item.percent;
51
- });
52
-
53
- const summaryData = {
54
- option: {
55
- hideHeaders: false
56
- },
57
- columns,
58
- rows: [
59
- rowValue,
60
- rowPercent
61
- ]
62
- };
63
-
64
- reportData.summaryTable = Table.generateHtml(summaryData);
65
- };
66
-
67
-
68
- module.exports = (reportData) => {
69
-
70
- generateSummaryTable(reportData);
71
-
72
- // local test
73
- // const Util = require('./utils/util.js');
74
- // Util.writeFileSync(`${reportData.outputDir}/summary.html`, reportData.summaryTable);
75
-
76
- };
1
+ const Table = require('../utils/table.js');
2
+
3
+ const generateSummaryTable = (reportData) => {
4
+
5
+ const summary = reportData.summary;
6
+
7
+ const columnMap = {};
8
+ Object.values(summary).filter((it) => it.nav).map((item) => {
9
+ columnMap[item.id] = {
10
+ id: item.id,
11
+ name: item.name
12
+ };
13
+ });
14
+
15
+ columnMap.passed.formatter = function(v, row, column) {
16
+ if (summary.failed.value === 0) {
17
+ return `<span style="color:green;">${v}</span>`;
18
+ }
19
+ return v;
20
+ };
21
+ columnMap.failed.formatter = function(v, row, column) {
22
+ if (summary.failed.value > 0) {
23
+ return `<span style="color:red;">${v}</span>`;
24
+ }
25
+ return v;
26
+ };
27
+ columnMap.flaky.formatter = function(v, row, column) {
28
+ if (summary.flaky.value > 0) {
29
+ return `<span style="color:orange;">${v}</span>`;
30
+ }
31
+ return v;
32
+ };
33
+
34
+ const columns = Object.values(columnMap);
35
+ columns.push({
36
+ id: 'chart',
37
+ name: ''
38
+ });
39
+
40
+ const rowValue = {};
41
+ Object.values(summary).map((item) => {
42
+ rowValue[item.id] = item.value;
43
+ });
44
+
45
+ rowValue.chart = Table.generateBarChart(rowValue.tests, rowValue.passed, rowValue.failed, rowValue.flaky);
46
+ rowValue.chart_rowspan = 2;
47
+
48
+ const rowPercent = {};
49
+ Object.values(summary).map((item) => {
50
+ rowPercent[item.id] = item.percent;
51
+ });
52
+
53
+ const summaryData = {
54
+ option: {
55
+ hideHeaders: false
56
+ },
57
+ columns,
58
+ rows: [
59
+ rowValue,
60
+ rowPercent
61
+ ]
62
+ };
63
+
64
+ reportData.summaryTable = Table.generateHtml(summaryData);
65
+ };
66
+
67
+
68
+ module.exports = (reportData) => {
69
+
70
+ generateSummaryTable(reportData);
71
+
72
+ // local test
73
+ // const Util = require('./utils/util.js');
74
+ // Util.writeFileSync(`${reportData.outputDir}/summary.html`, reportData.summaryTable);
75
+
76
+ };
@@ -1,25 +1,25 @@
1
- const Util = require('../../utils/util.js');
2
-
3
- const setMetadata = (data, testInfo) => {
4
- if (!data || typeof data !== 'object' || !testInfo) {
5
- return;
6
- }
7
-
8
- const definition = Util.attachments.metadata;
9
-
10
- // console.log(definition);
11
- const attachment = {
12
- name: definition.name,
13
- contentType: definition.contentType,
14
- body: Buffer.from(Util.jsonString(data))
15
- };
16
- // console.log(attachment);
17
-
18
- testInfo.attachments.push(attachment);
19
-
20
- };
21
-
22
-
23
- module.exports = {
24
- setMetadata
25
- };
1
+ const Util = require('../../utils/util.js');
2
+
3
+ const setMetadata = (data, testInfo) => {
4
+ if (!data || typeof data !== 'object' || !testInfo) {
5
+ return;
6
+ }
7
+
8
+ const definition = Util.attachments.metadata;
9
+
10
+ // console.log(definition);
11
+ const attachment = {
12
+ name: definition.name,
13
+ contentType: definition.contentType,
14
+ body: Buffer.from(Util.jsonString(data))
15
+ };
16
+ // console.log(attachment);
17
+
18
+ testInfo.attachments.push(attachment);
19
+
20
+ };
21
+
22
+
23
+ module.exports = {
24
+ setMetadata
25
+ };