@testivai/witness-playwright 0.1.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 (43) hide show
  1. package/README.md +65 -0
  2. package/__tests__/.gitkeep +0 -0
  3. package/__tests__/config-integration.spec.ts +102 -0
  4. package/__tests__/snapshot.spec.d.ts +1 -0
  5. package/__tests__/snapshot.spec.js +81 -0
  6. package/__tests__/snapshot.spec.ts +58 -0
  7. package/__tests__/unit/ci.spec.d.ts +1 -0
  8. package/__tests__/unit/ci.spec.js +35 -0
  9. package/__tests__/unit/ci.spec.ts +40 -0
  10. package/__tests__/unit/reporter.spec.d.ts +1 -0
  11. package/__tests__/unit/reporter.spec.js +37 -0
  12. package/__tests__/unit/reporter.spec.ts +43 -0
  13. package/dist/ci.d.ts +10 -0
  14. package/dist/ci.js +35 -0
  15. package/dist/cli/init.d.ts +3 -0
  16. package/dist/cli/init.js +146 -0
  17. package/dist/config/loader.d.ts +29 -0
  18. package/dist/config/loader.js +232 -0
  19. package/dist/index.d.ts +7 -0
  20. package/dist/index.js +24 -0
  21. package/dist/reporter-types.d.ts +2 -0
  22. package/dist/reporter-types.js +2 -0
  23. package/dist/reporter.d.ts +16 -0
  24. package/dist/reporter.js +155 -0
  25. package/dist/snapshot.d.ts +12 -0
  26. package/dist/snapshot.js +122 -0
  27. package/dist/types.d.ts +181 -0
  28. package/dist/types.js +10 -0
  29. package/jest.config.js +11 -0
  30. package/package.json +47 -0
  31. package/playwright.config.ts +11 -0
  32. package/progress.md +620 -0
  33. package/src/ci.ts +34 -0
  34. package/src/cli/init.ts +119 -0
  35. package/src/config/loader.ts +219 -0
  36. package/src/index.ts +9 -0
  37. package/src/reporter-types.ts +5 -0
  38. package/src/reporter.ts +148 -0
  39. package/src/snapshot.ts +103 -0
  40. package/src/types.ts +193 -0
  41. package/test-results/.last-run.json +4 -0
  42. package/tsconfig.jest.json +7 -0
  43. package/tsconfig.json +19 -0
