playwright-slack-report-burak 3.0.40 → 3.0.41

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.
@@ -19,10 +19,15 @@ try {
19
19
  }
20
20
 
21
21
  const SUMMARIES_DIR = path.join('./', 'playwright-artifacts');
22
- const NODE_ARTIFACTS_DIR = path.join(SUMMARIES_DIR, 'nodeArtifacts');
23
22
  const PLAYWRIGHT_REPORT_DIR = path.join('./', 'playwright-report');
24
23
  const FINAL_OUTPUT_DIR = path.join('./', 'playwright-report');
25
24
 
25
+ // Environment variables
26
+ const IS_CI = !!process.env.CI;
27
+ const GITHUB_TOKEN = process.env.SAFETYWINGTEST_GITHUB_TOKEN;
28
+ const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;
29
+ const GITHUB_RUN_ID = process.env.GITHUB_RUN_ID || 'local';
30
+
26
31
  class ResultsParser {
27
32
  result;
28
33
  separateFlakyTests;
@@ -91,7 +96,7 @@ class ResultsParser {
91
96
  fs.writeFileSync(nodeSummaryFile, JSON.stringify(nodeSummary, null, 2));
92
97
 
93
98
  if (this.shardIndex === 1 && this.totalShardCount > 1) {
94
- if (process.env.CI) {
99
+ if (IS_CI) {
95
100
  console.log('Fetching all artifacts...');
96
101
  await this.fetchAllArtifacts();
97
102
  } else {
@@ -331,7 +336,7 @@ class ResultsParser {
331
336
  console.log('Checking if all blob zips exist...');
332
337
 
333
338
  for (let i = 1; i <= this.totalShardCount; i++) {
334
- const blobZipFile = path.join(NODE_ARTIFACTS_DIR, `blob-report-node-${i}.zip`);
339
+ const blobZipFile = path.join(SUMMARIES_DIR, `blob-report-node-${i}.zip`);
335
340
  if (!fs.existsSync(blobZipFile)) {
336
341
  return false;
337
342
  }
@@ -345,28 +350,25 @@ class ResultsParser {
345
350
  fs.mkdirSync(SUMMARIES_DIR, { recursive: true });
346
351
  }
347
352
 
348
- // Create nodeArtifacts directory under summaries
349
- if (!fs.existsSync(NODE_ARTIFACTS_DIR)) {
350
- fs.mkdirSync(NODE_ARTIFACTS_DIR, { recursive: true });
351
- }
352
-
353
- // Copy entire contents of playwright-report to NODE_ARTIFACTS_DIR
353
+ // Copy entire contents of playwright-report to SUMMARIES_DIR
354
+ // This copies both blob-report-node-1.zip and node_summary_1.json to SUMMARIES_DIR
354
355
  const playwrightReportDir = path.join('./', 'playwright-report');
355
356
  if (fs.existsSync(playwrightReportDir)) {
356
- this.copyDirectoryRecursive(playwrightReportDir, NODE_ARTIFACTS_DIR);
357
- console.log(`Copied entire contents of playwright-report to ${NODE_ARTIFACTS_DIR}`);
357
+ this.copyDirectoryRecursive(playwrightReportDir, SUMMARIES_DIR);
358
+ console.log(`Copied entire contents of playwright-report to ${SUMMARIES_DIR}`);
358
359
  } else {
359
360
  console.warn('Warning: playwright-report directory not found');
360
361
  }
361
362
 
362
363
  while (!this.allNodeSummaryFilesExist() || !this.allBlobZipsExist()) {
364
+ console.log('Checking if all node summary files exist...');
363
365
  console.log('Waiting for all blob zips to exist...');
364
366
  if (!fs.existsSync(SUMMARIES_DIR)) {
365
367
  fs.mkdirSync(SUMMARIES_DIR, { recursive: true });
366
368
  }
367
369
  for (let i = 2; i <= this.totalShardCount; i++) {
368
370
  await this.fetchArtifact(i, `node_summary_${i}.json`, SUMMARIES_DIR);
369
- await this.fetchArtifact(i, `blob-report-node-${i}.zip`, NODE_ARTIFACTS_DIR);
371
+ await this.fetchArtifact(i, `blob-report-node-${i}.zip`, SUMMARIES_DIR);
370
372
  }
371
373
  }
372
374
  }
@@ -377,9 +379,7 @@ class ResultsParser {
377
379
  }
378
380
 
379
381
  async fetchArtifactFromGitHubActions(i, file, filePath) {
380
- const githubToken = process.env.SAFETYWINGTEST_GITHUB_TOKEN;
381
- const repo = process.env.GITHUB_REPOSITORY;
382
- const githubApiUrl = `https://api.github.com/repos/${repo}/actions/artifacts`;
382
+ const githubApiUrl = `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts`;
383
383
 
384
384
  // Try multiple artifact naming patterns
385
385
  const artifactNamePatterns = [
@@ -393,7 +393,7 @@ class ResultsParser {
393
393
  // List all artifacts to find the one we need
394
394
  const listResponse = await axios.get(githubApiUrl, {
395
395
  headers: {
396
- 'Authorization': `token ${githubToken}`,
396
+ 'Authorization': `token ${GITHUB_TOKEN}`,
397
397
  'Accept': 'application/vnd.github.v3+json'
398
398
  },
399
399
  params: {
@@ -416,7 +416,7 @@ class ResultsParser {
416
416
  // Download the artifact ZIP
417
417
  const downloadResponse = await axios.get(artifact.archive_download_url, {
418
418
  headers: {
419
- 'Authorization': `token ${githubToken}`,
419
+ 'Authorization': `token ${GITHUB_TOKEN}`,
420
420
  'Accept': 'application/vnd.github.v3+json'
421
421
  },
422
422
  responseType: 'arraybuffer'
@@ -460,7 +460,7 @@ class ResultsParser {
460
460
 
461
461
  // Copy all blob files to playwright-report before merging
462
462
  for (let i = 1; i <= this.totalShardCount; i++) {
463
- const blobZipFile = path.join(NODE_ARTIFACTS_DIR, `blob-report-node-${i}.zip`);
463
+ const blobZipFile = path.join(SUMMARIES_DIR, `blob-report-node-${i}.zip`);
464
464
  if (fs.existsSync(blobZipFile)) {
465
465
  try {
466
466
  const destFile = path.join(PLAYWRIGHT_REPORT_DIR, `blob-report-node-${i}.zip`);
@@ -489,8 +489,8 @@ class ResultsParser {
489
489
  }
490
490
  console.log('Reports merged successfully.');
491
491
 
492
- // After merge, extract all blobs from nodeArtifacts to playwright-report
493
- this.unzipBlobsAndCopyResources(NODE_ARTIFACTS_DIR, PLAYWRIGHT_REPORT_DIR);
492
+ // After merge, extract all blobs from SUMMARIES_DIR to playwright-report
493
+ this.unzipBlobsAndCopyResources(SUMMARIES_DIR, PLAYWRIGHT_REPORT_DIR);
494
494
  } catch (error) {
495
495
  // Log a warning instead of throwing an error
496
496
  console.warn('Warning: Failed to merge reports. This may not affect the overall process.', error.message);
@@ -516,17 +516,17 @@ class ResultsParser {
516
516
  }
517
517
  }
518
518
 
519
- unzipBlobsAndCopyResources(NODE_ARTIFACTS_DIR, FINAL_OUTPUT_DIR) {
519
+ unzipBlobsAndCopyResources(ARTIFACTS_DIR, FINAL_OUTPUT_DIR) {
520
520
  if (!AdmZip) {
521
521
  console.error('adm-zip is required for blob extraction. Please install it: npm install adm-zip');
522
522
  return;
523
523
  }
524
524
 
525
- // Unzip all blob files in nodeArtifacts into separate folders
525
+ // Unzip all blob files into separate folders
526
526
  for (let i = 1; i <= this.totalShardCount; i++) {
527
- const blobZipFile = path.join(NODE_ARTIFACTS_DIR, `blob-report-node-${i}.zip`);
527
+ const blobZipFile = path.join(ARTIFACTS_DIR, `blob-report-node-${i}.zip`);
528
528
  if (fs.existsSync(blobZipFile)) {
529
- const extractDir = path.join(NODE_ARTIFACTS_DIR, `node-${i}`);
529
+ const extractDir = path.join(ARTIFACTS_DIR, `${GITHUB_RUN_ID}-blob-contents-node-${i}`);
530
530
  if (!fs.existsSync(extractDir)) {
531
531
  fs.mkdirSync(extractDir, { recursive: true });
532
532
  }
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.40",
35
+ "version": "3.0.41",
36
36
  "main": "index.js",
37
37
  "types": "dist/index.d.ts",
38
38
  "author": "Burak B. <burak.boluk@hotmail.com>",