monocart-reporter 2.5.2 → 2.6.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.
@@ -18,6 +18,10 @@ const Util = {
18
18
  name: 'network',
19
19
  contentType: 'text/html',
20
20
  reportFile: 'network-report.json'
21
+ },
22
+ metadata: {
23
+ name: 'metadata',
24
+ contentType: 'application/json'
21
25
  }
22
26
  },
23
27
 
@@ -0,0 +1,25 @@
1
+ const Util = require('../../utils/util.js');
2
+
3
+ const setMetadata = (data, testInfo) => {
4
+ if (!data || typeof data !== 'object' || !testInfo) {
5
+ return;
6
+ }
7
+
8
+ const definition = Util.attachments.metadata;
9
+
10
+ // console.log(definition);
11
+ const attachment = {
12
+ name: definition.name,
13
+ contentType: definition.contentType,
14
+ body: Buffer.from(Util.jsonString(data))
15
+ };
16
+ // console.log(attachment);
17
+
18
+ testInfo.attachments.push(attachment);
19
+
20
+ };
21
+
22
+
23
+ module.exports = {
24
+ setMetadata
25
+ };
package/lib/visitor.js CHANGED
@@ -8,18 +8,6 @@ const Util = require('./utils/util.js');
8
8
  const commentsPlugin = require('./plugins/comments.js');
9
9
  const getDefaultColumns = require('./default/columns.js');
10
10
 
11
- // retired, just warning for old babel parser
12
- let collectWarning = '"collect.comments()" has been deprecated (replaced with new option "customFieldsInComments: true/false" in version 2.2.0), please remove the code related to "collect.comments()" in custom "visitor".';
13
- const collect = new Proxy({}, {
14
- get: function(obj, prop) {
15
- if (collectWarning) {
16
- Util.logError(collectWarning);
17
- collectWarning = null;
18
- }
19
- return () => {};
20
- }
21
- });
22
-
23
11
  class Visitor {
24
12
  constructor(root, options) {
25
13
  this.root = root;
@@ -125,13 +113,13 @@ class Visitor {
125
113
 
126
114
  // for all data
127
115
  if (this.customCommonVisitor) {
128
- await this.customCommonVisitor.call(this, data, metadata, collect);
116
+ await this.customCommonVisitor.call(this, data, metadata);
129
117
  }
130
118
 
131
119
  // for single column data (high priority)
132
120
  if (this.customVisitors) {
133
121
  for (const item of this.customVisitors) {
134
- const res = await item.visitor.call(this, data, metadata, collect);
122
+ const res = await item.visitor.call(this, data, metadata);
135
123
  if (typeof res !== 'undefined') {
136
124
  data[item.id] = res;
137
125
  }
@@ -518,6 +506,11 @@ class Visitor {
518
506
 
519
507
  attachments.forEach((item, i) => {
520
508
 
509
+ // metadata with body
510
+ if (this.testMetadataHandler(item, caseItem)) {
511
+ return;
512
+ }
513
+
521
514
  if (item.body) {
522
515
  if (!item.path) {
523
516
  this.saveAttachmentBodyHandler(item, i, caseId);
@@ -536,7 +529,7 @@ class Visitor {
536
529
  this.reportHandler(item, 'network', title);
537
530
 
538
531
  // content: text
539
- this.contentHandler(item);
532
+ this.testContentHandler(item);
540
533
 
541
534
  const o = this.options;
542
535
  // store relative path first
@@ -595,7 +588,39 @@ class Visitor {
595
588
 
596
589
  }
597
590
 
598
- contentHandler(item) {
591
+ testMetadataHandler(item, caseItem) {
592
+ const definition = Util.attachments.metadata;
593
+ if (item.name !== definition.name || item.contentType !== definition.contentType) {
594
+ return;
595
+ }
596
+
597
+ // console.log(item);
598
+ // name, path(undefined), contentType, body, retry
599
+
600
+ let content = item.body;
601
+ if (Buffer.isBuffer(content)) {
602
+ content = content.toString('utf8');
603
+ }
604
+ if (!content) {
605
+ return;
606
+ }
607
+
608
+ let metadata;
609
+ try {
610
+ metadata = JSON.parse(content);
611
+ } catch (e) {
612
+ // invalid json format
613
+ }
614
+
615
+ if (!metadata) {
616
+ return;
617
+ }
618
+
619
+ Object.assign(caseItem, metadata);
620
+ return true;
621
+ }
622
+
623
+ testContentHandler(item) {
599
624
  if (item.content) {
600
625
  return;
601
626
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "2.5.2",
3
+ "version": "2.6.0",
4
4
  "description": "A playwright test reporter. Shows suites/cases/steps with tree style, markdown annotations, custom columns/formatters/data collection visitors, console logs, style tags, send email.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -20,6 +20,7 @@
20
20
  "scripts": {
21
21
  "link": "node ./scripts/link.js",
22
22
  "test": "npm run link && npx playwright test -c tests",
23
+ "test-data": "npm run link && npx playwright test tests/data -c tests",
23
24
  "test-page": "npm run link && npx playwright test tests/home-page -c tests",
24
25
  "test-coverage": "npm run link && npx playwright test tests/report-coverage -c tests",
25
26
  "test-network": "npm run link && npx playwright test tests/report-network -c tests",
@@ -47,20 +48,20 @@
47
48
  "koa": "^2.15.3",
48
49
  "koa-static-resolver": "^1.0.6",
49
50
  "lz-utils": "^2.0.2",
50
- "monocart-coverage-reports": "^2.8.5",
51
+ "monocart-coverage-reports": "^2.9.0",
51
52
  "monocart-formatter": "^3.0.0",
52
- "monocart-locator": "^1.0.0",
53
+ "monocart-locator": "^1.0.2",
53
54
  "nodemailer": "^6.9.14",
54
55
  "turbogrid": "^3.2.0"
55
56
  },
56
57
  "devDependencies": {
57
- "@playwright/test": "^1.44.1",
58
+ "@playwright/test": "^1.45.1",
58
59
  "axios": "^1.7.2",
59
60
  "dotenv": "^16.4.5",
60
- "eslint": "^9.5.0",
61
+ "eslint": "^9.6.0",
61
62
  "eslint-config-plus": "^2.0.2",
62
63
  "eslint-plugin-html": "^8.1.1",
63
- "eslint-plugin-vue": "^9.26.0",
64
+ "eslint-plugin-vue": "^9.27.0",
64
65
  "mermaid": "^10.9.1",
65
66
  "open": "8.4.2",
66
67
  "stylelint": "^16.6.1",