@testivai/witness-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.
Files changed (61) hide show
  1. package/__tests__/.gitkeep +0 -0
  2. package/__tests__/config-integration.spec.ts +102 -0
  3. package/__tests__/snapshot.spec.d.ts +1 -0
  4. package/__tests__/snapshot.spec.js +81 -0
  5. package/__tests__/snapshot.spec.ts +58 -0
  6. package/__tests__/unit/ci.spec.d.ts +1 -0
  7. package/__tests__/unit/ci.spec.js +35 -0
  8. package/__tests__/unit/ci.spec.ts +40 -0
  9. package/__tests__/unit/reporter.spec.d.ts +1 -0
  10. package/__tests__/unit/reporter.spec.js +37 -0
  11. package/__tests__/unit/reporter.spec.ts +43 -0
  12. package/__tests__/unit/structureAnalyzer.spec.js +212 -0
  13. package/__tests__/unit/types.spec.ts +179 -0
  14. package/dist/__tests__/unit/ci.spec.d.ts +1 -0
  15. package/dist/__tests__/unit/ci.spec.js +226 -0
  16. package/dist/__tests__/unit/compression.spec.d.ts +4 -0
  17. package/dist/__tests__/unit/compression.spec.js +46 -0
  18. package/dist/ci.d.ts +30 -0
  19. package/dist/ci.js +117 -0
  20. package/dist/cli/index.d.ts +2 -0
  21. package/dist/cli/index.js +47 -0
  22. package/dist/cli/init.d.ts +3 -0
  23. package/dist/cli/init.js +158 -0
  24. package/dist/config/loader.d.ts +29 -0
  25. package/dist/config/loader.js +251 -0
  26. package/dist/domAnalyzer.d.ts +10 -0
  27. package/dist/domAnalyzer.js +285 -0
  28. package/dist/index.d.ts +7 -0
  29. package/dist/index.js +11 -0
  30. package/dist/reporter-entry.d.ts +2 -0
  31. package/dist/reporter-entry.js +5 -0
  32. package/dist/reporter-types.d.ts +2 -0
  33. package/dist/reporter-types.js +2 -0
  34. package/dist/reporter.d.ts +21 -0
  35. package/dist/reporter.js +249 -0
  36. package/dist/snapshot.d.ts +12 -0
  37. package/dist/snapshot.js +601 -0
  38. package/dist/structureAnalyzer.d.ts +12 -0
  39. package/dist/structureAnalyzer.js +288 -0
  40. package/dist/types.d.ts +368 -0
  41. package/dist/types.js +10 -0
  42. package/examples/structure-analysis-example.spec.ts +118 -0
  43. package/examples/structure-analysis.config.ts +159 -0
  44. package/jest.config.js +8 -0
  45. package/package.json +51 -0
  46. package/playwright.config.ts +11 -0
  47. package/src/__tests__/unit/ci.spec.ts +257 -0
  48. package/src/__tests__/unit/compression.spec.ts +52 -0
  49. package/src/ci.ts +140 -0
  50. package/src/cli/index.ts +49 -0
  51. package/src/cli/init.ts +131 -0
  52. package/src/config/loader.ts +238 -0
  53. package/src/index.ts +14 -0
  54. package/src/reporter-entry.ts +6 -0
  55. package/src/reporter-types.ts +5 -0
  56. package/src/reporter.ts +251 -0
  57. package/src/snapshot.ts +632 -0
  58. package/src/structureAnalyzer.ts +338 -0
  59. package/src/types.ts +388 -0
  60. package/tsconfig.jest.json +7 -0
  61. package/tsconfig.json +20 -0
