playwright-slack-report-burak 3.0.33 → 3.0.34

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 @@ try {
18
18
  AdmZip = null;
19
19
  }
20
20
 
21
+ const SUMMARIES_DIR = path.join('./', 'playwright-report');
22
+ const NODE_ARTIFACTS_DIR = path.join(SUMMARIES_DIR, 'nodeArtifacts');
23
+ const FINAL_OUTPUT_DIR = path.join(SUMMARIES_DIR, 'finalOutput');
24
+
21
25
  class ResultsParser {
22
26
  result;
23
27
  separateFlakyTests;
@@ -50,17 +54,15 @@ class ResultsParser {
50
54
  }*/
51
55
 
52
56
  // Define the directory to store node summaries
53
- const summariesDir = path.join('./', 'playwright-report');
54
-
55
- if (!fs.existsSync(summariesDir)) {
56
- fs.mkdirSync(summariesDir, { recursive: true });
57
+ if (!fs.existsSync(SUMMARIES_DIR)) {
58
+ fs.mkdirSync(SUMMARIES_DIR, { recursive: true });
57
59
  }
58
60
 
59
61
  // Determine the current node index
60
62
  const currentNodeIndex = this.shardIndex;
61
63
 
62
64
  // Define the file for the current node's summary
63
- const nodeSummaryFile = path.join(summariesDir, `node_summary_${currentNodeIndex}.json`);
65
+ const nodeSummaryFile = path.join(SUMMARIES_DIR, `node_summary_${currentNodeIndex}.json`);
64
66
 
65
67
  const totalTestCasesForNode = this.result.reduce((acc, suite) => acc + suite.testSuite.tests.length, 0);
66
68
 
@@ -102,7 +104,7 @@ class ResultsParser {
102
104
  if (this.shardIndex === 1 && this.allNodeSummaryFilesExist() && this.allBlobZipsExist()) {
103
105
  // Merge all node summaries into the final summary
104
106
  for (let i = 1; i <= this.totalShardCount; i++) {
105
- const nodeSummaryFile = path.join(summariesDir, `node_summary_${i}.json`);
107
+ const nodeSummaryFile = path.join(SUMMARIES_DIR, `node_summary_${i}.json`);
106
108
  const fileToRead = nodeSummaryFile;
107
109
 
108
110
  if (fs.existsSync(fileToRead)) {
@@ -314,10 +316,9 @@ class ResultsParser {
314
316
  }*/
315
317
  allNodeSummaryFilesExist() {
316
318
  console.log('Checking if all node summary files exist...');
317
- const summariesDir = path.join('./', 'playwright-report');
318
319
 
319
320
  for (let i = 1; i <= this.totalShardCount; i++) {
320
- const nodeSummaryFile = path.join(summariesDir, `node_summary_${i}.json`);
321
+ const nodeSummaryFile = path.join(SUMMARIES_DIR, `node_summary_${i}.json`);
321
322
  if (!fs.existsSync(nodeSummaryFile)) {
322
323
  return false;
323
324
  }
@@ -327,10 +328,9 @@ class ResultsParser {
327
328
 
328
329
  allBlobZipsExist() {
329
330
  console.log('Checking if all blob zips exist...');
330
- const summariesDir = path.join('./', 'playwright-report');
331
331
 
332
332
  for (let i = 1; i <= this.totalShardCount; i++) {
333
- const blobZipFile = path.join(summariesDir, `blob-report-node-${i}.zip`);
333
+ const blobZipFile = path.join(NODE_ARTIFACTS_DIR, `blob-report-node-${i}.zip`);
334
334
  if (!fs.existsSync(blobZipFile)) {
335
335
  return false;
336
336
  }
@@ -339,21 +339,54 @@ class ResultsParser {
339
339
  }
340
340
 
341
341
  async fetchAllArtifacts() {
342
- const summariesDir = path.join('./', 'playwright-report');
342
+ // Ensure playwright-report directory exists
343
+ if (!fs.existsSync(SUMMARIES_DIR)) {
344
+ fs.mkdirSync(SUMMARIES_DIR, { recursive: true });
345
+ }
346
+
347
+ // Create nodeArtifacts directory under playwright-report
348
+ if (!fs.existsSync(NODE_ARTIFACTS_DIR)) {
349
+ fs.mkdirSync(NODE_ARTIFACTS_DIR, { recursive: true });
350
+ }
351
+
352
+ // Copy artifacts from node 1 to nodeArtifacts
353
+ // Check multiple potential locations for node 1's blob file
354
+ const possibleNode1BlobSources = [
355
+ path.join(SUMMARIES_DIR, 'blob-report-node-1.zip'),
356
+ path.join('./', 'blob-report-node-1.zip'),
357
+ path.join(SUMMARIES_DIR, 'blob-report-1.zip'),
358
+ ];
359
+
360
+ const node1BlobDest = path.join(NODE_ARTIFACTS_DIR, 'blob-report-node-1.zip');
361
+ let node1BlobCopied = false;
362
+
363
+ for (const source of possibleNode1BlobSources) {
364
+ if (fs.existsSync(source)) {
365
+ fs.copyFileSync(source, node1BlobDest);
366
+ console.log(`Copied ${source} to nodeArtifacts`);
367
+ node1BlobCopied = true;
368
+ break;
369
+ }
370
+ }
371
+
372
+ if (!node1BlobCopied) {
373
+ console.warn('Warning: blob-report-node-1.zip not found in expected locations');
374
+ }
375
+
343
376
  while (!this.allNodeSummaryFilesExist() || !this.allBlobZipsExist()) {
344
377
  console.log('Waiting for all blob zips to exist...');
345
- if (!fs.existsSync(summariesDir)) {
346
- fs.mkdirSync(summariesDir, { recursive: true });
378
+ if (!fs.existsSync(SUMMARIES_DIR)) {
379
+ fs.mkdirSync(SUMMARIES_DIR, { recursive: true });
347
380
  }
348
381
  for (let i = 2; i <= this.totalShardCount; i++) {
349
- await this.fetchArtifact(i, `node_summary_${i}.json`, summariesDir);
350
- await this.fetchArtifact(i, `blob-report-node-${i}.zip`, summariesDir);
382
+ await this.fetchArtifact(i, `node_summary_${i}.json`, SUMMARIES_DIR);
383
+ await this.fetchArtifact(i, `blob-report-node-${i}.zip`, NODE_ARTIFACTS_DIR);
351
384
  }
352
385
  }
353
386
  }
354
387
 
355
- async fetchArtifact(i, file, summariesDir) {
356
- const filePath = path.join(summariesDir, file);
388
+ async fetchArtifact(i, file, targetDir) {
389
+ const filePath = path.join(targetDir, file);
357
390
  await this.fetchArtifactFromGitHubActions(i, file, filePath);
358
391
  }
359
392
 
@@ -438,10 +471,47 @@ class ResultsParser {
438
471
  mergeReports() {
439
472
  let breakMergeWaiter = false;
440
473
  try {
441
- // Execute the command to merge reports
442
- exec(`npx playwright merge-reports --reporter html -c ./playwright-report playwright-report`);
443
- // Wait until index.html exists
444
- while (!fs.existsSync(path.join('./playwright-report', 'index.html'))) {
474
+ // Ensure playwright-report directory exists
475
+ if (!fs.existsSync(SUMMARIES_DIR)) {
476
+ fs.mkdirSync(SUMMARIES_DIR, { recursive: true });
477
+ }
478
+
479
+ // Create finalOutput directory under playwright-report
480
+ if (!fs.existsSync(FINAL_OUTPUT_DIR)) {
481
+ fs.mkdirSync(FINAL_OUTPUT_DIR, { recursive: true });
482
+ }
483
+
484
+ // Extract blob files before merging (Playwright merge-reports expects extracted blob directories)
485
+ // We'll extract them temporarily for merging, then extract again for resource copying
486
+ const tempMergeDir = path.join(NODE_ARTIFACTS_DIR, 'temp-merge');
487
+ if (!fs.existsSync(tempMergeDir)) {
488
+ fs.mkdirSync(tempMergeDir, { recursive: true });
489
+ }
490
+
491
+ // Extract all blob zip files to temp directory for merging
492
+ if (!AdmZip) {
493
+ console.error('adm-zip is required for blob extraction. Please install it: npm install adm-zip');
494
+ return;
495
+ }
496
+
497
+ for (let i = 1; i <= this.totalShardCount; i++) {
498
+ const blobZipFile = path.join(NODE_ARTIFACTS_DIR, `blob-report-node-${i}.zip`);
499
+ if (fs.existsSync(blobZipFile)) {
500
+ try {
501
+ const zip = new AdmZip(blobZipFile);
502
+ zip.extractAllTo(tempMergeDir, true);
503
+ console.log(`Extracted blob-report-node-${i}.zip for merging`);
504
+ } catch (error) {
505
+ console.warn(`Failed to extract blob-report-node-${i}.zip for merging:`, error.message);
506
+ }
507
+ }
508
+ }
509
+
510
+ // Execute the command to merge reports FROM tempMergeDir INTO finalOutput
511
+ exec(`npx playwright merge-reports --reporter html ${tempMergeDir} ${FINAL_OUTPUT_DIR}`);
512
+
513
+ // Wait until index.html exists in finalOutput
514
+ while (!fs.existsSync(path.join(FINAL_OUTPUT_DIR, 'index.html'))) {
445
515
  console.log('Waiting 2 seconds for merged html report to be generated...');
446
516
  const currentTime = new Date().getTime();
447
517
  breakMergeWaiter = false;
@@ -452,10 +522,62 @@ class ResultsParser {
452
522
  }
453
523
  }
454
524
  console.log('Reports merged successfully.');
525
+
526
+ // Once merge is complete, unzip all blobs in nodeArtifacts into separate folders
527
+ this.unzipBlobsAndCopyResources(NODE_ARTIFACTS_DIR, FINAL_OUTPUT_DIR);
455
528
  } catch (error) {
456
529
  // Log a warning instead of throwing an error
457
530
  console.warn('Warning: Failed to merge reports. This may not affect the overall process.', error.message);
458
531
  }
459
532
  }
533
+
534
+ unzipBlobsAndCopyResources(nodeArtifactsDir, finalOutputDir) {
535
+ if (!AdmZip) {
536
+ console.error('adm-zip is required for blob extraction. Please install it: npm install adm-zip');
537
+ return;
538
+ }
539
+
540
+ // Unzip all blob files in nodeArtifacts into separate folders
541
+ for (let i = 1; i <= this.totalShardCount; i++) {
542
+ const blobZipFile = path.join(nodeArtifactsDir, `blob-report-node-${i}.zip`);
543
+ if (fs.existsSync(blobZipFile)) {
544
+ const extractDir = path.join(nodeArtifactsDir, `node-${i}`);
545
+ if (!fs.existsSync(extractDir)) {
546
+ fs.mkdirSync(extractDir, { recursive: true });
547
+ }
548
+
549
+ try {
550
+ const zip = new AdmZip(blobZipFile);
551
+ zip.extractAllTo(extractDir, true);
552
+ console.log(`Extracted blob-report-node-${i}.zip to ${extractDir}`);
553
+
554
+ // Check if this folder contains a "resources" folder with zip files
555
+ const resourcesDir = path.join(extractDir, 'resources');
556
+ if (fs.existsSync(resourcesDir) && fs.statSync(resourcesDir).isDirectory()) {
557
+ const files = fs.readdirSync(resourcesDir);
558
+ const zipFiles = files.filter(file => file.endsWith('.zip'));
559
+
560
+ if (zipFiles.length > 0) {
561
+ // Copy the resources folder to finalOutput
562
+ const finalResourcesDir = path.join(finalOutputDir, 'resources');
563
+ if (!fs.existsSync(finalResourcesDir)) {
564
+ fs.mkdirSync(finalResourcesDir, { recursive: true });
565
+ }
566
+
567
+ // Copy each zip file to finalOutput/resources
568
+ for (const zipFile of zipFiles) {
569
+ const sourceFile = path.join(resourcesDir, zipFile);
570
+ const destFile = path.join(finalResourcesDir, zipFile);
571
+ fs.copyFileSync(sourceFile, destFile);
572
+ console.log(`Copied ${zipFile} to finalOutput/resources`);
573
+ }
574
+ }
575
+ }
576
+ } catch (error) {
577
+ console.warn(`Failed to extract or process blob-report-node-${i}.zip:`, error.message);
578
+ }
579
+ }
580
+ }
581
+ }
460
582
  }
461
583
  exports.default = ResultsParser;
package/package.json CHANGED
@@ -32,7 +32,7 @@
32
32
  "lint-fix": "npx eslint . --ext .ts --fix"
33
33
  },
34
34
  "name": "playwright-slack-report-burak",
35
- "version": "3.0.33",
35
+ "version": "3.0.34",
36
36
  "main": "index.js",
37
37
  "types": "dist/index.d.ts",
38
38
  "author": "Burak B. <burak.boluk@hotmail.com>",