@checkly/playwright-reporter 0.1.9 → 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.
Files changed (4) hide show
  1. package/README.md +266 -0
  2. package/dist/index.d.ts +340 -175
  3. package/dist/index.js +1856 -641
  4. package/package.json +16 -14
package/dist/index.d.ts CHANGED
@@ -1,219 +1,384 @@
1
- export { Asset, AssetCollector, ZipEntry, ZipResult, Zipper, ZipperOptions } from '@checkly/reporter-utils';
2
- import { FullConfig, Suite, JSONReport as JSONReport$1, JSONReportSuite as JSONReportSuite$1, JSONReportSpec as JSONReportSpec$1, JSONReportTest as JSONReportTest$1, JSONReportTestResult as JSONReportTestResult$1, Reporter, TestCase, TestResult, TestError } from '@playwright/test/reporter';
1
+ import { Reporter, FullConfig, Suite as Suite$1, TestCase, TestResult as TestResult$1, TestStep as TestStep$1, TestError as TestError$1, FullResult } from '@playwright/test/reporter';
3
2
 
4
3
  /**
5
- * Checkly environment for API endpoints
4
+ * Output Contract Schema
5
+ *
6
+ * This defines the JSON structure that our reporter MUST produce.
7
+ * It is designed to be compatible with Playwright 1.40 through 1.57+.
8
+ *
9
+ * Fields are categorized as:
10
+ * - REQUIRED: Must always be present (exist in all versions 1.40+)
11
+ * - OPTIONAL: May be present (added in newer versions, older consumers ignore them)
6
12
  */
7
- type ChecklyEnvironment = 'local' | 'development' | 'staging' | 'production';
8
13
  /**
9
- * Context passed to sessionName callback function
14
+ * Individual test run status
10
15
  */
