monocart-reporter 2.2.5 → 2.3.0

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 CHANGED
@@ -25,6 +25,7 @@
25
25
  - [Column Formatter](#column-formatter)
26
26
  - [Searchable Fields](#searchable-fields)
27
27
  * [Custom Fields in Comments](#custom-fields-in-comments)
28
+ - [Create Diagrams and Visualizations with Mermaid](#create-diagrams-and-visualizations-with-mermaid)
28
29
  * [Custom Data Visitor](#custom-data-visitor)
29
30
  - [Collect Data from the Title](#collect-data-from-the-title)
30
31
  - [Collect Data from the Annotations](#collect-data-from-the-annotations)
@@ -402,6 +403,46 @@ test.beforeEach(() => {
402
403
  });
403
404
  ```
404
405
 
406
+ #### Create Diagrams and Visualizations with [Mermaid](https://mermaid.js.org/)
407
+ - Enable Mermaid
408
+ ```js
409
+ // playwright.config.js
410
+ module.exports = {
411
+ reporter: [
412
+ ['monocart-reporter', {
413
+ name: "My Test Report",
414
+ outputFile: './test-results/report.html',
415
+ mermaid: {
416
+ // mermaid script url, using mermaid CDN: https://www.jsdelivr.com/package/npm/mermaid
417
+ scriptSrc: 'https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js',
418
+ // mermaid config: https://mermaid.js.org/config/schema-docs/config.html
419
+ config: {
420
+ startOnLoad: false
421
+ }
422
+ }
423
+ }]
424
+ ]
425
+ };
426
+ ```
427
+ - Write Mermaid code in markdown:
428
+ ````js
429
+ /**
430
+ * @description Sequence diagram for Monocart Reporter
431
+ ```mermaid
432
+ flowchart LR
433
+
434
+ A[Hard] -->|Text| B(Round)
435
+ B --> C{Decision}
436
+ C -->|One| D[Result 1]
437
+ C -->|Two| E[Result 2]
438
+ ```
439
+ */
440
+ test('case description', () => {
441
+
442
+ });
443
+ ````
444
+
445
+
405
446
  ### Custom Data Visitor
406
447
  The `visitor` function will be executed for each row item (suite, case and step). Arguments:
407
448
  - `data` data item (suite/case/step) for reporter, you can rewrite some of its properties or add more
@@ -52,6 +52,16 @@ module.exports = {
52
52
  // enable/disable custom fields in comments. Defaults to true.
53
53
  customFieldsInComments: true,
54
54
 
55
+ // mermaid options
56
+ mermaid: null,
57
+ // mermaid: {
58
+ // scriptSrc: 'https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js',
59
+ // // mermaid config https://mermaid.js.org/config/schema-docs/config.html
60
+ // config: {
61
+ // startOnLoad: false
62
+ // }
63
+ // },
64
+
55
65
  // onEnd hook
56
66
  onEnd: null
57
67
  // onEnd: async (reportData, capability) => {}
@@ -79,6 +79,8 @@ const generateData = async (results) => {
79
79
  data.caseTypes = ['passed', 'flaky', 'skipped', 'failed'];
80
80
  data.traceViewerUrl = options.traceViewerUrl;
81
81
 
82
+ data.mermaid = options.mermaid;
83
+
82
84
  calculateSummary(data, options);
83
85
 
84
86
  // global metadata
package/lib/index.d.ts CHANGED
@@ -28,31 +28,39 @@ export type {
28
28
  }
29
29
 
30
30
  export type MonocartReporterOptions = {
31
- // the report name
31
+ /** the report name */
32
32
  name?: string,
33
33
 
34
- // the output file path (relative process.cwd)
34
+ /** the output file path (relative process.cwd) */
35
35
  outputFile?: string,
36
36
 
37
- // attachment path handler
37
+ /** attachment path handler, for example:
38
+ * ```js
39
+ * attachmentPath: (currentPath, extras) => `https://cenfun.github.io/monocart-reporter/${currentPath}`
40
+ * ```
41
+ */
38
42
  attachmentPath?: (currentPath: string, extras: any) => string,
39
- // attachmentPath: (currentPath, extras) => `https://cenfun.github.io/monocart-reporter/${currentPath}`,
40
43
 
44
+ /** custom trace viewer url: https://github.com/cenfun/monocart-reporter?#view-trace-online */
41
45
  traceViewerUrl?: string,
42
46
 
43
- // logging levels: off, error, info, debug
47
+ /** logging levels: off, error, info, debug */
44
48
  logging?: string,
45
49
 
46
- // timezone offset in minutes, GMT+0800 = -480
50
+ /** timezone offset in minutes, For example: GMT+0800 = -480 */
47
51
  timezoneOffset?: number,
48
52
 
49
- // global coverage settings for addCoverageReport API
53
+ /** global coverage options: https://github.com/cenfun/monocart-reporter?#code-coverage-report
54
+ * ```js
55
+ * coverage: {
56
+ * entryFilter: (entry) => true,
57
+ * sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
58
+ * }
59
+ * ```
60
+ */
50
61
  coverage?: CoverageReportOptions,
51
- // coverage: {
52
- // entryFilter: (entry) => true,
53
- // sourceFilter: (sourcePath) => sourcePath.search(/src\/.+/) !== -1,
54
- // },
55
62
 
63
+ /** Global State Management: https://github.com/cenfun/monocart-reporter?#global-state-management */
56
64
  state?: {
57
65
  data?: any,
58
66
  server?: {
@@ -63,41 +71,59 @@ export type MonocartReporterOptions = {
63
71
  onClose?: (data: any, config: any) => void
64
72
  },
65
73
 
66
- // trend data handler
67
- trend?: string | (() => Promise<string | object>),
68
- // trend: () => './test-results/report.json',
69
-
70
- // custom tags style
71
- tags?: object,
72
- // tags: {
73
- // smoke: {
74
- // 'background': '#6F9913'
75
- // },
76
- // sanity: {
77
- // 'background': '#178F43'
78
- // }
79
- // },
80
-
81
- // columns data handler
82
- columns?: (defaultColumns: object[]) => void,
83
- // columns: (defaultColumns) => {},
84
-
85
- // rows data handler (suite, case and step)
74
+ /** trend data handler: https://github.com/cenfun/monocart-reporter?#trend-chart
75
+ * ```js
76
+ * trend: () => './test-results/report.json'
77
+ * ```
78
+ */
79
+ trend?: string | (() => Promise<string | any>),
80
+
81
+ /** custom tags style: https://github.com/cenfun/monocart-reporter?#style-tags
82
+ * ```js
83
+ * tags: {
84
+ * smoke: {
85
+ * 'background': '#6F9913'
86
+ * },
87
+ * sanity: {
88
+ * 'background': '#178F43'
89
+ * }
90
+ * }
91
+ * ```
92
+ */
93
+ tags?: {
94
+ [key: string]: any;
95
+ },
96
+
97
+ /** columns data handler: https://github.com/cenfun/monocart-reporter?#style-tags */
98
+ columns?: (defaultColumns: any[]) => void,
99
+
100
+ /** rows data handler (suite, case and step) https://github.com/cenfun/monocart-reporter?#custom-data-visitor */
86
101
  visitor?: (data: any, metadata: any) => void,
87
- // visitor: (data, metadata) => {},
88
102
 
89
- // enable/disable custom fields in comments. Defaults to true.
103
+ /** enable/disable custom fields in comments. Defaults to true. */
90
104
  customFieldsInComments?: boolean,
91
105
 
92
- // onEnd hook
93
- onEnd?: (reportData: object, capability: {
106
+ /** mermaid options */
107
+ mermaid?: {
108
+ /** mermaid script url, for example: https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js */
109
+ scriptSrc?: string;
110
+ /** mermaid config: https://mermaid.js.org/config/schema-docs/config.html */
111
+ config?: any;
112
+ }
113
+
114
+ /** onEnd hook: https://github.com/cenfun/monocart-reporter?#onend-hook */
115
+ onEnd?: (reportData: any, capability: {
116
+ /** send email with nodemailer: https://nodemailer.com/ */
94
117
  sendEmail?: (emailOptions: {
95
- transport: object,
96
- message: object
118
+ /** email transport: https://nodemailer.com/smtp/ */
119
+ transport: any,
120
+ /** email message: https://nodemailer.com/message/ */
121
+ message: any
97
122
  }) => Promise<void>,
123
+ /** Traverse all cases, suites, and steps. */
98
124
  forEach?: (callback: ((item: any) => void)) => void
99
125
  }) => Promise<void>
100
- // onEnd: async (reportData, capability) => {}
126
+
101
127
  }
102
128
 
103
129
  /**
@@ -175,7 +201,7 @@ export type State = {
175
201
  },
176
202
  set: {
177
203
  (key: string, value: any): Promise<void>,
178
- (obj: object): Promise<void>
204
+ (obj: any): Promise<void>
179
205
  },
180
206
  remove: {
181
207
  (key: string): Promise<void>,