playwright-slack-report-burak 2.2.2 → 2.3.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.
@@ -53,52 +53,43 @@ class ResultsParser {
53
53
  const totalTestCasesForNode = this.result.reduce((acc, suite) => acc + suite.testSuite.tests.length, 0);
54
54
 
55
55
  // Initialize or read existing summary from file
56
- let nodeSummary = {
56
+ const nodeSummary = {
57
57
  total: totalTestCasesForNode,
58
- passed: 0,
59
- failed: 0,
60
- flaky: 0,
58
+ passed: passes.length,
59
+ failed: failures.length,
60
+ flaky: (this.separateFlakyTests && flakes.length > 0) ?
61
+ flakes.length : 0,
61
62
  skipped: 0,
62
- failures: [],
63
+ failures,
63
64
  tests: [],
64
65
  };
65
-
66
- // Create the file if it doesn't exist
67
- if (!fs.existsSync(nodeSummaryFile)) {
68
- fs.writeFileSync(nodeSummaryFile, JSON.stringify(nodeSummary, null, 2));
69
- } else {
70
- nodeSummary = JSON.parse(fs.readFileSync(nodeSummaryFile, 'utf-8'));
71
- }
72
-
73
- // Update the node summary with new test results
74
66
  for (const suite of this.result) {
75
- nodeSummary.tests = nodeSummary.tests.concat(suite.testSuite.tests);
67
+ nodeSummary.tests = nodeSummary.tests.concat(suite.testSuite.tests);
76
68
  for (const test of suite.testSuite.tests) {
77
69
  if (test.status === 'skipped') {
78
70
  nodeSummary.skipped += 1;
79
71
  }
80
- if (test.status === 'failed' || test.status === 'timedOut') {
81
- nodeSummary.failed += 1;
82
- }
83
- if (this.separateFlakyTests && test.status === 'passed' && test.retry > 0) {
84
- nodeSummary.flaky += 1;
85
- }
86
- if (test.status === 'passed' && (!this.separateFlakyTests || test.retry === 0)) {
87
- nodeSummary.passed += 1;
88
- }
89
72
  }
90
73
  }
91
74
 
92
- // Write the updated summary back to the file for the current node
75
+ // Create the file
93
76
  fs.writeFileSync(nodeSummaryFile, JSON.stringify(nodeSummary, null, 2));
94
77
 
95
78
  if (this.shardIndex === 0 && this.totalShardCount > 1) {
96
- await this.fetchAllArtifacts();
79
+ if (process.env.CI) {
80
+ console.log('Fetching all artifacts...');
81
+ await this.fetchAllArtifacts();
82
+ } else {
83
+ while (!this.allNodeSummaryFilesExist() || !this.allBlobZipsExist()) {
84
+ console.log('Waiting for all both to exist...');
85
+ await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for 1 second
86
+ }
87
+ }
97
88
  }
98
89
 
99
90
  console.log('Contents of playwright-report for node', this.shardIndex, ':', fs.readdirSync(summariesDir));
100
91
 
101
- if (this.allNodeSummaryFilesExist() && this.allBlobZipsExist() && this.shardIndex === 0) {
92
+ if (this.shardIndex === 0 && this.allNodeSummaryFilesExist() && this.allBlobZipsExist()) {
102
93
  // Merge all node summaries into the final summary
103
94
  for (let i = 0; i < this.totalShardCount; i++) {
104
95
  const nodeSummaryFile = path.join(summariesDir, `node_summary_${i}.json`);
@@ -301,7 +292,7 @@ class ResultsParser {
301
292
 
302
293
  async fetchArtifact(i, file, summariesDir) {
303
294
  const circleciToken = process.env.safetywingtest_CIRCLECI_API_TOKEN;
304
- const circleciJobId = process.env.CIRCLE_WORKFLOW_JOB_ID || '5175a4cb-273e-42fd-a5a6-40c3dc31c9de';
295
+ const circleciJobId = process.env.CIRCLE_WORKFLOW_JOB_ID || '8133c154-ceb3-466c-b4e1-d3d8768b60fa';
305
296
  const circleciApiUrl = `https://output.circle-artifacts.com/output/job/${circleciJobId}/artifacts/${i}/html-report/${file}`;
306
297
  const filePath = path.join(summariesDir, file);
307
298
 
@@ -329,13 +320,20 @@ class ResultsParser {
329
320
  }
330
321
  }
331
322
  mergeReports() {
323
+ let breakMergeWaiter = false;
332
324
  try {
333
325
  // Execute the command to merge reports
334
326
  exec(`npx playwright merge-reports --reporter html -c ./playwright-report playwright-report`);
335
327
  // Wait until index.html exists
336
328
  while (!fs.existsSync(path.join('./playwright-report', 'index.html'))) {
337
- console.log('Waiting for merged html report to be generated...');
338
- setTimeout(() => {}, 3000);
329
+ console.log('Waiting 2 seconds for merged html report to be generated...');
330
+ const currentTime = new Date().getTime();
331
+ breakMergeWaiter = false;
332
+ while (!breakMergeWaiter) {
333
+ if(new Date().getTime() - currentTime > 2000) {
334
+ breakMergeWaiter = true;
335
+ }
336
+ }
339
337
  }
340
338
  console.log('Reports merged successfully.');
341
339
  console.log('Contents of playwright-report:', fs.readdirSync('./playwright-report'));
@@ -71,7 +71,7 @@ class SlackReporter {
71
71
  return;
72
72
  }
73
73
  const resultSummary = await this.resultsParser.getParsedResults();
74
- // SHARDING SUPPORT - Stop slack messages for non-zero index node
74
+ // SHARDING SUPPORT - Stop slack messages for non-zero index node(s)
75
75
  if (process.env.CIRCLE_NODE_INDEX && process.env.CIRCLE_NODE_INDEX !== '0') {
76
76
  this.log(`❌ Stopping reporter for non-zero index node ${process.env.CIRCLE_NODE_INDEX} of ${process.env.CIRCLE_NODE_TOTAL}`);
77
77
  return;
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "lint-fix": "npx eslint . --ext .ts --fix"
31
31
  },
32
32
  "name": "playwright-slack-report-burak",
33
- "version": "2.2.2",
33
+ "version": "2.3.1",
34
34
  "main": "index.js",
35
35
  "types": "dist/index.d.ts",
36
36
  "repository": "git@github.com:ryanrosello-og/playwright-slack-report.git",