package/src/types.ts ADDED
@@ -0,0 +1,388 @@
1
+ /**
2
+ * Types for Testivai Witness Playwright SDK
3
+ *
4
+ * Defines the data shapes for evidence collection:
5
+ * - SnapshotPayload: DOM + Layout data for a single snapshot
6
+ * - BatchPayload: Git + Browser info + collection of snapshots
7
+ * - TestivAIConfig: Configuration for visual analysis behavior
8
+ */
9
+
10
+ /**
11
+ * Layout configuration for visual analysis
12
+ */
13
+ export interface LayoutConfig {
14
+ /** Sensitivity level: 0-4 scale (0=strict/precise, 4=very lenient) */
15
+ sensitivity: number;
16
+ /** Base pixel tolerance for layout differences */
17
+ tolerance: number;
18
+ /** Per-selector tolerance overrides (optional) */
19
+ selectorTolerances?: Record<string, number>;
20
+ /** Use relative tolerance for large elements (optional) */
21
+ useRelativeTolerance?: boolean;
22
+ /** Percentage multiplier for relative tolerance (optional) */
23
+ relativeTolerance?: number;
24
+ }
25
+
26
+ /**
27
+ * AI configuration for visual analysis
28
+ */
29
+ export interface AIConfig {
30
+ /** Sensitivity level: 0-4 scale (0=conservative, 4=aggressive) */
31
+ sensitivity: number;
32
+ /** Minimum confidence threshold for AI_BUG verdict (0.0-1.0) */
33
+ confidence: number;
34
+ /** Include AI reasoning in results (optional) */
35
+ enableReasoning?: boolean;
36
+ }
37
+
38
+ /**
39
+ * Performance metrics configuration
40
+ */
41
+ export interface PerformanceMetricsConfig {
42
+ /** Enable performance metrics capture (default: true) */
43
+ enabled?: boolean;
44
+ }
45
+
46
+ /**
47
+ * Structure analysis configuration
48
+ * Controls how page structure (HTML elements, hierarchy, semantics) is analyzed.
49
+ * @renamed Was `DOMAnalysisConfig` — renamed to conceal internal layer terminology (IP protection)
50
+ */
51
+ export interface StructureAnalysisConfig {
52
+ /** Enable fingerprint generation (default: true) */
53
+ enableFingerprint?: boolean;
54
+ /** Enable structural analysis (default: true) */
55
+ enableStructure?: boolean;
56
+ /** Enable semantic analysis (default: true) */
57
+ enableSemantic?: boolean;
58
+ /** Attributes to ignore in analysis */
59
+ ignoreAttributes?: string[];
60
+ /** Elements to ignore completely */
61
+ ignoreElements?: string[];
62
+ /** Content patterns to ignore */
63
+ ignoreContentPatterns?: RegExp[];
64
+ }
65
+
66
+ /**
67
+ * Structure fingerprint and analysis result
68
+ * Contains the structural analysis of a page: element fingerprint, hierarchy info, and semantic structure.
69
+ * @renamed Was `DOMAnalysis` — renamed to conceal internal layer terminology (IP protection)
70
+ */
71
+ export interface StructureAnalysis {
72
+ /** Fast hash of normalized DOM structure */
73
+ fingerprint?: string;
74
+ /** Structural information about the DOM */
75
+ structure?: {
76
+ totalElements: number;
77
+ elementTypes: Record<string, number>;
78
+ maxDepth: number;
79
+ interactiveElements: {
80
+ buttons: number;
81
+ inputs: number;
82
+ links: number;
83
+ forms: number;
84
+ };
85
+ };
86
+ /** Semantic structure information */
87
+ semantic?: {
88
+ headings: Record<string, number>;
89
+ landmarks: {
90
+ hasHeader: boolean;
91
+ hasNav: boolean;
92
+ hasMain: boolean;
93
+ hasFooter: boolean;
94
+ hasAside: boolean;
95
+ };
96
+ lists: {
97
+ ordered: number;
98
+ unordered: number;
99
+ };
100
+ tables: number;
101
+ images: number;
102
+ };
103
+ /** Component analysis (if detectable) */
104
+ components?: Record<string, Array<{
105
+ selector: string;
106
+ text: string;
107
+ attributes: Record<string, string>;
108
+ }>>;
109
+ }
110
+
111
+ /**
112
+ * Structure change information
113
+ * Describes a detected change in page structure between baseline and current.
114
+ * @renamed Was `DOMChange` — renamed to conceal internal layer terminology (IP protection)
115
+ */
116
+ export interface StructureChange {
117
+ type: 'fingerprint' | 'structure' | 'semantic' | 'component';
118
+ severity: 'low' | 'medium' | 'high';
119
+ description: string;
120
+ details?: any;
121
+ }
122
+
123
+ /**
124
+ * Performance timing metrics
125
+ * @deprecated Use performanceMetrics with CDP Performance.getMetrics instead
126
+ */
127
+ export interface PerformanceTimings {
128
+ /** Navigation start time */
129
+ navigationStart?: number;
130
+ /** DOM content loaded time */
131
+ domContentLoaded?: number;
132
+ /** Page load complete time */
133
+ loadComplete?: number;
134
+ /** First contentful paint */
135
+ firstContentfulPaint?: number;
136
+ /** Largest contentful paint */
137
+ largestContentfulPaint?: number;
138
+ /** Time to interactive */
139
+ timeToInteractive?: number;
140
+ /** Total blocking time */
141
+ totalBlockingTime?: number;
142
+ /** Cumulative layout shift */
143
+ cumulativeLayoutShift?: number;
144
+ }
145
+
146
+ /**
147
+ * Lighthouse performance results
148
+ * @deprecated Lighthouse has been removed. Use performanceMetrics with CDP Performance.getMetrics instead
149
+ */
150
+ export interface LighthouseResults {
151
+ /** Performance score (0-100) */
152
+ performance?: number;
153
+ /** Accessibility score (0-100) */
154
+ accessibility?: number;
155
+ /** Best practices score (0-100) */
156
+ bestPractices?: number;
157
+ /** SEO score (0-100) */
158
+ seo?: number;
159
+ /** Core Web Vitals */
160
+ coreWebVitals?: {
161
+ lcp?: number;
162
+ fid?: number;
163
+ cls?: number;
164
+ };
165
+ }
166
+
167
+ /**
168
+ * Environment-specific configuration overrides
169
+ */
170
+ export interface EnvironmentConfig {
171
+ /** Configuration for CI environments */
172
+ ci?: {
173
+ layout?: Partial<LayoutConfig>;
174
+ ai?: Partial<AIConfig>;
175
+ };
176
+ /** Configuration for development environments */
177
+ development?: {
178
+ layout?: Partial<LayoutConfig>;
179
+ ai?: Partial<AIConfig>;
180
+ };
181
+ /** Configuration for production environments */
182
+ production?: {
183
+ layout?: Partial<LayoutConfig>;
184
+ ai?: Partial<AIConfig>;
185
+ };
186
+ }
187
+
188
+ /**
189
+ * Complete TestivAI project configuration
190
+ */
191
+ export interface TestivAIProjectConfig {
192
+ /** API key for authentication */
193
+ apiKey?: string;
194
+ /** API endpoint URL (defaults to production) */
195
+ apiUrl?: string;
196
+ /** Layout analysis settings */
197
+ layout: LayoutConfig;
198
+ /** AI analysis settings */
199
+ ai: AIConfig;
200
+ /** Performance metrics settings (optional) */
201
+ performanceMetrics?: PerformanceMetricsConfig;
202
+ /**
203
+ * Structure analysis settings (optional)
204
+ * @renamed Was `dom` — renamed to conceal internal layer terminology (IP protection)
205
+ */
206
+ structure?: StructureAnalysisConfig;
207
+ /** Environment-specific overrides (optional) */
208
+ environments?: EnvironmentConfig;
209
+ }
210
+
211
+ /**
212
+ * Per-test configuration overrides
213
+ */
214
+ export interface TestivAIConfig {
215
+ /** Layout settings (optional - overrides project defaults) */
216
+ layout?: Partial<LayoutConfig>;
217
+ /** AI settings (optional - overrides project defaults) */
218
+ ai?: Partial<AIConfig>;
219
+ /** Performance settings (optional - overrides project defaults) */
220
+ performanceMetrics?: Partial<PerformanceMetricsConfig>;
221
+ /**
222
+ * Structure analysis settings (optional - overrides project defaults)
223
+ * @renamed Was `dom` — renamed to conceal internal layer terminology (IP protection)
224
+ */
225
+ structure?: Partial<StructureAnalysisConfig>;
226
+ /** Element selectors to capture (existing option) */
227
+ selectors?: string[];
228
+ /** Use Chrome DevTools Protocol for full-page capture (default: true - use CDP, set to false for scroll-and-stitch) */
229
+ useCDP?: boolean;
230
+ }
231
+
232
+ /**
233
+ * Layout/Bounding box data for an element
234
+ */
235
+ export interface LayoutData {
236
+ /** X coordinate */
237
+ x: number;
238
+ /** Y coordinate */
239
+ y: number;
240
+ /** Width */
241
+ width: number;
242
+ /** Height */
243
+ height: number;
244
+ /** Top position */
245
+ top: number;
246
+ /** Left position */
247
+ left: number;
248
+ /** Right position */
249
+ right: number;
250
+ /** Bottom position */
251
+ bottom: number;
252
+ }
253
+
254
+ /**
255
+ * Page structure snapshot data (HTML content)
256
+ * @renamed Was `DOMData` — renamed to conceal internal layer terminology (IP protection)
257
+ */
258
+ export interface StructureData {
259
+ /** Serialized HTML of the element */
260
+ html: string;
261
+ /** Computed styles (optional) */
262
+ styles?: Record<string, string>;
263
+ }
264
+
265
+ /**
266
+ * Computed styles data for visual comparison
267
+ * @renamed Was `CSSData` — renamed to conceal internal layer terminology (IP protection)
268
+ */
269
+ export interface StylesData {
270
+ /** Computed styles keyed by element selector path */
271
+ computed_styles: Record<string, Record<string, string>>;
272
+ }
273
+
274
+ /**
275
+ * Snapshot payload for a single evidence capture
276
+ */
277
+ export interface SnapshotPayload {
278
+ /**
279
+ * Page structure data (HTML content)
280
+ * @renamed Was `dom` — renamed to conceal internal layer terminology (IP protection)
281
+ */
282
+ structure: StructureData;
283
+ /**
284
+ * Computed styles data (optional)
285
+ * @renamed Was `css` — renamed to conceal internal layer terminology (IP protection)
286
+ */
287
+ styles?: StylesData;
288
+ /** Layout/bounding box data */
289
+ layout: LayoutData;
290
+ /** Timestamp when snapshot was taken */
291
+ timestamp: number;
292
+ /** Test name or identifier */
293
+ testName: string;
294
+ /** Snapshot name or identifier */
295
+ snapshotName: string;
296
+ /** URL of the page when snapshot was taken */
297
+ url?: string;
298
+ /** Viewport dimensions */
299
+ viewport?: {
300
+ width: number;
301
+ height: number;
302
+ };
303
+ /** TestivAI configuration for this snapshot */
304
+ testivaiConfig?: TestivAIConfig;
305
+ /** Base64-encoded screenshot data (PNG) */
306
+ screenshotData?: string;
307
+ /** Performance timing metrics (optional) */
308
+ performanceTimings?: PerformanceTimings;
309
+ /** Lighthouse results (optional) */
310
+ lighthouseResults?: LighthouseResults;
311
+ /**
312
+ * Structure analysis results (optional)
313
+ * @renamed Was `domAnalysis` — renamed to conceal internal layer terminology (IP protection)
314
+ */
315
+ structureAnalysis?: StructureAnalysis;
316
+ }
317
+
318
+ /**
319
+ * Git information for batch context
320
+ */
321
+ export interface GitInfo {
322
+ /** Current branch name */
323
+ branch: string;
324
+ /** Current commit hash */
325
+ commit: string;
326
+ /** Repository URL (optional) */
327
+ repository?: string;
328
+ /** Commit message (optional) */
329
+ message?: string;
330
+ /** Author name (optional) */
331
+ author?: string;
332
+ }
333
+
334
+ /**
335
+ * Browser context information
336
+ */
337
+ export interface BrowserInfo {
338
+ /** Browser name (chromium, firefox, webkit) */
339
+ name: string;
340
+ /** Browser version */
341
+ version: string;
342
+ /** Viewport width */
343
+ viewportWidth: number;
344
+ /** Viewport height */
345
+ viewportHeight: number;
346
+ /** User agent string */
347
+ userAgent: string;
348
+ /** Operating system */
349
+ os?: string;
350
+ /** Device type (desktop, mobile, tablet) */
351
+ device?: string;
352
+ }
353
+
354
+ /**
355
+ * CI environment information for integration feedback (e.g., GitHub commit statuses, PR comments).
356
+ * Mirrors CiInfo from ci.ts for payload serialization.
357
+ */
358
+ export interface CiInfoPayload {
359
+ /** CI provider name (e.g., 'github_actions', 'gitlab_ci', 'circleci') */
360
+ provider: string;
361
+ /** Pull/Merge request number (if available) */
362
+ prNumber?: number;
363
+ /** URL to the CI run (if available) */
364
+ runUrl?: string;
365
+ /** CI build/run identifier */
366
+ buildId?: string;
367
+ }
368
+
369
+ /**
370
+ * Batch payload containing all evidence for a test run
371
+ */
372
+ export interface BatchPayload {
373
+ /** Git information */
374
+ git: GitInfo;
375
+ /** Browser context information */
376
+ browser: BrowserInfo;
377
+ /** Collection of snapshots */
378
+ snapshots: SnapshotPayload[];
379
+ /** Batch ID (generated) */
380
+ batchId: string;
381
+ /** Timestamp when batch was created */
382
+ timestamp: number;
383
+ /** Unique identifier for a CI/CD run, to group sharded jobs */
384
+ runId?: string | null;
385
+ /** CI environment information for integration feedback (optional) */
386
+ ci?: CiInfoPayload | null;
387
+ }
388
+
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["node", "jest"]
5
+ },
6
+ "include": ["__tests__/unit/**/*.ts"]
7
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020", "DOM"],
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "allowSyntheticDefaultImports": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "resolveJsonModule": true,
14
+ "moduleResolution": "node",
15
+ "types": ["node", "@playwright/test", "jest"]
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist", "__tests__"]
19
+ }
20
+