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,174 +1,174 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const Util = require('./utils/util.js');
4
- const { getTickInfo } = require('./utils/system.js');
5
- const Visitor = require('./visitor.js');
6
- const { calculateSummary } = require('./common.js');
7
- const { generateGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
8
- const version = require('../package.json').version;
9
-
10
- const getReportName = (options, config, metadata) => {
11
- const reportName = options.name || config.name || metadata.name;
12
- if (reportName) {
13
- return reportName;
14
- }
15
- return 'Test Report';
16
- };
17
-
18
- const artifactsHandler = async (visitor, reporterOptions) => {
19
- const artifacts = [].concat(visitor.artifacts);
20
-
21
- // global artifacts
22
- const globalCoverageReport = await generateGlobalCoverageReport(reporterOptions);
23
- if (globalCoverageReport) {
24
- artifacts.push(globalCoverageReport);
25
- }
26
-
27
- return artifacts;
28
- };
29
-
30
- const getReportDate = (timestampStart, timezoneOffset = 0) => {
31
- // in minutes
32
- const offset = Util.toNum(timezoneOffset);
33
- return timestampStart + offset * 60 * 1000;
34
- };
35
-
36
- const generateMermaid = (options) => {
37
- const mermaidOptions = options.mermaid;
38
- if (mermaidOptions) {
39
- const scriptSrc = mermaidOptions.scriptSrc;
40
- if (!scriptSrc) {
41
- // try to copy and load from local
42
- let mp;
43
- try {
44
- mp = require.resolve('mermaid');
45
- } catch (e) {
46
- // ignore error
47
- }
48
- // console.log(mp);
49
- if (mp) {
50
- const filename = 'mermaid.min.js';
51
- const filePath = path.resolve(path.dirname(mp), filename);
52
- if (fs.existsSync(filePath)) {
53
- const assetPath = path.resolve(options.outputDir, 'assets', filename);
54
- fs.cpSync(filePath, assetPath, {
55
- recursive: true,
56
- force: true
57
- });
58
- mermaidOptions.scriptSrc = `assets/${filename}`;
59
- }
60
- }
61
- }
62
- }
63
- // console.log(mermaidOptions);
64
- return mermaidOptions;
65
- };
66
-
67
- const generateData = async (results) => {
68
-
69
- Util.logInfo('generating report data ...');
70
-
71
- const {
72
- config,
73
- root,
74
- options,
75
- system,
76
- trends
77
- } = results;
78
-
79
- const {
80
- cwd, outputFile, outputDir
81
- } = options;
82
-
83
- // console.log(config);
84
- const visitor = new Visitor(root, options);
85
- await visitor.start();
86
-
87
- const data = {
88
- columns: visitor.columns,
89
- rows: visitor.rows,
90
- formatters: visitor.formatters
91
- };
92
-
93
- // Limit workers
94
- system.workers = config.workers;
95
- // put jobs in system
96
- system.jobs = visitor.jobs;
97
-
98
- // suite and case types
99
- data.suiteTypes = ['project', 'file', 'describe', 'shard'];
100
- data.caseTypes = ['passed', 'flaky', 'skipped', 'failed'];
101
- data.traceViewerUrl = options.traceViewerUrl;
102
- data.mermaid = generateMermaid(options);
103
- data.groupOptions = options.groupOptions;
104
-
105
- calculateSummary(data, options);
106
-
107
- // global metadata
108
- const metadata = config.metadata || {};
109
-
110
- const reportName = getReportName(options, config, metadata);
111
- options.name = reportName;
112
-
113
- const artifacts = await artifactsHandler(visitor, options);
114
-
115
- system.cwd = cwd;
116
-
117
- // playwright configFile
118
- system.configFile = Util.relativePath(config.configFile);
119
- // playwright version
120
- system.playwright = config.version;
121
- // monocart version
122
- system.monocart = version;
123
-
124
- // test root dir
125
- system.testDir = Util.relativePath(config.rootDir);
126
-
127
- // reporter output, for shard in diff system
128
- system.outputFile = Util.relativePath(outputFile);
129
- system.outputDir = Util.relativePath(outputDir);
130
-
131
- // add one last tick before end time
132
- const tickInfo = await getTickInfo();
133
- system.ticks.push(tickInfo);
134
-
135
- // let start timestamp as date
136
- const date = getReportDate(system.timestampStart, options.timezoneOffset);
137
- const dateH = new Date(date).toLocaleString();
138
-
139
- // end timestamp for duration
140
- system.timestampEnd = Date.now();
141
- const duration = system.timestampEnd - system.timestampStart;
142
- const durationH = Util.TF(duration);
143
-
144
- const reportData = {
145
- // for report title
146
- name: reportName,
147
-
148
- date,
149
- dateH,
150
- duration,
151
- durationH,
152
-
153
- // for current process, like merge process
154
- cwd,
155
- outputFile,
156
- outputDir,
157
-
158
- metadata,
159
- system,
160
-
161
- artifacts,
162
- trends,
163
-
164
- // columns, rows, formatters
165
- // tags, summary, pieChart
166
- ... data
167
- };
168
-
169
- return reportData;
170
-
171
- };
172
-
173
-
174
- module.exports = generateData;
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const Util = require('./utils/util.js');
4
+ const { getTickInfo } = require('./utils/system.js');
5
+ const Visitor = require('./visitor.js');
6
+ const { calculateSummary } = require('./common.js');
7
+ const { generateGlobalCoverageReport } = require('./plugins/coverage/coverage.js');
8
+ const version = require('../package.json').version;
9
+
10
+ const getReportName = (options, config, metadata) => {
11
+ const reportName = options.name || config.name || metadata.name;
12
+ if (reportName) {
13
+ return reportName;
14
+ }
15
+ return 'Test Report';
16
+ };
17
+
18
+ const artifactsHandler = async (visitor, reporterOptions) => {
19
+ const artifacts = [].concat(visitor.artifacts);
20
+
21
+ // global artifacts
22
+ const globalCoverageReport = await generateGlobalCoverageReport(reporterOptions);
23
+ if (globalCoverageReport) {
24
+ artifacts.push(globalCoverageReport);
25
+ }
26
+
27
+ return artifacts;
28
+ };
29
+
30
+ const getReportDate = (timestampStart, timezoneOffset = 0) => {
31
+ // in minutes
32
+ const offset = Util.toNum(timezoneOffset);
33
+ return timestampStart + offset * 60 * 1000;
34
+ };
35
+
36
+ const generateMermaid = (options) => {
37
+ const mermaidOptions = options.mermaid;
38
+ if (mermaidOptions) {
39
+ const scriptSrc = mermaidOptions.scriptSrc;
40
+ if (!scriptSrc) {
41
+ // try to copy and load from local
42
+ let mp;
43
+ try {
44
+ mp = require.resolve('mermaid');
45
+ } catch (e) {
46
+ // ignore error
47
+ }
48
+ // console.log(mp);
49
+ if (mp) {
50
+ const filename = 'mermaid.min.js';
51
+ const filePath = path.resolve(path.dirname(mp), filename);
52
+ if (fs.existsSync(filePath)) {
53
+ const assetPath = path.resolve(options.outputDir, 'assets', filename);
54
+ fs.cpSync(filePath, assetPath, {
55
+ recursive: true,
56
+ force: true
57
+ });
58
+ mermaidOptions.scriptSrc = `assets/${filename}`;
59
+ }
60
+ }
61
+ }
62
+ }
63
+ // console.log(mermaidOptions);
64
+ return mermaidOptions;
65
+ };
66
+
67
+ const generateData = async (results) => {
68
+
69
+ Util.logInfo('generating report data ...');
70
+
71
+ const {
72
+ config,
73
+ root,
74
+ options,
75
+ system,
76
+ trends
77
+ } = results;
78
+
79
+ const {
80
+ cwd, outputFile, outputDir
81
+ } = options;
82
+
83
+ // console.log(config);
84
+ const visitor = new Visitor(root, options);
85
+ await visitor.start();
86
+
87
+ const data = {
88
+ columns: visitor.columns,
89
+ rows: visitor.rows,
90
+ formatters: visitor.formatters
91
+ };
92
+
93
+ // Limit workers
94
+ system.workers = config.workers;
95
+ // put jobs in system
96
+ system.jobs = visitor.jobs;
97
+
98
+ // suite and case types
99
+ data.suiteTypes = ['project', 'file', 'describe', 'shard'];
100
+ data.caseTypes = ['passed', 'flaky', 'skipped', 'failed'];
101
+ data.traceViewerUrl = options.traceViewerUrl;
102
+ data.mermaid = generateMermaid(options);
103
+ data.groupOptions = options.groupOptions;
104
+
105
+ calculateSummary(data, options);
106
+
107
+ // global metadata
108
+ const metadata = config.metadata || {};
109
+
110
+ const reportName = getReportName(options, config, metadata);
111
+ options.name = reportName;
112
+
113
+ const artifacts = await artifactsHandler(visitor, options);
114
+
115
+ system.cwd = cwd;
116
+
117
+ // playwright configFile
118
+ system.configFile = Util.relativePath(config.configFile);
119
+ // playwright version
120
+ system.playwright = config.version;
121
+ // monocart version
122
+ system.monocart = version;
123
+
124
+ // test root dir
125
+ system.testDir = Util.relativePath(config.rootDir);
126
+
127
+ // reporter output, for shard in diff system
128
+ system.outputFile = Util.relativePath(outputFile);
129
+ system.outputDir = Util.relativePath(outputDir);
130
+
131
+ // add one last tick before end time
132
+ const tickInfo = await getTickInfo();
133
+ system.ticks.push(tickInfo);
134
+
135
+ // let start timestamp as date
136
+ const date = getReportDate(system.timestampStart, options.timezoneOffset);
137
+ const dateH = new Date(date).toLocaleString();
138
+
139
+ // end timestamp for duration
140
+ system.timestampEnd = Date.now();
141
+ const duration = system.timestampEnd - system.timestampStart;
142
+ const durationH = Util.TF(duration);
143
+
144
+ const reportData = {
145
+ // for report title
146
+ name: reportName,
147
+
148
+ date,
149
+ dateH,
150
+ duration,
151
+ durationH,
152
+
153
+ // for current process, like merge process
154
+ cwd,
155
+ outputFile,
156
+ outputDir,
157
+
158
+ metadata,
159
+ system,
160
+
161
+ artifacts,
162
+ trends,
163
+
164
+ // columns, rows, formatters
165
+ // tags, summary, pieChart
166
+ ... data
167
+ };
168
+
169
+ return reportData;
170
+
171
+ };
172
+
173
+
174
+ module.exports = generateData;