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.
package/lib/index.js CHANGED
@@ -1,253 +1,253 @@
1
- const path = require('path');
2
- const EC = require('eight-colors');
3
- const { getSystemInfo, getTickInfo } = require('./utils/system.js');
4
- const generateData = require('./generate-data.js');
5
- const generateReport = require('./generate-report.js');
6
- const getDefaultOptions = require('./default/options.js');
7
- const { getTrends } = require('./common.js');
8
-
9
- const merge = require('./merge-data.js');
10
- const { attachAuditReport } = require('./plugins/audit/audit.js');
11
- const { addCoverageReport, attachCoverageReport } = require('./plugins/coverage/coverage.js');
12
- const { attachNetworkReport } = require('./plugins/network/network.js');
13
- const { setMetadata } = require('./plugins/metadata/metadata.js');
14
-
15
- const { createStateServer, useState } = require('./plugins/state/state.js');
16
-
17
- const Util = require('./utils/util.js');
18
-
19
- // custom reporter
20
- // https://playwright.dev/docs/test-reporters#custom-reporters
21
- class MonocartReporter {
22
-
23
- static Util = Util;
24
-
25
- static merge = merge;
26
-
27
- static attachAuditReport = attachAuditReport;
28
-
29
- static addCoverageReport = addCoverageReport;
30
- static attachCoverageReport = attachCoverageReport;
31
-
32
- static attachNetworkReport = attachNetworkReport;
33
-
34
- static setMetadata = setMetadata;
35
-
36
- static useState = useState;
37
-
38
- constructor(userOptions = {}) {
39
-
40
- const timestampStart = Date.now();
41
-
42
- this.options = {
43
- ... getDefaultOptions(),
44
- ... userOptions
45
- };
46
-
47
- Util.initLoggingLevel(this.options.logging, 'reporter');
48
-
49
- this.testMap = new Map();
50
-
51
- this.system = getSystemInfo();
52
- this.system.timestampStart = timestampStart;
53
- this.system.ticks = [];
54
-
55
- this.tickTime = this.options.tickTime || 1000;
56
- this.tickStart();
57
-
58
- this.trends = [];
59
- // read trends from json before clean dir
60
- getTrends(this.options.trend).then((trends) => {
61
- // console.log('=========================== ', 'trends', trends.length);
62
- this.trends = trends;
63
- });
64
-
65
- this.init();
66
-
67
- }
68
-
69
- init() {
70
-
71
- this.options.cwd = Util.formatPath(process.cwd());
72
-
73
- // init outputDir
74
- const outputFile = Util.resolveOutputFile(this.options.outputFile);
75
- this.options.outputFile = outputFile;
76
-
77
- const outputDir = path.dirname(outputFile);
78
-
79
- // for visitor relative path of attachments
80
- this.options.outputDir = outputDir;
81
-
82
- // init attachmentsDir
83
- if (this.options.copyAttachments) {
84
- this.options.attachmentsDir = path.resolve(outputDir, 'attachments');
85
- }
86
-
87
- const stateOptions = this.options.state;
88
- if (stateOptions) {
89
- this.bindFunctions(stateOptions);
90
- this.stateServer = createStateServer(stateOptions);
91
- }
92
-
93
- this.cleanOutputDir();
94
-
95
- }
96
-
97
- cleanOutputDir() {
98
- Util.initDir(this.options.outputDir);
99
- // console.log('=========================== ', 'cleanOutputDir');
100
- }
101
-
102
- // ==========================================================================
103
-
104
- bindFunctions(obj) {
105
- Object.keys(obj).forEach((k) => {
106
- if (typeof obj[k] === 'function') {
107
- // The bind() method creates a new function
108
- obj[k] = obj[k].bind(this);
109
- }
110
- });
111
- }
112
-
113
- // ==========================================================================
114
-
115
-
116
- tickStart() {
117
- this.tick_time_id = setTimeout(async () => {
118
- const tickInfo = await getTickInfo();
119
- this.system.ticks.push(tickInfo);
120
- this.tickStart();
121
- }, this.tickTime);
122
- }
123
-
124
- tickStop() {
125
- clearTimeout(this.tick_time_id);
126
- }
127
-
128
- // ==========================================================================
129
-
130
- getTest(testId) {
131
- return this.testMap.get(testId);
132
- }
133
-
134
- addTestLog(test, log) {
135
- if (test && test.logs) {
136
- test.logs.push(log);
137
- }
138
- }
139
-
140
- // ==========================================================================
141
-
142
- // Whether this reporter uses stdio for reporting.
143
- // When it does not, Playwright Test could add some output to enhance user experience.
144
- // If your reporter does not print to the terminal, it is strongly recommended to return false.
145
- printsToStdio() {
146
- return true;
147
- }
148
-
149
- // root suite in the reporter.onBegin(config, suite) method.
150
- onBegin(config, suite) {
151
- this.config = config;
152
- this.root = suite;
153
-
154
- // console.log('=========================== ', 'onBegin');
155
-
156
- // output dir for test results (not reporter)
157
- this.options.testOutputDir = config.projects[0].outputDir;
158
- // console.log(`onBegin: ${suite.allTests().length} tests`);
159
- }
160
-
161
- onTestBegin(test, result) {
162
- // console.log(`onTestBegin ${test.title}`);
163
-
164
- // there maybe multiple test running at same time
165
- // current test only for missing logs
166
- // do NOT using for test info
167
- this.lastTest = test;
168
-
169
- // id, not testId (for test info)
170
- // console.log('==========================================');
171
- // console.log('keep test in map', test.id);
172
- this.testMap.set(test.id, test);
173
-
174
- // Note that do not use this because is parallel
175
- if (!test.timestamps) {
176
- test.timestamps = [];
177
- }
178
- test.timestamps.push(Date.now());
179
-
180
- // keep logs here with order
181
- // result stderr and stdout without order
182
- if (test.logs) {
183
- const retryLogs = ['\n', EC.yellow(`Retry #${result.retry}`), '\n'].join('');
184
- this.addTestLog(test, retryLogs);
185
- } else {
186
- test.logs = [];
187
- }
188
- }
189
-
190
- onStdErr(chunk, test, result) {
191
- // Note that output may happen when no test is running, in which case this will be void.
192
- this.addTestLog(test || this.lastTest, EC.red(chunk));
193
- }
194
-
195
- onStdOut(chunk, test, result) {
196
- // Note that output may happen when no test is running, in which case this will be void.
197
- this.addTestLog(test || this.lastTest, chunk);
198
- }
199
-
200
- // Called on some global error, for example unhandled exception in the worker process.
201
- onError(error) {
202
- // EC.logRed(error);
203
-
204
- // add the error to test logs
205
- this.addTestLog(this.lastTest, EC.red(error.message));
206
-
207
- }
208
-
209
- // onStepBegin(test, result, step)
210
- // onStepEnd(test, result, step)
211
-
212
- onTestEnd(test, result) {
213
- // console.log(`onTestEnd ${test.title}: ${result.status}`);
214
- // console.log(result);
215
-
216
- // logs
217
- if (!test.logs.length) {
218
- delete test.logs;
219
- }
220
-
221
- // timestamps
222
- test.timestamps.push(Date.now());
223
-
224
- }
225
-
226
- async onEnd(result) {
227
-
228
- if (this.stateServer) {
229
- await this.stateServer.close(this.config);
230
- this.stateServer = null;
231
- }
232
-
233
- this.lastTest = null;
234
- this.testMap.clear();
235
-
236
- // console.log(`onEnd: ${result.status}`);
237
- // console.log(result);
238
- this.tickStop();
239
-
240
- const reportData = await generateData({
241
- config: this.config,
242
- root: this.root,
243
- options: this.options,
244
- system: this.system,
245
- trends: this.trends
246
- });
247
-
248
- return generateReport(reportData, this.options, this.root);
249
- }
250
-
251
- }
252
-
253
- module.exports = MonocartReporter;
1
+ const path = require('path');
2
+ const EC = require('eight-colors');
3
+ const { getSystemInfo, getTickInfo } = require('./utils/system.js');
4
+ const generateData = require('./generate-data.js');
5
+ const generateReport = require('./generate-report.js');
6
+ const getDefaultOptions = require('./default/options.js');
7
+ const { getTrends } = require('./common.js');
8
+
9
+ const merge = require('./merge-data.js');
10
+ const { attachAuditReport } = require('./plugins/audit/audit.js');
11
+ const { addCoverageReport, attachCoverageReport } = require('./plugins/coverage/coverage.js');
12
+ const { attachNetworkReport } = require('./plugins/network/network.js');
13
+ const { setMetadata } = require('./plugins/metadata/metadata.js');
14
+
15
+ const { createStateServer, useState } = require('./plugins/state/state.js');
16
+
17
+ const Util = require('./utils/util.js');
18
+
19
+ // custom reporter
20
+ // https://playwright.dev/docs/test-reporters#custom-reporters
21
+ class MonocartReporter {
22
+
23
+ static Util = Util;
24
+
25
+ static merge = merge;
26
+
27
+ static attachAuditReport = attachAuditReport;
28
+
29
+ static addCoverageReport = addCoverageReport;
30
+ static attachCoverageReport = attachCoverageReport;
31
+
32
+ static attachNetworkReport = attachNetworkReport;
33
+
34
+ static setMetadata = setMetadata;
35
+
36
+ static useState = useState;
37
+
38
+ constructor(userOptions = {}) {
39
+
40
+ const timestampStart = Date.now();
41
+
42
+ this.options = {
43
+ ... getDefaultOptions(),
44
+ ... userOptions
45
+ };
46
+
47
+ Util.initLoggingLevel(this.options.logging, 'reporter');
48
+
49
+ this.testMap = new Map();
50
+
51
+ this.system = getSystemInfo();
52
+ this.system.timestampStart = timestampStart;
53
+ this.system.ticks = [];
54
+
55
+ this.tickTime = this.options.tickTime || 1000;
56
+ this.tickStart();
57
+
58
+ this.trends = [];
59
+ // read trends from json before clean dir
60
+ getTrends(this.options.trend).then((trends) => {
61
+ // console.log('=========================== ', 'trends', trends.length);
62
+ this.trends = trends;
63
+ });
64
+
65
+ this.init();
66
+
67
+ }
68
+
69
+ init() {
70
+
71
+ this.options.cwd = Util.formatPath(process.cwd());
72
+
73
+ // init outputDir
74
+ const outputFile = Util.resolveOutputFile(this.options.outputFile);
75
+ this.options.outputFile = outputFile;
76
+
77
+ const outputDir = path.dirname(outputFile);
78
+
79
+ // for visitor relative path of attachments
80
+ this.options.outputDir = outputDir;
81
+
82
+ // init attachmentsDir
83
+ if (this.options.copyAttachments) {
84
+ this.options.attachmentsDir = path.resolve(outputDir, 'attachments');
85
+ }
86
+
87
+ const stateOptions = this.options.state;
88
+ if (stateOptions) {
89
+ this.bindFunctions(stateOptions);
90
+ this.stateServer = createStateServer(stateOptions);
91
+ }
92
+
93
+ this.cleanOutputDir();
94
+
95
+ }
96
+
97
+ cleanOutputDir() {
98
+ Util.initDir(this.options.outputDir);
99
+ // console.log('=========================== ', 'cleanOutputDir');
100
+ }
101
+
102
+ // ==========================================================================
103
+
104
+ bindFunctions(obj) {
105
+ Object.keys(obj).forEach((k) => {
106
+ if (typeof obj[k] === 'function') {
107
+ // The bind() method creates a new function
108
+ obj[k] = obj[k].bind(this);
109
+ }
110
+ });
111
+ }
112
+
113
+ // ==========================================================================
114
+
115
+
116
+ tickStart() {
117
+ this.tick_time_id = setTimeout(async () => {
118
+ const tickInfo = await getTickInfo();
119
+ this.system.ticks.push(tickInfo);
120
+ this.tickStart();
121
+ }, this.tickTime);
122
+ }
123
+
124
+ tickStop() {
125
+ clearTimeout(this.tick_time_id);
126
+ }
127
+
128
+ // ==========================================================================
129
+
130
+ getTest(testId) {
131
+ return this.testMap.get(testId);
132
+ }
133
+
134
+ addTestLog(test, log) {
135
+ if (test && test.logs) {
136
+ test.logs.push(log);
137
+ }
138
+ }
139
+
140
+ // ==========================================================================
141
+
142
+ // Whether this reporter uses stdio for reporting.
143
+ // When it does not, Playwright Test could add some output to enhance user experience.
144
+ // If your reporter does not print to the terminal, it is strongly recommended to return false.
145
+ printsToStdio() {
146
+ return true;
147
+ }
148
+
149
+ // root suite in the reporter.onBegin(config, suite) method.
150
+ onBegin(config, suite) {
151
+ this.config = config;
152
+ this.root = suite;
153
+
154
+ // console.log('=========================== ', 'onBegin');
155
+
156
+ // output dir for test results (not reporter)
157
+ this.options.testOutputDir = config.projects[0].outputDir;
158
+ // console.log(`onBegin: ${suite.allTests().length} tests`);
159
+ }
160
+
161
+ onTestBegin(test, result) {
162
+ // console.log(`onTestBegin ${test.title}`);
163
+
164
+ // there maybe multiple test running at same time
165
+ // current test only for missing logs
166
+ // do NOT using for test info
167
+ this.lastTest = test;
168
+
169
+ // id, not testId (for test info)
170
+ // console.log('==========================================');
171
+ // console.log('keep test in map', test.id);
172
+ this.testMap.set(test.id, test);
173
+
174
+ // Note that do not use this because is parallel
175
+ if (!test.timestamps) {
176
+ test.timestamps = [];
177
+ }
178
+ test.timestamps.push(Date.now());
179
+
180
+ // keep logs here with order
181
+ // result stderr and stdout without order
182
+ if (test.logs) {
183
+ const retryLogs = ['\n', EC.yellow(`Retry #${result.retry}`), '\n'].join('');
184
+ this.addTestLog(test, retryLogs);
185
+ } else {
186
+ test.logs = [];
187
+ }
188
+ }
189
+
190
+ onStdErr(chunk, test, result) {
191
+ // Note that output may happen when no test is running, in which case this will be void.
192
+ this.addTestLog(test || this.lastTest, EC.red(chunk));
193
+ }
194
+
195
+ onStdOut(chunk, test, result) {
196
+ // Note that output may happen when no test is running, in which case this will be void.
197
+ this.addTestLog(test || this.lastTest, chunk);
198
+ }
199
+
200
+ // Called on some global error, for example unhandled exception in the worker process.
201
+ onError(error) {
202
+ // EC.logRed(error);
203
+
204
+ // add the error to test logs
205
+ this.addTestLog(this.lastTest, EC.red(error.message));
206
+
207
+ }
208
+
209
+ // onStepBegin(test, result, step)
210
+ // onStepEnd(test, result, step)
211
+
212
+ onTestEnd(test, result) {
213
+ // console.log(`onTestEnd ${test.title}: ${result.status}`);
214
+ // console.log(result);
215
+
216
+ // logs
217
+ if (!test.logs.length) {
218
+ delete test.logs;
219
+ }
220
+
221
+ // timestamps
222
+ test.timestamps.push(Date.now());
223
+
224
+ }
225
+
226
+ async onEnd(result) {
227
+
228
+ if (this.stateServer) {
229
+ await this.stateServer.close(this.config);
230
+ this.stateServer = null;
231
+ }
232
+
233
+ this.lastTest = null;
234
+ this.testMap.clear();
235
+
236
+ // console.log(`onEnd: ${result.status}`);
237
+ // console.log(result);
238
+ this.tickStop();
239
+
240
+ const reportData = await generateData({
241
+ config: this.config,
242
+ root: this.root,
243
+ options: this.options,
244
+ system: this.system,
245
+ trends: this.trends
246
+ });
247
+
248
+ return generateReport(reportData, this.options, this.root);
249
+ }
250
+
251
+ }
252
+
253
+ module.exports = MonocartReporter;
package/lib/index.mjs CHANGED
@@ -1,19 +1,19 @@
1
- import MonocartReporter from './index.js';
2
-
3
- export default MonocartReporter;
4
- export { MonocartReporter };
5
-
6
- export const Util = MonocartReporter.Util;
7
-
8
- export const merge = MonocartReporter.merge;
9
-
10
- export const attachAuditReport = MonocartReporter.attachAuditReport;
11
-
12
- export const addCoverageReport = MonocartReporter.addCoverageReport;
13
- export const attachCoverageReport = MonocartReporter.attachCoverageReport;
14
-
15
- export const attachNetworkReport = MonocartReporter.attachNetworkReport;
16
-
17
- export const setMetadata = MonocartReporter.setMetadata;
18
-
19
- export const useState = MonocartReporter.useState;
1
+ import MonocartReporter from './index.js';
2
+
3
+ export default MonocartReporter;
4
+ export { MonocartReporter };
5
+
6
+ export const Util = MonocartReporter.Util;
7
+
8
+ export const merge = MonocartReporter.merge;
9
+
10
+ export const attachAuditReport = MonocartReporter.attachAuditReport;
11
+
12
+ export const addCoverageReport = MonocartReporter.addCoverageReport;
13
+ export const attachCoverageReport = MonocartReporter.attachCoverageReport;
14
+
15
+ export const attachNetworkReport = MonocartReporter.attachNetworkReport;
16
+
17
+ export const setMetadata = MonocartReporter.setMetadata;
18
+
19
+ export const useState = MonocartReporter.useState;