fair-playwright 1.0.0

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.
@@ -0,0 +1,429 @@
1
+ import { Reporter, FullConfig, Suite, TestCase, TestResult, TestStep, FullResult, TestError } from '@playwright/test/reporter';
2
+ export { FullConfig, FullResult, Reporter, Suite, TestCase, TestResult, TestStep } from '@playwright/test/reporter';
3
+
4
+ /**
5
+ * Type definitions for fair-playwright reporter
6
+ */
7
+
8
+ /**
9
+ * Step level in the hierarchy
10
+ */
11
+ type StepLevel = 'major' | 'minor';
12
+ /**
13
+ * Step status
14
+ */
15
+ type StepStatus = 'pending' | 'running' | 'passed' | 'failed' | 'skipped';
16
+ /**
17
+ * Output mode for the reporter
18
+ */
19
+ type OutputMode = 'progressive' | 'full' | 'minimal';
20
+ /**
21
+ * Configuration for the Fair Playwright reporter
22
+ */
23
+ interface FairReporterConfig {
24
+ /**
25
+ * Output mode: progressive (live updates), full (all details), minimal (summary only)
26
+ * @default 'progressive'
27
+ */
28
+ mode?: OutputMode;
29
+ /**
30
+ * Enable AI-optimized markdown output
31
+ * @default true
32
+ */
33
+ aiOptimized?: boolean;
34
+ /**
35
+ * Output file configurations
36
+ */
37
+ output?: {
38
+ /**
39
+ * Enable console output
40
+ * @default true
41
+ */
42
+ console?: boolean;
43
+ /**
44
+ * AI-optimized markdown output file path, or true for default location
45
+ * @default false
46
+ */
47
+ ai?: boolean | string;
48
+ /**
49
+ * JSON output file path, or true for default location
50
+ * @default false
51
+ */
52
+ json?: boolean | string;
53
+ };
54
+ /**
55
+ * Step classification settings
56
+ */
57
+ stepClassification?: {
58
+ /**
59
+ * Duration threshold in ms - steps longer than this are considered MAJOR
60
+ * @default 1000
61
+ */
62
+ durationThreshold?: number;
63
+ /**
64
+ * Auto-detect step level based on context and duration
65
+ * @default true
66
+ */
67
+ autoDetect?: boolean;
68
+ };
69
+ /**
70
+ * Progressive mode settings
71
+ */
72
+ progressive?: {
73
+ /**
74
+ * Clear completed tests from terminal
75
+ * @default true
76
+ */
77
+ clearCompleted?: boolean;
78
+ /**
79
+ * Update interval in milliseconds
80
+ * @default 100
81
+ */
82
+ updateInterval?: number;
83
+ };
84
+ /**
85
+ * Compression settings for output
86
+ */
87
+ compression?: {
88
+ /**
89
+ * How to display passed tests: summary, hide, or full
90
+ * @default 'summary'
91
+ */
92
+ passedTests?: 'summary' | 'hide' | 'full';
93
+ /**
94
+ * Failure context settings
95
+ */
96
+ failureContext?: {
97
+ /**
98
+ * Number of steps to show before failure
99
+ * @default 3
100
+ */
101
+ steps?: number;
102
+ /**
103
+ * Include screenshot in failure context
104
+ * @default true
105
+ */
106
+ screenshot?: boolean;
107
+ /**
108
+ * Include trace in failure context
109
+ * @default true
110
+ */
111
+ trace?: boolean;
112
+ /**
113
+ * Include console logs in failure context
114
+ * @default true
115
+ */
116
+ logs?: boolean;
117
+ };
118
+ };
119
+ }
120
+ /**
121
+ * Step metadata for tracking
122
+ */
123
+ interface StepMetadata {
124
+ /**
125
+ * Unique identifier for the step
126
+ */
127
+ id: string;
128
+ /**
129
+ * Step title/description
130
+ */
131
+ title: string;
132
+ /**
133
+ * Step level (major or minor)
134
+ */
135
+ level: StepLevel;
136
+ /**
137
+ * Current status
138
+ */
139
+ status: StepStatus;
140
+ /**
141
+ * Start timestamp
142
+ */
143
+ startTime: number;
144
+ /**
145
+ * End timestamp (undefined if not finished)
146
+ */
147
+ endTime?: number;
148
+ /**
149
+ * Duration in milliseconds
150
+ */
151
+ duration?: number;
152
+ /**
153
+ * Success message
154
+ */
155
+ successMessage?: string;
156
+ /**
157
+ * Failure message
158
+ */
159
+ failureMessage?: string;
160
+ /**
161
+ * Error details if failed
162
+ */
163
+ error?: {
164
+ message: string;
165
+ stack?: string;
166
+ location?: string;
167
+ };
168
+ /**
169
+ * Parent step ID (for nested steps)
170
+ */
171
+ parentId?: string;
172
+ /**
173
+ * Child step IDs
174
+ */
175
+ childIds: string[];
176
+ }
177
+ /**
178
+ * Test metadata for tracking
179
+ */
180
+ interface TestMetadata {
181
+ /**
182
+ * Unique identifier
183
+ */
184
+ id: string;
185
+ /**
186
+ * Test title
187
+ */
188
+ title: string;
189
+ /**
190
+ * Test file path
191
+ */
192
+ file: string;
193
+ /**
194
+ * Test status
195
+ */
196
+ status: StepStatus;
197
+ /**
198
+ * Start timestamp
199
+ */
200
+ startTime: number;
201
+ /**
202
+ * End timestamp
203
+ */
204
+ endTime?: number;
205
+ /**
206
+ * Duration in milliseconds
207
+ */
208
+ duration?: number;
209
+ /**
210
+ * Steps in this test
211
+ */
212
+ steps: StepMetadata[];
213
+ /**
214
+ * Error details if failed
215
+ */
216
+ error?: {
217
+ message: string;
218
+ stack?: string;
219
+ location?: string;
220
+ };
221
+ /**
222
+ * Attachments (screenshots, traces, etc.)
223
+ */
224
+ attachments: Array<{
225
+ name: string;
226
+ path?: string;
227
+ contentType: string;
228
+ }>;
229
+ /**
230
+ * Browser console errors captured during test execution
231
+ */
232
+ consoleErrors?: Array<{
233
+ type: string;
234
+ message: string;
235
+ location?: string;
236
+ timestamp: number;
237
+ }>;
238
+ }
239
+ /**
240
+ * Options for e2e step execution (inline mode)
241
+ */
242
+ interface StepOptions {
243
+ /**
244
+ * Success message to display
245
+ */
246
+ success?: string;
247
+ /**
248
+ * Failure message to display
249
+ */
250
+ failure?: string;
251
+ }
252
+ /**
253
+ * Step definition for declarative mode
254
+ */
255
+ interface StepDefinition {
256
+ /**
257
+ * Step title
258
+ */
259
+ title: string;
260
+ /**
261
+ * Success message
262
+ */
263
+ success?: string;
264
+ /**
265
+ * Failure message
266
+ */
267
+ failure?: string;
268
+ /**
269
+ * Action to execute
270
+ */
271
+ action: () => Promise<void>;
272
+ }
273
+ /**
274
+ * Options for major step execution (declarative mode)
275
+ */
276
+ interface MajorStepOptions {
277
+ /**
278
+ * Success message for the major step
279
+ */
280
+ success?: string;
281
+ /**
282
+ * Failure message for the major step
283
+ */
284
+ failure?: string;
285
+ /**
286
+ * Child steps to execute
287
+ */
288
+ steps?: StepDefinition[];
289
+ }
290
+ /**
291
+ * E2E test helper interface
292
+ */
293
+ interface E2EHelper {
294
+ /**
295
+ * Execute a major step (inline mode)
296
+ */
297
+ major(title: string, action: () => Promise<void>, options?: StepOptions): Promise<void>;
298
+ /**
299
+ * Execute a major step with child steps (declarative mode)
300
+ */
301
+ major(title: string, options: MajorStepOptions): Promise<void>;
302
+ /**
303
+ * Execute a minor step
304
+ */
305
+ minor(title: string, action: () => Promise<void>, options?: StepOptions): Promise<void>;
306
+ }
307
+
308
+ /**
309
+ * Fair Playwright Reporter
310
+ * AI-optimized reporter with progressive terminal output and hierarchical step management
311
+ */
312
+ declare class FairReporter implements Reporter {
313
+ private config;
314
+ private stepTracker;
315
+ private consoleFormatter?;
316
+ private aiFormatter?;
317
+ private jsonFormatter?;
318
+ private stepIdMap;
319
+ constructor(config?: FairReporterConfig);
320
+ /**
321
+ * Called once before running tests
322
+ */
323
+ onBegin(_config: FullConfig, suite: Suite): void;
324
+ /**
325
+ * Called when a test begins
326
+ */
327
+ onTestBegin(test: TestCase, result: TestResult): void;
328
+ /**
329
+ * Called when a test step begins
330
+ */
331
+ onStepBegin(test: TestCase, result: TestResult, step: TestStep): void;
332
+ /**
333
+ * Called when a test step ends
334
+ */
335
+ onStepEnd(test: TestCase, result: TestResult, step: TestStep): void;
336
+ /**
337
+ * Called when a test ends
338
+ */
339
+ onTestEnd(test: TestCase, result: TestResult): void;
340
+ /**
341
+ * Called once after all tests have finished
342
+ */
343
+ onEnd(result: FullResult): Promise<void>;
344
+ /**
345
+ * Optional: Called on error
346
+ */
347
+ onError(error: TestError): void;
348
+ }
349
+
350
+ /**
351
+ * Global e2e helper instance
352
+ * Usage:
353
+ * import { e2e } from 'fair-playwright'
354
+ * await e2e.major('User login', ...)
355
+ */
356
+ declare const e2e: E2EHelper;
357
+
358
+ /**
359
+ * MCP (Model Context Protocol) Server for AI integration
360
+ * Provides test results and progress to AI coding assistants
361
+ *
362
+ * Full MCP protocol implementation using @modelcontextprotocol/sdk
363
+ */
364
+ interface MCPServerConfig {
365
+ /**
366
+ * Path to test results JSON file
367
+ * Default: './test-results/results.json'
368
+ */
369
+ resultsPath?: string;
370
+ /**
371
+ * Server name
372
+ */
373
+ name?: string;
374
+ /**
375
+ * Server version
376
+ */
377
+ version?: string;
378
+ /**
379
+ * Enable verbose logging
380
+ */
381
+ verbose?: boolean;
382
+ }
383
+ /**
384
+ * MCP Server for exposing test results to AI assistants
385
+ */
386
+ declare class MCPServer {
387
+ private server;
388
+ private config;
389
+ private testResults;
390
+ constructor(config?: MCPServerConfig);
391
+ /**
392
+ * Setup MCP protocol handlers
393
+ */
394
+ private setupHandlers;
395
+ /**
396
+ * Load test results from JSON file
397
+ */
398
+ private loadTestResults;
399
+ /**
400
+ * Start the MCP server with stdio transport
401
+ */
402
+ start(): Promise<void>;
403
+ /**
404
+ * Get current test results
405
+ */
406
+ private getTestResults;
407
+ /**
408
+ * Get test summary in markdown format
409
+ */
410
+ private getTestSummary;
411
+ /**
412
+ * Get AI-optimized summary of failures
413
+ */
414
+ private getFailureSummary;
415
+ /**
416
+ * Query specific test by title
417
+ */
418
+ private queryTest;
419
+ /**
420
+ * Get tests by status
421
+ */
422
+ private getTestsByStatus;
423
+ }
424
+ /**
425
+ * Create and start MCP server
426
+ */
427
+ declare function createMCPServer(config?: MCPServerConfig): Promise<MCPServer>;
428
+
429
+ export { type E2EHelper, FairReporter, type FairReporterConfig, MCPServer, type MCPServerConfig, type MajorStepOptions, type OutputMode, type StepDefinition, type StepLevel, type StepMetadata, type StepOptions, type StepStatus, type TestMetadata, createMCPServer, FairReporter as default, e2e };