monocart-reporter 2.9.2 → 2.9.4

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,38 +18,26 @@ const generateJson = (outputDir, filename, reportData, options) => {
18
18
  reportData.jsonPath = Util.relativePath(jsonPath);
19
19
  };
20
20
 
21
- const forEachFile = (dir, callback) => {
22
- if (!fs.existsSync(dir)) {
21
+ const generateZip = (outputDir, filename, reportData, options) => {
22
+
23
+ if (!options.zip) {
23
24
  return;
24
25
  }
25
- const dirs = [];
26
- fs.readdirSync(dir, {
27
- withFileTypes: true
28
- }).forEach((it) => {
29
26
 
30
- if (it.isFile()) {
31
- callback(it.name, dir);
32
- return;
27
+ let zipPath = path.resolve(outputDir, `${filename}.zip`);
28
+ if (typeof options.zip === 'string') {
29
+ zipPath = options.zip;
30
+ if (!zipPath.endsWith('.zip')) {
31
+ zipPath += '.zip';
33
32
  }
34
-
35
- if (it.isDirectory()) {
36
- dirs.push(path.resolve(dir, it.name));
33
+ const zipDir = path.dirname(zipPath);
34
+ if (!fs.existsSync(zipDir)) {
35
+ fs.mkdirSync(zipDir, {
36
+ recursive: true
37
+ });
37
38
  }
38
- });
39
-
40
- for (const subDir of dirs) {
41
- forEachFile(subDir, callback);
42
- }
43
-
44
- };
45
-
46
- const generateZip = (outputDir, filename, reportData, options) => {
47
-
48
- if (!options.zip) {
49
- return;
50
39
  }
51
40
 
52
- const zipPath = path.resolve(outputDir, `${filename}.zip`);
53
41
  const reportFiles = [];
54
42
  return new Promise((resolve) => {
55
43
  const zipFile = new ZipFile();
@@ -62,7 +50,7 @@ const generateZip = (outputDir, filename, reportData, options) => {
62
50
  resolve();
63
51
  });
64
52
 
65
- forEachFile(outputDir, (name, dir) => {
53
+ Util.forEachFile(outputDir, (name, dir) => {
66
54
  const absPath = path.resolve(dir, name);
67
55
  const relPath = Util.relativePath(absPath, outputDir);
68
56
  reportFiles.push(relPath);
package/lib/index.d.ts CHANGED
@@ -56,8 +56,12 @@ export type MonocartReporterOptions = {
56
56
 
57
57
  /** output json file for data only */
58
58
  json?: boolean;
59
- /** output zip file for all report files */
60
- zip?: boolean;
59
+
60
+ /** output zip file for all report files
61
+ * {boolean} using default path
62
+ * {string} zip file path
63
+ */
64
+ zip?: boolean | string;
61
65
 
62
66
  /**
63
67
  * whether to copy attachments to the reporter output dir, defaults to true
package/lib/merge-data.js CHANGED
@@ -36,8 +36,22 @@ const unzipDataFile = async (item, num, options) => {
36
36
  // Do not forget to close the file once you're done
37
37
  await zip.close();
38
38
 
39
- const filename = path.basename(item, '.zip');
40
- return path.resolve(unzipDir, `${filename}.json`);
39
+ let filename = path.basename(item, '.zip');
40
+ let jsonPath = path.resolve(unzipDir, `${filename}.json`);
41
+ if (fs.existsSync(jsonPath)) {
42
+ return jsonPath;
43
+ }
44
+
45
+ Util.forEachFile(unzipDir, (name, dir) => {
46
+ if (name.endsWith('.html')) {
47
+ filename = path.basename(name, '.html');
48
+ return 'break';
49
+ }
50
+ }, true);
51
+
52
+ jsonPath = path.resolve(unzipDir, `${filename}.json`);
53
+
54
+ return jsonPath;
41
55
  };
42
56
 
43
57
  const getReportData = async (item, num, options) => {
package/lib/utils/util.js CHANGED
@@ -277,6 +277,50 @@ const Util = {
277
277
  }
278
278
  },
279
279
 
280
+ // eslint-disable-next-line complexity
281
+ forEachFile: (dir, callback, shallow) => {
282
+ if (!fs.existsSync(dir)) {
283
+ return;
284
+ }
285
+
286
+ const isBreak = (res) => {
287
+ return res === 'break' || res === false;
288
+ };
289
+
290
+ const dirs = [];
291
+ const list = fs.readdirSync(dir, {
292
+ withFileTypes: true
293
+ });
294
+
295
+ for (const item of list) {
296
+
297
+ if (item.isFile()) {
298
+ const res = callback(item.name, dir);
299
+ if (isBreak(res)) {
300
+ return res;
301
+ }
302
+ continue;
303
+ }
304
+
305
+ if (item.isDirectory()) {
306
+ dirs.push(path.resolve(dir, item.name));
307
+ }
308
+
309
+ }
310
+
311
+ if (shallow) {
312
+ return;
313
+ }
314
+
315
+ for (const subDir of dirs) {
316
+ const res = Util.forEachFile(subDir, callback, shallow);
317
+ if (isBreak(res)) {
318
+ return res;
319
+ }
320
+ }
321
+
322
+ },
323
+
280
324
  getTemplate: function(templatePath) {
281
325
  if (!Util.templateCache) {
282
326
  Util.templateCache = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocart-reporter",
3
- "version": "2.9.2",
3
+ "version": "2.9.4",
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": {
@@ -47,7 +47,7 @@
47
47
  "koa": "^2.15.3",
48
48
  "koa-static-resolver": "^1.0.6",
49
49
  "lz-utils": "^2.1.0",
50
- "monocart-coverage-reports": "^2.11.0",
50
+ "monocart-coverage-reports": "^2.11.1",
51
51
  "monocart-locator": "^1.0.2",
52
52
  "nodemailer": "^6.9.15"
53
53
  },
@@ -60,7 +60,7 @@
60
60
  "axios": "^1.7.7",
61
61
  "commander": "^12.1.0",
62
62
  "dotenv": "^16.4.5",
63
- "eslint": "^9.11.1",
63
+ "eslint": "^9.12.0",
64
64
  "eslint-config-plus": "^2.0.2",
65
65
  "eslint-plugin-html": "^8.1.2",
66
66
  "eslint-plugin-vue": "^9.28.0",