playwright-slack-report-burak 3.0.14 → 3.0.16

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,18 @@ try {
18
18
  AdmZip = null;
19
19
  }
20
20
 
21
+ // Get package version
22
+ let packageVersion = 'unknown';
23
+ try {
24
+ const packageJsonPath = path.join(__dirname, '../../package.json');
25
+ if (fs.existsSync(packageJsonPath)) {
26
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
27
+ packageVersion = packageJson.version || 'unknown';
28
+ }
29
+ } catch (e) {
30
+ // Version detection failed, use default
31
+ }
32
+
21
33
  class ResultsParser {
22
34
  result;
23
35
  separateFlakyTests;
@@ -34,6 +46,8 @@ class ResultsParser {
34
46
  constructor(options = { separateFlakyTests: false }) {
35
47
  this.result = [];
36
48
  this.separateFlakyTests = options.separateFlakyTests;
49
+ // Log package version
50
+ console.log(`📦 [ResultsParser] playwright-slack-report-burak v${packageVersion}`);
37
51
  // Log shard detection in ResultsParser
38
52
  console.log('🔍 [ResultsParser] Initialized with shard detection:');
39
53
  console.log(`🔍 MATRIX_SHARD env: ${process.env.MATRIX_SHARD !== undefined ? `"${process.env.MATRIX_SHARD}"` : 'undefined'}`);
@@ -13,6 +13,21 @@ try {
13
13
  // axios optional for GitHub Actions API detection
14
14
  axios = null;
15
15
  }
16
+
17
+ // Get package version
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ let packageVersion = 'unknown';
21
+ try {
22
+ const packageJsonPath = path.join(__dirname, '../../package.json');
23
+ if (fs.existsSync(packageJsonPath)) {
24
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
25
+ packageVersion = packageJson.version || 'unknown';
26
+ }
27
+ } catch (e) {
28
+ // Version detection failed, use default
29
+ }
30
+
16
31
  class SlackReporter {
17
32
  customLayout;
18
33
  customLayoutAsync;
@@ -31,7 +46,11 @@ class SlackReporter {
31
46
  suite;
32
47
  separateFlaky = false;
33
48
  logs = [];
49
+ fullConfig;
34
50
  onBegin(fullConfig, suite) {
51
+ // Log package version
52
+ console.log(`📦 [SlackReporter] playwright-slack-report-burak v${packageVersion}`);
53
+ this.fullConfig = fullConfig;
35
54
  this.suite = suite;
36
55
  this.logs = [];
37
56
  const slackReporterConfig = fullConfig.reporter.filter((f) => f[0].toLowerCase().includes('slackreporter'))[0][1];
@@ -306,38 +325,66 @@ class SlackReporter {
306
325
 
307
326
  this.log('🔍 [Shard Detection] Starting shard detection logic...');
308
327
 
328
+ // Check if we're actually running in GitHub Actions (not just env vars set locally)
329
+ const isActuallyInGitHubActions = process.env.GITHUB_ACTIONS === 'true' &&
330
+ process.env.GITHUB_RUN_ID !== undefined &&
331
+ process.env.GITHUB_RUNNER_NAME !== undefined;
332
+
309
333
  // Log all relevant environment variables
310
334
  this.log(`🔍 [Shard Detection] Environment variables:`);
311
335
  this.log(`🔍 CI: ${process.env.CI !== undefined ? `"${process.env.CI}"` : 'undefined'}`);
312
336
  this.log(`🔍 GITHUB_ACTIONS: ${process.env.GITHUB_ACTIONS !== undefined ? `"${process.env.GITHUB_ACTIONS}"` : 'undefined'}`);
313
337
  this.log(`🔍 GITHUB_JOB: ${process.env.GITHUB_JOB !== undefined ? `"${process.env.GITHUB_JOB}"` : 'undefined'}`);
338
+ this.log(`🔍 GITHUB_RUN_ID: ${process.env.GITHUB_RUN_ID !== undefined ? `"${process.env.GITHUB_RUN_ID}"` : 'undefined'}`);
339
+ this.log(`🔍 GITHUB_RUNNER_NAME: ${process.env.GITHUB_RUNNER_NAME !== undefined ? `"${process.env.GITHUB_RUNNER_NAME}"` : 'undefined'}`);
314
340
  this.log(`🔍 MATRIX_SHARD: ${process.env.MATRIX_SHARD !== undefined ? `"${process.env.MATRIX_SHARD}"` : 'undefined'}`);
315
341
  this.log(`🔍 MATRIX_INDEX: ${process.env.MATRIX_INDEX !== undefined ? `"${process.env.MATRIX_INDEX}"` : 'undefined'}`);
316
342
  this.log(`🔍 MATRIX_COUNT: ${process.env.MATRIX_COUNT !== undefined ? `"${process.env.MATRIX_COUNT}"` : 'undefined'}`);
317
343
 
318
- // Step 1: Try GitHub Actions API detection (most robust for GitHub Actions)
344
+ // Check Playwright's shard config (highest priority for local runs)
345
+ let playwrightShardInfo = null;
346
+ if (this.fullConfig && this.fullConfig.shard) {
347
+ playwrightShardInfo = {
348
+ current: this.fullConfig.shard.current,
349
+ total: this.fullConfig.shard.total
350
+ };
351
+ this.log(`🔍 [Shard Detection] Found Playwright shard config: ${playwrightShardInfo.current}/${playwrightShardInfo.total}`);
352
+ }
353
+
354
+ // Step 1: Try GitHub Actions API detection (only if actually in GitHub Actions)
319
355
  let githubApiShardInfo = null;
320
- if (process.env.GITHUB_ACTIONS === 'true') {
321
- this.log(`🔍 [Shard Detection] Attempting GitHub Actions API detection...`);
356
+ if (isActuallyInGitHubActions) {
357
+ this.log(`🔍 [Shard Detection] Actually running in GitHub Actions - attempting API detection...`);
322
358
  githubApiShardInfo = await this.detectGitHubActionsShardInfo();
359
+ } else if (process.env.GITHUB_ACTIONS === 'true') {
360
+ this.log(`🔍 [Shard Detection] GitHub Actions env vars set but not actually in runner - skipping API detection`);
323
361
  }
324
362
 
325
- // Step 2: Detect shard index from environment variables (priority)
326
- let currentShardIndex = process.env.MATRIX_SHARD !== undefined
327
- ? process.env.MATRIX_SHARD
328
- : (process.env.MATRIX_INDEX !== undefined ? process.env.MATRIX_INDEX : undefined);
329
-
330
- // Step 3: Use GitHub API detection if env vars not set
331
- if (currentShardIndex === undefined && githubApiShardInfo) {
363
+ // Step 2: Detect shard index (priority order: Playwright config > env vars > GitHub API)
364
+ let currentShardIndex;
365
+ if (playwrightShardInfo) {
366
+ // Playwright uses 1-based indexing, convert to 0-based
367
+ currentShardIndex = (playwrightShardInfo.current - 1).toString();
368
+ this.log(`🔍 [Shard Detection] Using Playwright shard config (converted to 0-based): "${currentShardIndex}"`);
369
+ } else if (process.env.MATRIX_SHARD !== undefined) {
370
+ currentShardIndex = process.env.MATRIX_SHARD;
371
+ this.log(`🔍 [Shard Detection] Using MATRIX_SHARD env var: "${currentShardIndex}"`);
372
+ } else if (process.env.MATRIX_INDEX !== undefined) {
373
+ currentShardIndex = process.env.MATRIX_INDEX;
374
+ this.log(`🔍 [Shard Detection] Using MATRIX_INDEX env var: "${currentShardIndex}"`);
375
+ } else if (githubApiShardInfo) {
332
376
  currentShardIndex = githubApiShardInfo.shardIndex.toString();
333
377
  this.log(`🔍 [Shard Detection] Using GitHub API detected shardIndex: "${currentShardIndex}"`);
334
378
  }
335
379
 
336
380
  this.log(`🔍 [Shard Detection] Initial currentShardIndex: ${currentShardIndex !== undefined ? `"${currentShardIndex}"` : 'undefined'}`);
337
381
 
338
- // Step 4: Get shard count from multiple sources (priority order)
382
+ // Step 3: Get shard count from multiple sources (priority order)
339
383
  let totalShards;
340
- if (process.env.MATRIX_COUNT !== undefined) {
384
+ if (playwrightShardInfo) {
385
+ totalShards = playwrightShardInfo.total;
386
+ this.log(`🔍 [Shard Detection] Using Playwright shard config totalShards: ${totalShards}`);
387
+ } else if (process.env.MATRIX_COUNT !== undefined) {
341
388
  totalShards = parseInt(process.env.MATRIX_COUNT, 10);
342
389
  this.log(`🔍 [Shard Detection] Using MATRIX_COUNT env var: ${totalShards}`);
343
390
  } else if (githubApiShardInfo && githubApiShardInfo.totalShards > 1) {
@@ -373,7 +420,8 @@ class SlackReporter {
373
420
 
374
421
  // CRITICAL: In CI (especially GitHub Actions), if we can't detect shard info, block posting
375
422
  // This prevents duplicate messages when running with multiple shards
376
- if (process.env.CI && currentShardIndex === undefined) {
423
+ // BUT: Don't block if we're running locally (even if CI env vars are set)
424
+ if (isActuallyInGitHubActions && currentShardIndex === undefined) {
377
425
  if (process.env.GITHUB_ACTIONS === 'true') {
378
426
  this.log(`❌ [Shard Detection] BLOCKING: GitHub Actions detected but shard index cannot be determined.`);
379
427
  this.log(`❌ Attempted: GitHub API detection ${githubApiShardInfo ? 'succeeded' : 'failed'}, env vars not set`);
@@ -404,11 +452,17 @@ class SlackReporter {
404
452
  // This ensures ResultsParser always has correct values, even if we block posting
405
453
  this.resultsParser.updateShardInfo(shardIndexNum, totalShards);
406
454
 
455
+ // For local runs with CI env vars set but not actually in CI, allow posting if single shard
456
+ // or if shard index is 0
457
+ if (!isActuallyInGitHubActions && process.env.CI && totalShards > 1 && currentShardIndex === undefined) {
458
+ this.log(`⚠️ [Shard Detection] Local run with CI env vars but shard info unclear - allowing post (may cause duplicates)`);
459
+ }
460
+
407
461
  // CRITICAL: For GitHub Actions with multiple shards, only shard 0 should post
408
462
  // If we're in CI with multiple shards and don't know which shard we are, block all posts
409
463
  // This prevents duplicate messages when MATRIX_SHARD/MATRIX_INDEX is not set
410
- if (process.env.CI && totalShards > 1 && currentShardIndex === undefined) {
411
- this.log(`❌ [Shard Detection] BLOCKING: CI environment detected with ${totalShards} shards but shard index not set (MATRIX_SHARD/MATRIX_INDEX missing).`);
464
+ if (isActuallyInGitHubActions && totalShards > 1 && currentShardIndex === undefined) {
465
+ this.log(`❌ [Shard Detection] BLOCKING: GitHub Actions detected with ${totalShards} shards but shard index not set (MATRIX_SHARD/MATRIX_INDEX missing).`);
412
466
  this.log(`❌ Skipping Slack report to prevent duplicate messages from all shards.`);
413
467
  this.log(`💡 Fix: Add these env vars to your workflow:`);
414
468
  this.log(`💡 env:`);
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.14",
35
+ "version": "3.0.16",
36
36
  "main": "index.js",
37
37
  "types": "dist/index.d.ts",
38
38
  "author": "Burak B. <burak.boluk@hotmail.com>",