monocart-reporter 2.0.4 → 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 +29 -18
- package/lib/index.js +10 -12
- package/lib/packages/monocart-network.js +1 -1
- package/lib/packages/monocart-reporter.js +1 -1
- package/lib/packages/monocart-vendor.js +1 -1
- package/lib/utils/parse-source.js +1 -2
- package/package.json +9 -10
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)
|
|
@@ -36,7 +37,8 @@
|
|
|
36
37
|
- [V8](#v8)
|
|
37
38
|
- [V8 to Istanbul](#v8-to-istanbul)
|
|
38
39
|
- [Istanbul vs V8](#istanbul-vs-v8)
|
|
39
|
-
- [Global Coverage Report](#global-coverage-report)
|
|
40
|
+
- [Global Coverage Report](#global-coverage-report)
|
|
41
|
+
- [Coverage Examples](#coverage-examples)
|
|
40
42
|
* [Attach Network Report](#attach-network-report)
|
|
41
43
|
* [Global State Management](#global-state-management)
|
|
42
44
|
- [Setup Global State](#setup-global-state)
|
|
@@ -179,7 +181,12 @@ npx monocart serve-report <your-outputFile-path>
|
|
|
179
181
|
```
|
|
180
182
|
Or customize your own trace viewer url with option `traceViewerUrl` defaults to `https://trace.playwright.dev/?trace={traceUrl}`
|
|
181
183
|
|
|
182
|
-
## 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
|
|
183
190
|
The report will be displayed in a `Tree Grid`. The `columns` function is used to customize the grid columns. The column properties following:
|
|
184
191
|
- `id` (String) Column id (required)
|
|
185
192
|
- `name` (String) Column name, shows in grid header
|
|
@@ -234,7 +241,7 @@ module.exports = {
|
|
|
234
241
|
]
|
|
235
242
|
};
|
|
236
243
|
```
|
|
237
|
-
|
|
244
|
+
#### Column Formatter
|
|
238
245
|
> Note: The `formatter` function will be serialized into string via JSON, so closures, contexts, etc. will not work!
|
|
239
246
|
```js
|
|
240
247
|
// playwright.config.js
|
|
@@ -273,7 +280,7 @@ module.exports = {
|
|
|
273
280
|
};
|
|
274
281
|
```
|
|
275
282
|
|
|
276
|
-
|
|
283
|
+
#### Searchable Fields
|
|
277
284
|
```js
|
|
278
285
|
// playwright.config.js
|
|
279
286
|
module.exports = {
|
|
@@ -290,13 +297,13 @@ module.exports = {
|
|
|
290
297
|
};
|
|
291
298
|
```
|
|
292
299
|
|
|
293
|
-
|
|
300
|
+
### Custom Data Visitor
|
|
294
301
|
The `visitor` function will be executed for each row item (suite, case and step). Arguments:
|
|
295
302
|
- `data` data item (suite/case/step) for reporter, you can rewrite some of its properties or add more
|
|
296
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)
|
|
297
304
|
- `collect` see [collect data from the comments](#collect-data-from-the-comments)
|
|
298
305
|
|
|
299
|
-
|
|
306
|
+
#### Collect Data from the Title
|
|
300
307
|
For example, we want to parse out the jira key from the title:
|
|
301
308
|
```js
|
|
302
309
|
test('[MCR-123] collect data from the title', () => {
|
|
@@ -324,7 +331,7 @@ module.exports = {
|
|
|
324
331
|
```
|
|
325
332
|
multiple matches example: [collect-data](https://github.com/cenfun/monocart-reporter-test/tree/main/tests/collect-data)
|
|
326
333
|
|
|
327
|
-
|
|
334
|
+
#### Collect Data from the Annotations
|
|
328
335
|
It should be easier than getting from title. see [custom annotations](https://playwright.dev/docs/test-annotations#custom-annotations) via `test.info().annotations`
|
|
329
336
|
```js
|
|
330
337
|
test('collect data from the annotations', () => {
|
|
@@ -355,7 +362,7 @@ module.exports = {
|
|
|
355
362
|
};
|
|
356
363
|
```
|
|
357
364
|
|
|
358
|
-
|
|
365
|
+
#### Collect Data from the Comments
|
|
359
366
|
> The code comments are good enough to provide extra information without breaking existing code, and no dependencies, clean, easy to read, etc.
|
|
360
367
|
- First, add the collection of comments in the visitor.
|
|
361
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.
|
|
@@ -468,7 +475,7 @@ test.describe('suite title', () => {
|
|
|
468
475
|
const { test, expect } = require('@playwright/test');
|
|
469
476
|
```
|
|
470
477
|
|
|
471
|
-
|
|
478
|
+
#### Remove Secrets and Sensitive Data
|
|
472
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.
|
|
473
480
|
```js
|
|
474
481
|
// playwright.config.js
|
|
@@ -792,10 +799,14 @@ const test = testBase.extend({
|
|
|
792
799
|
});
|
|
793
800
|
export { test, expect };
|
|
794
801
|
```
|
|
795
|
-
|
|
802
|
+
|
|
803
|
+
### Coverage Examples
|
|
804
|
+
- For Playwright component testing:
|
|
796
805
|
- [playwright-ct-vue](https://github.com/cenfun/playwright-ct-vue)
|
|
797
806
|
- [playwright-ct-react](https://github.com/cenfun/playwright-ct-react)
|
|
798
807
|
- [playwright-ct-svelte](https://github.com/cenfun/playwright-ct-svelte)
|
|
808
|
+
- [playwright-nextjs-coverage-example](https://github.com/michaelhays/playwright-nextjs-coverage-example)
|
|
809
|
+
- [code-coverage-with-monocart-reporter](https://github.com/edumserrano/playwright-adventures/blob/main/demos/code-coverage-with-monocart-reporter/)
|
|
799
810
|
|
|
800
811
|
## Attach Network Report
|
|
801
812
|
Attach a network report with API `attachNetworkReport(har, testInfo)`. Arguments:
|
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
|
|