package/src/types.ts ADDED
@@ -0,0 +1,193 @@
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
+ * Environment-specific configuration overrides
40
+ */
41
+ export interface EnvironmentConfig {
42
+ /** Configuration for CI environments */
43
+ ci?: {
44
+ layout?: Partial<LayoutConfig>;
45
+ ai?: Partial<AIConfig>;
46
+ };
47
+ /** Configuration for development environments */
48
+ development?: {
49
+ layout?: Partial<LayoutConfig>;
50
+ ai?: Partial<AIConfig>;
51
+ };
52
+ /** Configuration for production environments */
53
+ production?: {
54
+ layout?: Partial<LayoutConfig>;
55
+ ai?: Partial<AIConfig>;
56
+ };
57
+ }
58
+
59
+ /**
60
+ * Complete TestivAI project configuration
61
+ */
62
+ export interface TestivAIProjectConfig {
63
+ /** Layout analysis settings */
64
+ layout: LayoutConfig;
65
+ /** AI analysis settings */
66
+ ai: AIConfig;
67
+ /** Environment-specific overrides (optional) */
68
+ environments?: EnvironmentConfig;
69
+ }
70
+
71
+ /**
72
+ * Per-test configuration overrides
73
+ */
74
+ export interface TestivAIConfig {
75
+ /** Layout settings (optional - overrides project defaults) */
76
+ layout?: Partial<LayoutConfig>;
77
+ /** AI settings (optional - overrides project defaults) */
78
+ ai?: Partial<AIConfig>;
79
+ /** Element selectors to capture (existing option) */
80
+ selectors?: string[];
81
+ }
82
+
83
+ /**
84
+ * Layout/Bounding box data for an element
85
+ */
86
+ export interface LayoutData {
87
+ /** X coordinate */
88
+ x: number;
89
+ /** Y coordinate */
90
+ y: number;
91
+ /** Width */
92
+ width: number;
93
+ /** Height */
94
+ height: number;
95
+ /** Top position */
96
+ top: number;
97
+ /** Left position */
98
+ left: number;
99
+ /** Right position */
100
+ right: number;
101
+ /** Bottom position */
102
+ bottom: number;
103
+ }
104
+
105
+ /**
106
+ * DOM snapshot data
107
+ */
108
+ export interface DOMData {
109
+ /** Serialized HTML of the element */
110
+ html: string;
111
+ /** Computed styles (optional) */
112
+ styles?: Record<string, string>;
113
+ }
114
+
115
+ /**
116
+ * Snapshot payload for a single evidence capture
117
+ */
118
+ export interface SnapshotPayload {
119
+ /** DOM data (HTML + styles) */
120
+ dom: DOMData;
121
+ /** Layout/bounding box data */
122
+ layout: LayoutData;
123
+ /** Timestamp when snapshot was taken */
124
+ timestamp: number;
125
+ /** Test name or identifier */
126
+ testName: string;
127
+ /** Snapshot name or identifier */
128
+ snapshotName: string;
129
+ /** URL of the page when snapshot was taken */
130
+ url?: string;
131
+ /** Viewport dimensions */
132
+ viewport?: {
133
+ width: number;
134
+ height: number;
135
+ };
136
+ /** TestivAI configuration for this snapshot */
137
+ testivaiConfig?: TestivAIConfig;
138
+ }
139
+
140
+ /**
141
+ * Git information for batch context
142
+ */
143
+ export interface GitInfo {
144
+ /** Current branch name */
145
+ branch: string;
146
+ /** Current commit hash */
147
+ commit: string;
148
+ /** Repository URL (optional) */
149
+ repository?: string;
150
+ /** Commit message (optional) */
151
+ message?: string;
152
+ /** Author name (optional) */
153
+ author?: string;
154
+ }
155
+
156
+ /**
157
+ * Browser context information
158
+ */
159
+ export interface BrowserInfo {
160
+ /** Browser name (chromium, firefox, webkit) */
161
+ name: string;
162
+ /** Browser version */
163
+ version: string;
164
+ /** Viewport width */
165
+ viewportWidth: number;
166
+ /** Viewport height */
167
+ viewportHeight: number;
168
+ /** User agent string */
169
+ userAgent: string;
170
+ /** Operating system */
171
+ os?: string;
172
+ /** Device type (desktop, mobile, tablet) */
173
+ device?: string;
174
+ }
175
+
176
+ /**
177
+ * Batch payload containing all evidence for a test run
178
+ */
179
+ export interface BatchPayload {
180
+ /** Git information */
181
+ git: GitInfo;
182
+ /** Browser context information */
183
+ browser: BrowserInfo;
184
+ /** Collection of snapshots */
185
+ snapshots: SnapshotPayload[];
186
+ /** Batch ID (generated) */
187
+ batchId: string;
188
+ /** Timestamp when batch was created */
189
+ timestamp: number;
190
+ /** Unique identifier for a CI/CD run, to group sharded jobs */
191
+ runId?: string | null;
192
+ }
193
+
@@ -0,0 +1,4 @@
1
+ {
2
+ "status": "passed",
3
+ "failedTests": []
4
+ }
@@ -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,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "declaration": true,
7
+ "outDir": "./dist",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "moduleResolution": "node",
14
+ "types": ["node", "@playwright/test", "jest"]
15
+ },
16
+ "include": ["src/**/*"],
17
+ "exclude": ["node_modules", "dist", "__tests__"]
18
+ }
19
+