playwright-ai-reporter 0.0.4 → 0.0.6

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.
@@ -1,4 +1,4 @@
1
- import { Reporter, TestCase, TestResult, FullConfig, Suite } from '@playwright/test/reporter';
1
+ import { Reporter, TestCase, TestResult, FullConfig, Suite, TestStep, FullResult } from '@playwright/test/reporter';
2
2
  import { ReporterConfig } from './types';
3
3
  /**
4
4
  * PlaywrightTestReporter is a modern, maintainable reporter for Playwright tests.
@@ -62,12 +62,34 @@ export default class PlaywrightTestReporter implements Reporter {
62
62
  * @param result - The result of the test execution
63
63
  */
64
64
  onTestEnd(test: TestCase, result: TestResult): void;
65
+ /**
66
+ * Called when a test begins.
67
+ *
68
+ * @param test - The test case that is starting
69
+ */
70
+ onTestBegin(test: TestCase, result: TestResult): Promise<void>;
71
+ /**
72
+ * Called when a test step begins.
73
+ *
74
+ * @param test - The test case
75
+ * @param result - The current test result
76
+ * @param step - The test step that is starting
77
+ */
78
+ onStepBegin(test: TestCase, result: TestResult, step: TestStep): Promise<void>;
79
+ /**
80
+ * Called when a test step ends.
81
+ *
82
+ * @param test - The test case
83
+ * @param result - The current test result
84
+ * @param step - The test step that ended
85
+ */
86
+ onStepEnd(test: TestCase, result: TestResult, step: TestStep): Promise<void>;
65
87
  /**
66
88
  * Called when all tests have completed.
67
89
  * Processes results, displays summary statistics, and sets appropriate exit code.
68
90
  * Now properly handles all error conditions including non-test errors.
69
91
  */
70
- onEnd(): Promise<void>;
92
+ onEnd(result: FullResult): Promise<void>;
71
93
  /**
72
94
  * Exits the process with a success code.
73
95
  * Extracted to a method to make the flow clearer and more maintainable.
@@ -80,6 +102,14 @@ export default class PlaywrightTestReporter implements Reporter {
80
102
  * @private
81
103
  */
82
104
  private _exitWithError;
105
+ /**
106
+ * Helper method to log messages with appropriate coloring.
107
+ *
108
+ * @param level - The log level ('debug' or 'error')
109
+ * @param message - The message to log
110
+ * @private
111
+ */
112
+ private _log;
83
113
  /**
84
114
  * Formats and logs the outcome of a single test with appropriate coloring.
85
115
  * Handles different test states (passed, failed, skipped) and retry attempts.
package/dist/reporter.js CHANGED
@@ -171,6 +171,7 @@ class PlaywrightTestReporter {
171
171
  onTestEnd(test, result) {
172
172
  const title = test.title;
173
173
  const timeTakenSec = result.duration / 1000;
174
+ console.log(`${colors_1.colors.fgCyan}Finished test: ${colors_1.colors.fgMagentaBright}${test.title}${colors_1.colors.fgCyan}: ${result.status}${colors_1.colors.reset}`);
174
175
  // Initialize test record if first attempt
175
176
  if (!this._testRecords.has(title)) {
176
177
  // Create an enhanced test case with required properties
@@ -227,12 +228,57 @@ class PlaywrightTestReporter {
227
228
  // Log test outcome with appropriate formatting
228
229
  this._logTestOutcome(test.title, result, timeTakenSec);
229
230
  }
231
+ /**
232
+ * Called when a test begins.
233
+ *
234
+ * @param test - The test case that is starting
235
+ */
236
+ async onTestBegin(test, result) {
237
+ if (result.retry > 0) {
238
+ console.log(`${colors_1.colors.fgYellow}🔄 Retrying test (attempt #${result.retry + 1}): ${colors_1.colors.fgMagentaBright}${test.title}${colors_1.colors.reset}`);
239
+ }
240
+ else {
241
+ console.log(`${colors_1.colors.fgCyan}Starting test: ${colors_1.colors.fgMagentaBright}${test.title}${colors_1.colors.reset}`);
242
+ }
243
+ }
244
+ /**
245
+ * Called when a test step begins.
246
+ *
247
+ * @param test - The test case
248
+ * @param result - The current test result
249
+ * @param step - The test step that is starting
250
+ */
251
+ async onStepBegin(test, result, step) {
252
+ if (step.category !== 'test.step')
253
+ return;
254
+ this._log('debug', `Test step BEGIN: ${step.title}`);
255
+ }
256
+ /**
257
+ * Called when a test step ends.
258
+ *
259
+ * @param test - The test case
260
+ * @param result - The current test result
261
+ * @param step - The test step that ended
262
+ */
263
+ async onStepEnd(test, result, step) {
264
+ if (step.category !== 'test.step')
265
+ return;
266
+ if (step.error) {
267
+ this._log('error', `Test step FAILED: ${step.title}`);
268
+ }
269
+ else {
270
+ this._log('debug', `Test step END: ${step.title}`);
271
+ }
272
+ }
230
273
  /**
231
274
  * Called when all tests have completed.
232
275
  * Processes results, displays summary statistics, and sets appropriate exit code.
233
276
  * Now properly handles all error conditions including non-test errors.
234
277
  */