11
- interface SessionNameContext {
12
- /**
13
- * The directory name where tests are running
14
- */
15
- directoryName: string;
16
- /**
17
- * Playwright's full configuration object
18
- */
19
- config: FullConfig;
20
- /**
21
- * The root test suite containing all tests
22
- */
23
- suite: Suite;
16
+ type TestStatus = 'passed' | 'failed' | 'skipped' | 'timedOut' | 'interrupted';
17
+ /**
18
+ * Overall test outcome (aggregated across retries)
19
+ */
20
+ type TestOutcome = 'expected' | 'unexpected' | 'skipped' | 'flaky';
21
+ interface Location {
22
+ file: string;
23
+ line: number;
24
+ column: number;
25
+ }
26
+ interface TestError {
27
+ message?: string;
28
+ stack?: string;
29
+ location?: Location;
30
+ snippet?: string;
31
+ value?: string;
32
+ matcherResult?: unknown;
33
+ }
34
+ interface Attachment {
35
+ name: string;
36
+ contentType: string;
37
+ path?: string;
38
+ body?: string;
39
+ }
40
+ interface TestStep {
41
+ title: string;
42
+ duration: number;
43
+ error?: TestError;
44
+ steps?: TestStep[];
45
+ }
46
+ interface Annotation {
47
+ type: string;
48
+ description?: string;
49
+ location?: {
50
+ file: string;
51
+ line: number;
52
+ column: number;
53
+ };
54
+ }
55
+ interface TestResult {
56
+ workerIndex: number;
57
+ parallelIndex: number;
58
+ status: TestStatus;
59
+ duration: number;
60
+ startTime: string;
61
+ retry: number;
62
+ errors: TestError[];
63
+ error?: TestError;
64
+ errorLocation?: Location;
65
+ stdout: Array<{
66
+ text: string;
67
+ } | {
68
+ buffer: string;
69
+ }>;
70
+ stderr: Array<{
71
+ text: string;
72
+ } | {
73
+ buffer: string;
74
+ }>;
75
+ attachments: Attachment[];
76
+ steps?: TestStep[];
77
+ annotations: Annotation[];
78
+ }
79
+ interface Test {
80
+ projectId: string;
81
+ projectName: string;
82
+ timeout: number;
83
+ expectedStatus: TestStatus;
84
+ annotations: Annotation[];
85
+ results: TestResult[];
86
+ status: TestOutcome;
87
+ }
88
+ interface Spec {
89
+ id: string;
90
+ title: string;
91
+ file: string;
92
+ line: number;
93
+ column: number;
94
+ tags: string[];
95
+ ok: boolean;
96
+ tests: Test[];
97
+ }
98
+ interface Suite {
99
+ title: string;
100
+ file: string;
101
+ line: number;
102
+ column: number;
103
+ specs: Spec[];
104
+ suites?: Suite[];
105
+ }
106
+ interface ProjectConfig {
107
+ id: string;
108
+ name: string;
109
+ testDir: string;
110
+ outputDir: string;
111
+ timeout: number;
112
+ retries: number;
113
+ repeatEach: number;
114
+ metadata: Record<string, unknown>;
115
+ testMatch: string[];
116
+ testIgnore: string[];
117
+ }
118
+ interface ReportConfig {
119
+ rootDir: string;
120
+ configFile?: string;
121
+ version: string;
122
+ workers: number;
123
+ fullyParallel: boolean;
124
+ forbidOnly: boolean;
125
+ globalTimeout: number;
126
+ maxFailures: number;
127
+ projects: ProjectConfig[];
128
+ shard?: {
129
+ current: number;
130
+ total: number;
131
+ } | null;
132
+ metadata: Record<string, unknown>;
133
+ tags?: string[];
134
+ updateSourceMethod?: string;
135
+ preserveOutput?: string;
136
+ quiet?: boolean;
137
+ reportSlowTests?: {
138
+ max: number;
139
+ threshold: number;
140
+ } | null;
141
+ webServer?: unknown;
142
+ globalSetup?: string | null;
143
+ globalTeardown?: string | null;
144
+ grep?: unknown;
145
+ grepInvert?: unknown;
146
+ reporter?: unknown;
147
+ updateSnapshots?: string;
148
+ }
149
+ interface Stats {
150
+ startTime: string;
151
+ duration: number;
152
+ expected: number;
153
+ unexpected: number;
154
+ flaky: number;
155
+ skipped: number;
156
+ }
157
+ interface JSONReport {
158
+ config: ReportConfig;
159
+ suites: Suite[];
160
+ errors: TestError[];
161
+ stats: Stats;
24
162
  }
25
163
  /**
26
- * Session name can be a static string or a function that returns a string
164
+ * Type guard to check if an object is a valid JSONReport
27
165
  */
28
- type SessionNameOption = string | ((context: SessionNameContext) => string);
166
+ declare function isValidJSONReport(obj: unknown): obj is JSONReport;
167
+ /**
168
+ * Type guard to check if stats are valid
169
+ */
170
+ declare function isValidStats(obj: unknown): obj is Stats;
29
171
  /**
30
- * Configuration options for ChecklyReporter
172
+ * Type guard to check if a test result is valid
31
173
  */
32
- interface ChecklyReporterOptions {
174
+ declare function isValidTestResult(obj: unknown): obj is TestResult;
175
+
176
+ interface BaseReporterOptions {
33
177
  /**
34
- * Checkly account ID for uploading test results
35
- * Required for Phase 2 (upload functionality)
178
+ * Directory for output files. JSON report is written to `{outputDir}/checkly-report.json`.
36
179
  */
37
- accountId?: string;
180
+ outputDir?: string;
38
181
  /**
39
- * Checkly API key for authentication
40
- * Required for Phase 2 (upload functionality)
182
+ * @deprecated Use `outputDir` instead. Will be removed in next major version.
41
183
  */
42
- apiKey?: string;
184
+ outputFile?: string;
185
+ verbose?: boolean;
186
+ }
187
+ type LogFn = (message: string, data?: Record<string, unknown>) => void;
188
+ interface ExtensionContext$1 {
189
+ log: LogFn;
190
+ }
191
+ interface Extension$1 {
192
+ name: string;
193
+ onBegin?(ctx: ExtensionContext$1 & {
194
+ config: FullConfig;
195
+ suite: Suite$1;
196
+ }): void | Promise<void>;
197
+ onTestBegin?(ctx: ExtensionContext$1 & {
198
+ test: TestCase;
199
+ result: TestResult$1;
200
+ }): void | Promise<void>;
201
+ onStepBegin?(ctx: ExtensionContext$1 & {
202
+ test: TestCase;
203
+ result: TestResult$1;
204
+ step: TestStep$1;
205
+ }): void | Promise<void>;
206
+ onStepEnd?(ctx: ExtensionContext$1 & {
207
+ test: TestCase;
208
+ result: TestResult$1;
209
+ step: TestStep$1;
210
+ }): void | Promise<void>;
211
+ onTestEnd?(ctx: ExtensionContext$1 & {
212
+ test: TestCase;
213
+ result: TestResult$1;
214
+ }): void | Promise<void>;
215
+ onStdOut?(ctx: ExtensionContext$1 & {
216
+ chunk: string | Buffer;
217
+ test?: TestCase;
218
+ result?: TestResult$1;
219
+ }): void | Promise<void>;
220
+ onStdErr?(ctx: ExtensionContext$1 & {
221
+ chunk: string | Buffer;
222
+ test?: TestCase;
223
+ result?: TestResult$1;
224
+ }): void | Promise<void>;
225
+ onError?(ctx: ExtensionContext$1 & {
226
+ error: TestError$1;
227
+ }): void | Promise<void>;
228
+ onEnd?(ctx: ExtensionContext$1 & {
229
+ result: FullResult;
230
+ report: JSONReport;
231
+ addSummaryLine: (line: string) => void;
232
+ }): void | Promise<void>;
233
+ onExit?(ctx: ExtensionContext$1): void | Promise<void>;
234
+ }
235
+ declare class BaseReporter implements Reporter {
236
+ private config;
237
+ private suite;
238
+ private startTime;
239
+ private options;
240
+ private verbose;
241
+ private globalErrors;
242
+ private tests;
243
+ private expectedCount;
244
+ private unexpectedCount;
245
+ private flakyCount;
246
+ private skippedCount;
247
+ private _report;
248
+ private extensions;
249
+ private summaryLines;
250
+ constructor(options?: BaseReporterOptions);
251
+ protected use(extension: Extension$1): this;
252
+ private log;
253
+ private createExtensionLogger;
254
+ onBegin(config: FullConfig, suite: Suite$1): void;
255
+ onTestBegin(test: TestCase, result: TestResult$1): void;
256
+ onStepBegin(test: TestCase, result: TestResult$1, step: TestStep$1): void;
257
+ onStepEnd(test: TestCase, result: TestResult$1, step: TestStep$1): void;
258
+ onTestEnd(test: TestCase, result: TestResult$1): void;
259
+ onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult$1): void;
260
+ onStdErr(chunk: string | Buffer, test?: TestCase, result?: TestResult$1): void;
261
+ onError(error: TestError$1): void;
262
+ onEnd(result: FullResult): Promise<void>;
263
+ onExit(): Promise<void>;
264
+ printsToStdio(): boolean;
265
+ getReport(): JSONReport;
266
+ private buildReport;
267
+ private serializeConfig;
268
+ private serializeProject;
43
269
  /**
44
- * Checkly environment to use
45
- * Can also be set via CHECKLY_ENV environment variable
46
- * @default 'production'
270
+ * Serialize suites following the same order as native Playwright JSON reporter.
271
+ * Iterates through suite tree structure (discovery order) rather than test completion order.
47
272
  */
48
- environment?: ChecklyEnvironment;
273
+ private serializeSuites;
49
274
  /**
50
- * Output path for the generated ZIP file (for testing/debugging)
51
- * @default 'checkly-report.zip'
52
- * @internal
275
+ * Recursively serialize a suite and its children.
276
+ * Returns null if the suite has no tests.
53
277
  */
54
- outputPath?: string;
278
+ private serializeSuite;
55
279
  /**
56
- * Path to the JSON report file generated by Playwright's json reporter
57
- * @default 'test-results/playwright-test-report.json'
58
- * @internal
280
+ * Merge tests from 'from' suite into 'to' suite (for multi-project scenarios).
281
+ * Matches native Playwright JSON reporter behavior - specs are NOT merged,
282
+ * each project gets its own spec even for the same test.
59
283
  */
60
- jsonReportPath?: string;
284
+ private mergeSuites;
285
+ private serializeSpec;
61
286
  /**
62
- * Directory containing test results and assets
63
- * @default 'test-results'
64
- * @internal
65
- */
66
- testResultsDir?: string;
67
- /**
68
- * Dry run mode - skips API calls and only creates local ZIP file
69
- * @default false
287
+ * Extract tags from test case - uses testCase.tags (1.42+) or extracts @tags from title
288
+ * Tags are returned without @ prefix to match native Playwright JSON reporter
70
289
  */
290
+ private extractTags;
291
+ private serializeTest;
292
+ private serializeTestResult;
293
+ private serializeStep;
294
+ private serializeError;
295
+ private serializeAnnotations;
296
+ private countTests;
297
+ private getFileName;
298
+ private mapOutcome;
299
+ private printSummary;
300
+ }
301
+
302
+ type ChecklyEnvironment = 'local' | 'development' | 'staging' | 'production';
303
+ interface SessionNameContext {
304
+ directoryName: string;
305
+ config: FullConfig;
306
+ suite: Suite$1;
307
+ }
308
+ type SessionNameOption = string | ((context: SessionNameContext) => string);
309
+ interface ChecklyUploadOptions {
310
+ apiKey?: string;
311
+ accountId?: string;
312
+ environment?: ChecklyEnvironment;
313
+ sessionName?: SessionNameOption;
71
314
  dryRun?: boolean;
72
315
  /**
73
- * Custom name for the test session
74
- * Can be a string or a callback function for dynamic names
75
- * @default 'Playwright Test Session: {directoryName}'
76
- * @example
77
- * // Static string
78
- * sessionName: 'My E2E Tests'
79
- *
80
- * // Dynamic with callback
81
- * sessionName: ({ directoryName, config }) => `E2E: ${directoryName} (${config.projects.length} projects)`
316
+ * Directory for assets and ZIP output. Defaults to Playwright's outputDir.
317
+ * - Assets (screenshots, videos, traces) are read from here
318
+ * - ZIP is written to `{outputDir}/checkly-report.zip`
82
319
  */
83
- sessionName?: SessionNameOption;
84
- }
85
- /**
86
- * Warning types that can be attached to test results
87
- */
88
- type ChecklyWarningType = 'trace-off' | 'trace-retained-on-failure' | 'trace-first-retry-only' | 'trace-retries-only' | 'trace-retained-on-first-failure' | 'trace-missing';
89
- /**
90
- * A warning attached to a test result
91
- */
92
- interface ChecklyWarning {
320
+ outputDir?: string;
93
321
  /**
94
- * Type of warning for programmatic handling
322
+ * @deprecated Use `outputDir` instead. Will be removed in next major version.
95
323
  */
96
- type: ChecklyWarningType;
324
+ testResultsDir?: string;
97
325
  /**
98
- * Human-readable warning message
326
+ * @deprecated ZIP is now written to `{outputDir}/checkly-report.zip`. Will be removed in next major version.
99
327
  */
100
- message: string;
328
+ outputPath?: string;
101
329
  }
102
- /**
103
- * Checkly-specific extensions added to JSONReportTestResult
104
- */
105
- interface ChecklyTestResultExtensions {
106
- /**
107
- * Warnings about the test result (e.g., missing traces)
108
- */
109
- warnings?: ChecklyWarning[];
330
+ interface ExtensionContext {
331
+ log: LogFn;
110
332
  }
333
+ interface Extension {
334
+ name: string;
335
+ onBegin?(ctx: ExtensionContext & {
336
+ config: FullConfig;
337
+ suite: Suite$1;
338
+ }): void | Promise<void>;
339
+ onTestEnd?(ctx: ExtensionContext & {
340
+ test: TestCase;
341
+ result: TestResult$1;
342
+ }): void | Promise<void>;
343
+ onEnd?(ctx: ExtensionContext & {
344
+ result: unknown;
345
+ report: JSONReport;
346
+ addSummaryLine: (line: string) => void;
347
+ }): void | Promise<void>;
348
+ }
349
+ declare function checklyUpload(options?: ChecklyUploadOptions): Extension;
350
+
111
351
  /**
112
- * Extended JSONReportTestResult with Checkly-specific data
113
- */
114
- type JSONReportTestResult = JSONReportTestResult$1 & {
115
- _checkly?: ChecklyTestResultExtensions;
116
- };
117
- /**
118
- * Extended JSONReportTest with Checkly-extended results
119
- */
120
- type JSONReportTest = Omit<JSONReportTest$1, 'results'> & {
121
- results: JSONReportTestResult[];
122
- };
123
- /**
124
- * Extended JSONReportSpec with Checkly-extended tests
125
- */
126
- type JSONReportSpec = Omit<JSONReportSpec$1, 'tests'> & {
127
- tests: JSONReportTest[];
128
- };
129
- /**
130
- * Extended JSONReportSuite with Checkly-extended specs and nested suites
352
+ * @checkly/playwright-reporter-next
353
+ *
354
+ * Standalone Playwright reporter for Checkly
355
+ * Compatible with Playwright 1.40 through 1.57+
131
356
  */
132
- type JSONReportSuite = Omit<JSONReportSuite$1, 'suites' | 'specs'> & {
133
- suites?: JSONReportSuite[];
134
- specs: JSONReportSpec[];
135
- };
357
+
358
+ interface ChecklyReporterOptions extends BaseReporterOptions, ChecklyUploadOptions {
359
+ }
136
360
  /**
137
- * Extended JSONReport with Checkly-extended suites
361
+ * Full-featured reporter with all Checkly functionality.
362
+ * This is what Playwright loads when using the package.
138
363
  */
139
- type JSONReport = Omit<JSONReport$1, 'suites'> & {
140
- suites: JSONReportSuite[];
141
- };
364
+ declare class ChecklyReporter extends BaseReporter {
365
+ constructor(options?: ChecklyReporterOptions);
366
+ }
142
367
 
143
368
  /**
144
- * Checkly Playwright Reporter
369
+ * Create a Checkly reporter configuration with full intellisense support.
145
370
  *
146
- * Creates a ZIP archive containing the JSON report and all test assets.
147
- * Designed to work alongside Playwright's built-in JSONReporter.
371
+ * Use this instead of the array-based syntax for better IDE experience.
148
372
  *
149
373
  * @example
150
- * // playwright.config.ts
374
+ * import { createChecklyReporter } from '@checkly/playwright-reporter'
375
+ *
151
376
  * export default defineConfig({
152
377
  * reporter: [
153
- * ['json', { outputFile: 'test-results/playwright-test-report.json' }],
154
- * ['@checkly/playwright-reporter', {
155
- * apiKey: process.env.CHECKLY_API_KEY,
156
- * accountId: process.env.CHECKLY_ACCOUNT_ID,
157
- * }]
158
- * ]
159
- * });
378
+ * createChecklyReporter({ outputDir: 'test-results' }),
379
+ * ],
380
+ * })
160
381
  */
161
- declare class ChecklyReporter implements Reporter {
162
- private options;
163
- private assetCollector;
164
- private zipper;
165
- private testResults?;
166
- private testSession?;
167
- private startTime?;
168
- private testCounts;
169
- private stepsMap;
170
- private warningsMap;
171
- constructor(options?: ChecklyReporterOptions);
172
- /**
173
- * Resolves the session name from options
174
- * Supports string, callback function, or falls back to default
175
- */
176
- private resolveSessionName;
177
- /**
178
- * Checks if test result has a trace attachment and adds context-aware warning if missing
179
- * The warning type depends on the trace configuration and test result state
180
- */
181
- private checkTraceAttachment;
182
- /**
183
- * Called once before running tests
184
- * Creates test session in Checkly if credentials provided
185
- */
186
- onBegin(config: FullConfig, suite: Suite): void;
187
- /**
188
- * Called for each test when it completes
189
- * Captures steps and warnings, tracks test results for final status calculation
190
- */
191
- onTestEnd(test: TestCase, result: TestResult): void;
192
- /**
193
- * Called after all tests have completed
194
- * This is where we create the ZIP archive and upload results
195
- */
196
- onEnd(): Promise<void>;
197
- private printSummary;
198
- /**
199
- * Injects captured steps and warnings into the JSON report
200
- * Traverses the report structure and matches by test ID + retry
201
- */
202
- private injectDataIntoReport;
203
- /**
204
- * Reconstructs config.projects and test.projectId from test data
205
- * This is necessary for blob merge scenarios where Playwright's JSON reporter
206
- * doesn't populate projects array or projectId fields
207
- */
208
- private reconstructProjectsFromTests;
209
- /**
210
- * Uploads test results to Checkly API
211
- */
212
- private uploadResults;
213
- /**
214
- * Called when a global error occurs
215
- */
216
- onError(error: TestError): void;
217
- }
382
+ declare function createChecklyReporter(options?: ChecklyReporterOptions): ['@checkly/playwright-reporter', ChecklyReporterOptions];
218
383
 
219
- export { ChecklyReporter, type ChecklyReporterOptions, type ChecklyTestResultExtensions, type ChecklyWarning, type ChecklyWarningType, type JSONReport, type JSONReportSpec, type JSONReportSuite, type JSONReportTest, type JSONReportTestResult, ChecklyReporter as default };
384
+ export { type Annotation, type Attachment, BaseReporter, type BaseReporterOptions, ChecklyReporter, type ChecklyReporterOptions, type ChecklyUploadOptions, type JSONReport, type Location, type LogFn, type ProjectConfig, type ReportConfig, type Spec, type Stats, type Suite, type Test, type TestError, type TestOutcome, type TestResult, type TestStatus, type TestStep, checklyUpload, createChecklyReporter, ChecklyReporter as default, isValidJSONReport, isValidStats, isValidTestResult };