monocart-reporter 2.1.0 → 2.1.1
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 +22 -16
- package/lib/index.js +10 -12
- package/lib/packages/monocart-network.js +1 -1
- package/lib/packages/monocart-reporter.js +1 -1
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -18,14 +18,15 @@
|
|
|
18
18
|
* [Output](#output) HTML and JSON
|
|
19
19
|
* [Reporter Options](#reporter-options)
|
|
20
20
|
* [View Trace Online](#view-trace-online)
|
|
21
|
-
* [Custom
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
* [Custom Fields Report](#custom-fields-report)
|
|
22
|
+
* [Custom Columns](#custom-columns) (Extra properties for suite/case/step)
|
|
23
|
+
- [Column Formatter](#column-formatter)
|
|
24
|
+
- [Searchable Fields](#searchable-fields)
|
|
25
|
+
* [Custom Data Visitor](#custom-data-visitor) (Extra data collection for suite/case/step)
|
|
26
|
+
- [Collect Data from the Title](#collect-data-from-the-title)
|
|
27
|
+
- [Collect Data from the Annotations](#collect-data-from-the-annotations)
|
|
28
|
+
- [Collect Data from the Comments](#collect-data-from-the-comments) (Recommended)
|
|
29
|
+
- [Remove Secrets and Sensitive Data](#remove-secrets-and-sensitive-data)
|
|
29
30
|
* [Style Tags](#style-tags)
|
|
30
31
|
* [Metadata](#metadata)
|
|
31
32
|
* [Trend Chart](#trend-chart)
|
|
@@ -180,7 +181,12 @@ npx monocart serve-report <your-outputFile-path>
|
|
|
180
181
|
```
|
|
181
182
|
Or customize your own trace viewer url with option `traceViewerUrl` defaults to `https://trace.playwright.dev/?trace={traceUrl}`
|
|
182
183
|
|
|
183
|
-
## Custom
|
|
184
|
+
## Custom Fields Report
|
|
185
|
+
You can add custom fields to the report. for example: Owner, JIRA Key etc.
|
|
186
|
+
- First, you need to add [custom columns](#custom-columns) for the fields.
|
|
187
|
+
- Then, collect data for these fields with [custom data visitor](#custom-data-visitor)
|
|
188
|
+
|
|
189
|
+
### Custom Columns
|
|
184
190
|
The report will be displayed in a `Tree Grid`. The `columns` function is used to customize the grid columns. The column properties following:
|
|
185
191
|
- `id` (String) Column id (required)
|
|
186
192
|
- `name` (String) Column name, shows in grid header
|
|
@@ -235,7 +241,7 @@ module.exports = {
|
|
|
235
241
|
]
|
|
236
242
|
};
|
|
237
243
|
```
|
|
238
|
-
|
|
244
|
+
#### Column Formatter
|
|
239
245
|
> Note: The `formatter` function will be serialized into string via JSON, so closures, contexts, etc. will not work!
|
|
240
246
|
```js
|
|
241
247
|
// playwright.config.js
|
|
@@ -274,7 +280,7 @@ module.exports = {
|
|
|
274
280
|
};
|
|
275
281
|
```
|
|
276
282
|
|
|
277
|
-
|
|
283
|
+
#### Searchable Fields
|
|
278
284
|
```js
|
|
279
285
|
// playwright.config.js
|
|
280
286
|
module.exports = {
|
|
@@ -291,13 +297,13 @@ module.exports = {
|
|
|
291
297
|
};
|
|
292
298
|
```
|
|
293
299
|
|
|
294
|
-
|
|
300
|
+
### Custom Data Visitor
|
|
295
301
|
The `visitor` function will be executed for each row item (suite, case and step). Arguments:
|
|
296
302
|
- `data` data item (suite/case/step) for reporter, you can rewrite some of its properties or add more
|
|
297
303
|
- `metadata` original data object from Playwright test, could be one of [Suite](https://playwright.dev/docs/api/class-suite), [TestCase](https://playwright.dev/docs/api/class-testcase) or [TestStep](https://playwright.dev/docs/api/class-teststep)
|
|
298
304
|
- `collect` see [collect data from the comments](#collect-data-from-the-comments)
|
|
299
305
|
|
|
300
|
-
|
|
306
|
+
#### Collect Data from the Title
|
|
301
307
|
For example, we want to parse out the jira key from the title:
|
|
302
308
|
```js
|
|
303
309
|
test('[MCR-123] collect data from the title', () => {
|
|
@@ -325,7 +331,7 @@ module.exports = {
|
|
|
325
331
|
```
|
|
326
332
|
multiple matches example: [collect-data](https://github.com/cenfun/monocart-reporter-test/tree/main/tests/collect-data)
|
|
327
333
|
|
|
328
|
-
|
|
334
|
+
#### Collect Data from the Annotations
|
|
329
335
|
It should be easier than getting from title. see [custom annotations](https://playwright.dev/docs/test-annotations#custom-annotations) via `test.info().annotations`
|
|
330
336
|
```js
|
|
331
337
|
test('collect data from the annotations', () => {
|
|
@@ -356,7 +362,7 @@ module.exports = {
|
|
|
356
362
|
};
|
|
357
363
|
```
|
|
358
364
|
|
|
359
|
-
|
|
365
|
+
#### Collect Data from the Comments
|
|
360
366
|
> The code comments are good enough to provide extra information without breaking existing code, and no dependencies, clean, easy to read, etc.
|
|
361
367
|
- First, add the collection of comments in the visitor.
|
|
362
368
|
> Note: If there are any parsing error messages in red lines, try other parser options like `sourceType: 'module'` or `plugins: ['typescript']` according to your situation.
|
|
@@ -469,7 +475,7 @@ test.describe('suite title', () => {
|
|
|
469
475
|
const { test, expect } = require('@playwright/test');
|
|
470
476
|
```
|
|
471
477
|
|
|
472
|
-
|
|
478
|
+
#### Remove Secrets and Sensitive Data
|
|
473
479
|
> The report may hosted outside of the organization’s internal boundaries, security becomes a big issue. Any secrets or sensitive data, such as usernames, passwords, tokens and API keys, should be handled with extreme care. The following example is removing the password and token from the report data with the string replacement in `visitor` function.
|
|
474
480
|
```js
|
|
475
481
|
// playwright.config.js
|
package/lib/index.js
CHANGED
|
@@ -96,6 +96,12 @@ class Reporter {
|
|
|
96
96
|
return this.testMap.get(testId);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
addTestLog(test, log) {
|
|
100
|
+
if (test && test.logs) {
|
|
101
|
+
test.logs.push(log);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
99
105
|
// ==========================================================================
|
|
100
106
|
|
|
101
107
|
// Whether this reporter uses stdio for reporting.
|
|
@@ -136,7 +142,7 @@ class Reporter {
|
|
|
136
142
|
// result stderr and stdout without order
|
|
137
143
|
if (test.logs) {
|
|
138
144
|
const retryLogs = ['\n', EC.yellow(`Retry #${result.retry}`), '\n'].join('');
|
|
139
|
-
|
|
145
|
+
this.addTestLog(test, retryLogs);
|
|
140
146
|
} else {
|
|
141
147
|
test.logs = [];
|
|
142
148
|
}
|
|
@@ -144,18 +150,12 @@ class Reporter {
|
|
|
144
150
|
|
|
145
151
|
onStdErr(chunk, test, result) {
|
|
146
152
|
// Note that output may happen when no test is running, in which case this will be void.
|
|
147
|
-
test
|
|
148
|
-
if (test) {
|
|
149
|
-
test.logs.push(EC.red(chunk));
|
|
150
|
-
}
|
|
153
|
+
this.addTestLog(test || this.lastTest, EC.red(chunk));
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
onStdOut(chunk, test, result) {
|
|
154
157
|
// Note that output may happen when no test is running, in which case this will be void.
|
|
155
|
-
test
|
|
156
|
-
if (test) {
|
|
157
|
-
test.logs.push(chunk);
|
|
158
|
-
}
|
|
158
|
+
this.addTestLog(test || this.lastTest, chunk);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
// Called on some global error, for example unhandled exception in the worker process.
|
|
@@ -163,9 +163,7 @@ class Reporter {
|
|
|
163
163
|
// EC.logRed(error);
|
|
164
164
|
|
|
165
165
|
// add the error to test logs
|
|
166
|
-
|
|
167
|
-
this.lastTest.logs.push(EC.red(error.message));
|
|
168
|
-
}
|
|
166
|
+
this.addTestLog(this.lastTest, EC.red(error.message));
|
|
169
167
|
|
|
170
168
|
}
|
|
171
169
|
|