monocart-reporter 2.7.1 → 2.8.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.
@@ -72,9 +72,11 @@ const attachAuditReport = async (runnerResult, testInfo, options = {}) => {
72
72
  return;
73
73
  }
74
74
 
75
+ const outputDir = await Util.resolveOutputDir(testInfo);
76
+
75
77
  options = {
76
78
  name: `Lighthouse Report - ${testInfo.title}`,
77
- outputDir: Util.resolveOutputDir(testInfo, options),
79
+ outputDir,
78
80
  outputName: `audit-${Util.resolveTestIdWithRetry(testInfo)}`,
79
81
  ... options
80
82
  };
@@ -5,9 +5,7 @@ const Util = require('../../utils/util.js');
5
5
 
6
6
  const attachCoverageReport = async (data, testInfo, options = {}) => {
7
7
 
8
- const reporterOptions = Util.resolveReporterOptions(testInfo);
9
-
10
- const outputDir = Util.resolveOutputDir(testInfo, options);
8
+ const outputDir = await Util.resolveOutputDir(testInfo);
11
9
  const folderName = `coverage-${Util.resolveTestIdWithRetry(testInfo)}`;
12
10
 
13
11
  // support multiple calls
@@ -21,7 +19,7 @@ const attachCoverageReport = async (data, testInfo, options = {}) => {
21
19
  }
22
20
 
23
21
  const coverageOptions = {
24
- logging: reporterOptions.logging,
22
+ logging: Util.resolveLogging(testInfo, options),
25
23
  outputDir: htmlDir,
26
24
  name: `Coverage Report - ${testInfo.title}`,
27
25
  assetsPath: '../assets',
@@ -129,10 +129,12 @@ const attachNetworkReport = async (har, testInfo, options = {}) => {
129
129
  return;
130
130
  }
131
131
 
132
+ const outputDir = await Util.resolveOutputDir(testInfo);
133
+
132
134
  options = {
133
135
  // default title
134
136
  name: `Network Report - ${testInfo.title}`,
135
- outputDir: Util.resolveOutputDir(testInfo, options),
137
+ outputDir,
136
138
  outputName: `network-${Util.resolveTestIdWithRetry(testInfo)}`,
137
139
  inline: false,
138
140
  ... options
package/lib/utils/util.js CHANGED
@@ -9,8 +9,6 @@ const Share = require('../platform/share.js');
9
9
 
10
10
  const getDefaultOptions = require('../default/options.js');
11
11
 
12
- const assetsName = 'assets';
13
-
14
12
  const Util = {
15
13
  ... Share,
16
14
 
@@ -78,15 +76,11 @@ const Util = {
78
76
  return parsed;
79
77
  },
80
78
 
81
- resolveOutputDir: (testInfo, options) => {
82
- if (options && options.outputDir) {
83
- return options.outputDir;
84
- }
85
- const outputDir = testInfo.project.outputDir || testInfo.config.outputDir;
86
- if (outputDir) {
87
- return outputDir;
88
- }
89
- return path.resolve(testInfo.outputDir, '../');
79
+ resolveOutputDir: async (testInfo) => {
80
+ const reporterOptions = Util.resolveReporterOptions(testInfo);
81
+ const outputFile = await Util.resolveOutputFile(reporterOptions.outputFile);
82
+ const outputDir = path.dirname(outputFile);
83
+ return outputDir;
90
84
  },
91
85
 
92
86
  resolveOutputFile: async (outputFile) => {
@@ -98,6 +92,12 @@ const Util = {
98
92
  if (!outputFile || typeof outputFile !== 'string') {
99
93
  outputFile = getDefaultOptions().outputFile;
100
94
  }
95
+
96
+ // end with html
97
+ if (!outputFile.endsWith('.html')) {
98
+ outputFile = path.join(outputFile, 'index.html');
99
+ }
100
+
101
101
  return path.resolve(outputFile);
102
102
  },
103
103
 
@@ -109,7 +109,11 @@ const Util = {
109
109
  return reporterOptions.logging;
110
110
  },
111
111
 
112
+ // eslint-disable-next-line complexity
112
113
  resolveReporterOptions: (testInfo) => {
114
+ if (Util.reporterOptions) {
115
+ return Util.reporterOptions;
116
+ }
113
117
  if (!testInfo) {
114
118
  return {};
115
119
  }
@@ -119,6 +123,7 @@ const Util = {
119
123
  if (Array.isArray(item)) {
120
124
  const [name, options] = item;
121
125
  if (name && name.indexOf('monocart-reporter') !== -1) {
126
+ Util.reporterOptions = options;
122
127
  return options || {};
123
128
  }
124
129
  }
@@ -152,13 +157,6 @@ const Util = {
152
157
  });
153
158
  },
154
159
 
155
- initAssetsDir: async (options) => {
156
- const outputFile = await Util.resolveOutputFile(options.outputFile);
157
- const outputDir = path.dirname(outputFile);
158
- const assetsDir = path.resolve(outputDir, assetsName);
159
- Util.initDir(assetsDir);
160
- },
161
-
162
160
  getEOL: function(content) {
163
161
  if (!content) {
164
162
  return os.EOL;
@@ -276,7 +274,8 @@ const Util = {
276
274
  if (fs.existsSync(p)) {
277
275
  fs.rmSync(p, {
278
276
  recursive: true,
279
- force: true
277
+ force: true,
278
+ maxRetries: 10
280
279
  });
281
280
  }
282
281
  },
package/lib/visitor.js CHANGED
@@ -527,6 +527,8 @@ class Visitor {
527
527
  }
528
528
 
529
529
  // before path change
530
+ // Attachments with a text/html content type can now be opened in a new tab in the HTML report.
531
+ // This is useful for including third-party reports or other HTML content in the Playwright test report and distributing it to your team.
530
532
  this.reportHandler(item, 'audit', title);
531
533
  this.reportHandler(item, 'coverage', title);
532
534
  this.reportHandler(item, 'network', title);
@@ -536,6 +538,7 @@ class Visitor {
536
538
 
537
539
  const o = this.options;
538
540
  // store relative path first
541
+ this.copyAttachmentsHandler(item);
539
542
  item.path = Util.relativePath(item.path, o.outputDir);
540
543
 
541
544
  // custom attachment path
@@ -558,6 +561,37 @@ class Visitor {
558
561
  }
559
562
  }
560
563
 
564
+ copyAttachmentsHandler(item) {
565
+
566
+ const { attachmentsDir } = this.options;
567
+ if (!attachmentsDir) {
568
+ return;
569
+ }
570
+
571
+ if (!fs.existsSync(attachmentsDir)) {
572
+ fs.mkdirSync(attachmentsDir, {
573
+ recursive: true
574
+ });
575
+ }
576
+
577
+ // custom report
578
+ if (item.report) {
579
+ return;
580
+ }
581
+
582
+ const oldPath = item.path;
583
+ const filename = Util.calculateSha1(oldPath);
584
+ const ext = path.extname(oldPath);
585
+ const newPath = path.resolve(attachmentsDir, `${filename}${ext}`);
586
+ fs.cpSync(oldPath, newPath, {
587
+ force: true,
588
+ recursive: true
589
+ });
590
+
591
+ item.path = newPath;
592
+
593
+ }
594
+
561
595
  getImageCategory(item) {
562
596
  if (item.contentType && item.contentType.startsWith('image/')) {
563
597
  if (item.name) {
@@ -702,7 +736,10 @@ class Visitor {
702
736
  return;
703
737
  }
704
738
 
705
- const attachmentsPath = path.resolve(this.options.outputDir, caseId);
739
+ // testOutputDir is for test results not reporter
740
+ const { outputDir, testOutputDir } = this.options;
741
+
742
+ const attachmentsPath = path.resolve(testOutputDir || outputDir, caseId);
706
743
  if (!fs.existsSync(attachmentsPath)) {
707
744
  fs.mkdirSync(attachmentsPath, {
708
745
  recursive: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "2.7.1",
3
+ "version": "2.8.1",
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": {
@@ -46,27 +46,29 @@
46
46
  "koa": "^2.15.3",
47
47
  "koa-static-resolver": "^1.0.6",
48
48
  "lz-utils": "^2.1.0",
49
- "monocart-coverage-reports": "^2.10.3",
49
+ "monocart-coverage-reports": "^2.10.9",
50
50
  "monocart-locator": "^1.0.2",
51
- "nodemailer": "^6.9.14"
51
+ "nodemailer": "^6.9.15"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@babel/code-frame": "^7.24.7",
55
- "@playwright/test": "^1.46.1",
55
+ "@playwright/test": "^1.47.1",
56
56
  "ansi-to-html": "^0.7.2",
57
57
  "async-tick": "^1.0.0",
58
58
  "autolinker": "^4.0.0",
59
- "axios": "^1.7.5",
59
+ "axios": "^1.7.7",
60
60
  "commander": "^12.1.0",
61
61
  "dotenv": "^16.4.5",
62
- "eslint": "^9.9.1",
62
+ "eslint": "^9.10.0",
63
63
  "eslint-config-plus": "^2.0.2",
64
64
  "eslint-plugin-html": "^8.1.1",
65
- "eslint-plugin-vue": "^9.27.0",
65
+ "eslint-plugin-vue": "^9.28.0",
66
66
  "file-saver": "^2.0.5",
67
+ "find-up": "^7.0.0",
67
68
  "github-markdown-css": "^5.6.1",
68
- "marked": "^14.1.0",
69
- "mermaid": "^11.0.2",
69
+ "glob": "^11.0.0",
70
+ "marked": "^14.1.2",
71
+ "mermaid": "^11.2.1",
70
72
  "mitt": "^3.0.1",
71
73
  "monocart-code-viewer": "^1.1.4",
72
74
  "monocart-formatter": "^3.0.0",
@@ -75,7 +77,8 @@
75
77
  "sanitize-filename": "^1.6.3",
76
78
  "stack-utils": "^2.0.6",
77
79
  "stylelint": "^16.9.0",
78
- "stylelint-config-plus": "^1.1.2",
80
+ "stylelint-config-plus": "^1.1.3",
81
+ "supports-color": "^9.4.0",
79
82
  "turbogrid": "^3.2.0",
80
83
  "vine-ui": "^3.1.16",
81
84
  "ws": "^8.18.0"