monocart-reporter 1.7.9 → 1.7.11

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/visitor.js CHANGED
@@ -506,12 +506,13 @@ class Visitor {
506
506
 
507
507
  if (item.body) {
508
508
  if (!item.path) {
509
- this.saveAttachmentHandler(item, i, caseId);
509
+ this.saveAttachmentBodyHandler(item, i, caseId);
510
510
  }
511
- delete item.body;
512
511
  }
513
512
 
513
+ // text attachment may no path
514
514
  if (!item.path) {
515
+ list.push(item);
515
516
  return;
516
517
  }
517
518
 
@@ -584,12 +585,38 @@ class Visitor {
584
585
  }
585
586
 
586
587
  contentHandler(item) {
587
- if (item.contentType && item.contentType.startsWith('text')) {
588
+ if (item.content) {
589
+ return;
590
+ }
591
+ if (Util.isTextType(item.contentType)) {
588
592
  item.content = Util.readFileSync(item.path);
589
593
  }
590
594
  }
591
595
 
592
- saveAttachmentHandler(item, i, caseId) {
596
+ contentToString(content) {
597
+ if (typeof content === 'string') {
598
+ return content;
599
+ }
600
+
601
+ if (Buffer.isBuffer(content)) {
602
+ return content.toString('utf8');
603
+ }
604
+
605
+ return content.toString();
606
+ }
607
+
608
+ saveAttachmentBodyHandler(item, i, caseId) {
609
+
610
+ const content = item.body;
611
+ delete item.body;
612
+
613
+ // if text content no need save file, just show the content
614
+ const contentType = item.contentType;
615
+ if (Util.isTextType(contentType)) {
616
+ // body is buffer
617
+ item.content = this.contentToString(content);
618
+ return;
619
+ }
593
620
 
594
621
  const attachmentsPath = path.resolve(this.options.outputDir, caseId);
595
622
  if (!fs.existsSync(attachmentsPath)) {
@@ -598,21 +625,22 @@ class Visitor {
598
625
  });
599
626
  }
600
627
 
628
+ // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
601
629
  const types = {
602
630
  'text/plain': 'txt',
603
- 'application/octet-stream': 'data'
631
+ 'application/octet-stream': 'bin'
604
632
  };
605
633
 
606
634
  const filename = sanitize(`${item.name}-${i + 1}`);
607
635
 
608
- let ext = 'data';
609
- const contentType = item.contentType;
636
+ let ext = 'bin';
610
637
  if (contentType) {
611
638
  ext = types[contentType] || contentType.split('/').pop().slice(0, 4);
612
639
  }
613
640
  const filePath = path.resolve(attachmentsPath, `${filename}.${ext}`);
614
- fs.writeFileSync(filePath, item.body);
641
+ fs.writeFileSync(filePath, content);
615
642
  item.path = filePath;
643
+
616
644
  }
617
645
 
618
646
  locationHandler(location) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "1.7.9",
3
+ "version": "1.7.11",
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": {
@@ -52,10 +52,10 @@
52
52
  "open": "^9.1.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@playwright/test": "^1.38.0",
55
+ "@playwright/test": "^1.38.1",
56
56
  "axios": "^1.5.0",
57
57
  "dotenv": "^16.3.1",
58
- "eslint": "^8.49.0",
58
+ "eslint": "^8.50.0",
59
59
  "eslint-config-plus": "^1.0.6",
60
60
  "eslint-plugin-html": "^7.1.0",
61
61
  "eslint-plugin-vue": "^9.17.0",