235
- async onEnd() {
278
+ async onEnd(result) {
279
+ console.log(`${colors_1.colors.fgCyan}===============================================${colors_1.colors.reset}`);
280
+ console.log(`${colors_1.colors.fgMagentaBright}Finished the test run: ${result.status.toUpperCase()}${colors_1.colors.reset}`);
281
+ console.log(`${colors_1.colors.fgCyan}===============================================${colors_1.colors.reset}`);
236
282
  const endTime = Date.now();
237
283
  const totalTimeSec = (endTime - this._startTime) / 1000;
238
284
  const totalTimeDisplay = utils_1.TestUtils.formatTime(totalTimeSec);
@@ -326,6 +372,21 @@ class PlaywrightTestReporter {
326
372
  _exitWithError() {
327
373
  process.exitCode = 1;
328
374
  }
375
+ /**
376
+ * Helper method to log messages with appropriate coloring.
377
+ *
378
+ * @param level - The log level ('debug' or 'error')
379
+ * @param message - The message to log
380
+ * @private
381
+ */
382
+ _log(level, message) {
383
+ if (level === 'error') {
384
+ console.log(`${colors_1.colors.fgRed}${message}${colors_1.colors.reset}`);
385
+ }
386
+ else {
387
+ console.log(`${colors_1.colors.fgGray}${message}${colors_1.colors.reset}`);
388
+ }
389
+ }
329
390
  /**
330
391
  * Formats and logs the outcome of a single test with appropriate coloring.
331
392
  * Handles different test states (passed, failed, skipped) and retry attempts.
@@ -377,8 +438,14 @@ class PlaywrightTestReporter {
377
438
  failedTests,
378
439
  };
379
440
  try {
441
+ // Ensure output directory exists
442
+ if (!fs.existsSync(this.outputDir)) {
443
+ fs.mkdirSync(this.outputDir, { recursive: true });
444
+ console.log(`Created output directory: ${path.resolve(this.outputDir)}`);
445
+ }
380
446
  const filePath = path.join(this.outputDir, '.last-run.json');
381
447
  fs.writeFileSync(filePath, JSON.stringify(lastRunData, null, 2));
448
+ console.log(`Last run status written to: ${path.resolve(filePath)}`);
382
449
  }
383
450
  catch (error) {
384
451
  console.error('Failed to write last run status:', error);
@@ -51,12 +51,14 @@ class FileHandler {
51
51
  // Ensure the output directory exists
52
52
  if (!fs.existsSync(outputDir)) {
53
53
  fs.mkdirSync(outputDir, { recursive: true });
54
+ console.log(`Created output directory: ${path.resolve(outputDir)}`);
54
55
  }
55
56
  this.failuresFilePath = path.join(outputDir, 'testFailures.json');
56
57
  this.summaryFilePath = path.join(outputDir, 'testSummary.json');
57
58
  // Initialize failures file with empty array if it doesn't exist
58
59
  if (!fs.existsSync(this.failuresFilePath)) {
59
60
  fs.writeFileSync(this.failuresFilePath, JSON.stringify([], null, 2));
61
+ console.log(`Initialized test failures file: ${path.resolve(this.failuresFilePath)}`);
60
62
  }
61
63
  // Setup periodic flushing of the buffer (every 5 seconds)
62
64
  this.startPeriodicFlush();
@@ -82,6 +84,7 @@ class FileHandler {
82
84
  runEnvironment: summary.buildInfo?.isPipeline ? 'Pipeline' : 'Local',
83
85
  };
84
86
  fs.writeFileSync(this.summaryFilePath, JSON.stringify(summaryWithTests, null, 2));
87
+ console.log(`Test summary written to: ${path.resolve(this.summaryFilePath)}`);
85
88
  // Final flush of failures buffer
86
89
  this.flushFailuresBuffer();
87
90
  // Stop the periodic flush
@@ -124,6 +127,7 @@ class FileHandler {
124
127
  const allFailures = [...existingFailures, ...this.failuresBuffer];
125
128
  // Write back to file
126
129
  fs.writeFileSync(this.failuresFilePath, JSON.stringify(allFailures, null, 2));
130
+ console.log(`Test failures written to: ${path.resolve(this.failuresFilePath)} (${allFailures.length} total failures)`);
127
131
  // Clear buffer
128
132
  this.failuresBuffer = [];
129
133
  this.isBufferDirty = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playwright-ai-reporter",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Enterprise-grade AI-powered test reporter for Playwright with automatic bug creation, intelligent fix suggestions, auto-healing PRs, and multi-provider support for CI/CD pipelines.",
5
5
  "keywords": [
6
6
  "playwright",
Binary file
Binary file