@testivai/witness-cdp 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.
- package/LICENSE +21 -0
- package/README.md +405 -0
- package/dist/__tests__/setup.d.ts +4 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +24 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/bin/testivai.d.ts +3 -0
- package/dist/bin/testivai.d.ts.map +1 -0
- package/dist/bin/testivai.js +48 -0
- package/dist/bin/testivai.js.map +1 -0
- package/dist/cdp/binding.d.ts +56 -0
- package/dist/cdp/binding.d.ts.map +1 -0
- package/dist/cdp/binding.js +364 -0
- package/dist/cdp/binding.js.map +1 -0
- package/dist/cdp/capture.d.ts +61 -0
- package/dist/cdp/capture.d.ts.map +1 -0
- package/dist/cdp/capture.js +422 -0
- package/dist/cdp/capture.js.map +1 -0
- package/dist/cdp/client.d.ts +63 -0
- package/dist/cdp/client.d.ts.map +1 -0
- package/dist/cdp/client.js +279 -0
- package/dist/cdp/client.js.map +1 -0
- package/dist/cdp/discovery.d.ts +33 -0
- package/dist/cdp/discovery.d.ts.map +1 -0
- package/dist/cdp/discovery.js +157 -0
- package/dist/cdp/discovery.js.map +1 -0
- package/dist/ci.d.ts +31 -0
- package/dist/ci.d.ts.map +1 -0
- package/dist/ci.js +118 -0
- package/dist/ci.js.map +1 -0
- package/dist/commands/auth.d.ts +3 -0
- package/dist/commands/auth.d.ts.map +1 -0
- package/dist/commands/auth.js +122 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/capture.d.ts +3 -0
- package/dist/commands/capture.d.ts.map +1 -0
- package/dist/commands/capture.js +143 -0
- package/dist/commands/capture.js.map +1 -0
- package/dist/commands/init.d.ts +3 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +255 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/run.d.ts +3 -0
- package/dist/commands/run.d.ts.map +1 -0
- package/dist/commands/run.js +438 -0
- package/dist/commands/run.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +77 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +329 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/file-naming.d.ts +31 -0
- package/dist/utils/file-naming.d.ts.map +1 -0
- package/dist/utils/file-naming.js +137 -0
- package/dist/utils/file-naming.js.map +1 -0
- package/dist/utils/framework-detect.d.ts +31 -0
- package/dist/utils/framework-detect.d.ts.map +1 -0
- package/dist/utils/framework-detect.js +379 -0
- package/dist/utils/framework-detect.js.map +1 -0
- package/dist/utils/logger.d.ts +29 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +114 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/process.d.ts +61 -0
- package/dist/utils/process.d.ts.map +1 -0
- package/dist/utils/process.js +208 -0
- package/dist/utils/process.js.map +1 -0
- package/dist/utils/template-generator.d.ts +36 -0
- package/dist/utils/template-generator.d.ts.map +1 -0
- package/dist/utils/template-generator.js +255 -0
- package/dist/utils/template-generator.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TestivAI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# @testivai/witness-cdp
|
|
2
|
+
|
|
3
|
+
Framework-agnostic visual regression testing SDK using Chrome DevTools Protocol.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The TestivAI CDP SDK allows you to integrate visual regression testing into any test framework that can control Chrome/Chromium browsers. It works by connecting directly to the Chrome DevTools Protocol (CDP) and injecting a `window.testivaiWitness` function that triggers visual captures.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g @testivai/witness-cdp
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
1. **Initialize your project**
|
|
18
|
+
```bash
|
|
19
|
+
npx testivai init
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. **Authenticate with your API key**
|
|
23
|
+
```bash
|
|
24
|
+
npx testivai auth <your-api-key>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
3. **Add visual captures to your tests**
|
|
28
|
+
```javascript
|
|
29
|
+
// In your test code
|
|
30
|
+
await window.testivaiWitness('my-snapshot');
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
4. **Run your tests**
|
|
34
|
+
```bash
|
|
35
|
+
# Make sure Chrome is running with remote debugging
|
|
36
|
+
chrome --remote-debugging-port=9222
|
|
37
|
+
|
|
38
|
+
# Run your tests with TestivAI
|
|
39
|
+
testivai run "npm test"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Framework Integration
|
|
43
|
+
|
|
44
|
+
### Cypress
|
|
45
|
+
|
|
46
|
+
Add this custom command to `cypress/support/commands.js`:
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
// testivai-witness-cdp.js
|
|
50
|
+
Cypress.Commands.add('witness', (name) => {
|
|
51
|
+
return cy.window().invoke('testivaiWitness', name);
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Use in your tests:
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
it('should capture visual snapshot', () => {
|
|
59
|
+
cy.visit('/my-page');
|
|
60
|
+
cy.witness('my-snapshot');
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Run tests:
|
|
65
|
+
```bash
|
|
66
|
+
testivai run "cypress run"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Selenium (Python)
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from selenium import webdriver
|
|
73
|
+
|
|
74
|
+
def capture_snapshot(driver, name):
|
|
75
|
+
driver.execute_script(f"return window.testivaiWitness('{name}')")
|
|
76
|
+
|
|
77
|
+
def test_visual_snapshot():
|
|
78
|
+
driver = webdriver.Chrome()
|
|
79
|
+
driver.get("http://localhost:3000")
|
|
80
|
+
capture_snapshot(driver, "my-snapshot")
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run tests:
|
|
84
|
+
```bash
|
|
85
|
+
testivai run "pytest tests/"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Selenium (JavaScript)
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
const { Builder, By } = require('selenium-webdriver');
|
|
92
|
+
|
|
93
|
+
async function captureSnapshot(driver, name) {
|
|
94
|
+
await driver.executeScript(`return window.testivaiWitness('${name}')`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
it('should capture visual snapshot', async () => {
|
|
98
|
+
const driver = await new Builder().forBrowser('chrome').build();
|
|
99
|
+
await driver.get('http://localhost:3000');
|
|
100
|
+
await captureSnapshot(driver, 'my-snapshot');
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Run tests:
|
|
105
|
+
```bash
|
|
106
|
+
testivai run "npm test"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### WebdriverIO
|
|
110
|
+
|
|
111
|
+
Add this custom command to your test setup:
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
// In wdio.conf.js or test setup
|
|
115
|
+
browser.addCommand('witness', function(name) {
|
|
116
|
+
return this.executeScript('return window.testivaiWitness(arguments[0])', name);
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Use in your tests:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
it('should capture visual snapshot', async () => {
|
|
124
|
+
await browser.url('/my-page');
|
|
125
|
+
await browser.witness('my-snapshot');
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Run tests:
|
|
130
|
+
```bash
|
|
131
|
+
testivai run "npx wdio"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## How It Works
|
|
135
|
+
|
|
136
|
+
1. **CDP Connection**: The SDK connects to Chrome's DevTools Protocol (usually on port 9222)
|
|
137
|
+
2. **Binding Injection**: Using `Runtime.addBinding`, it injects a native function `window.testivaiWitness`
|
|
138
|
+
3. **Promise Wrapper**: A client-side script wraps the native binding in a Promise for async/await support
|
|
139
|
+
4. **Capture Trigger**: When `window.testivaiWitness('name')` is called, it triggers:
|
|
140
|
+
- Screenshot capture
|
|
141
|
+
- DOM extraction
|
|
142
|
+
- Layout analysis
|
|
143
|
+
- Performance metrics
|
|
144
|
+
5. **Batch Upload**: All captures are batched and uploaded to TestivAI for analysis
|
|
145
|
+
|
|
146
|
+
## Configuration
|
|
147
|
+
|
|
148
|
+
Create a `testivai.config.ts` file in your project root:
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import type { CdpConfig } from '@testivai/witness-cdp';
|
|
152
|
+
|
|
153
|
+
const config: CdpConfig = {
|
|
154
|
+
// API key (set via TESTIVAI_API_KEY environment variable)
|
|
155
|
+
// apiKey: 'your-api-key-here',
|
|
156
|
+
|
|
157
|
+
// Project ID from TestivAI dashboard
|
|
158
|
+
// projectId: 'your-project-id-here',
|
|
159
|
+
|
|
160
|
+
// Chrome DevTools Protocol port
|
|
161
|
+
cdpPort: 9222,
|
|
162
|
+
|
|
163
|
+
// Auto-launch Chrome if not running (experimental)
|
|
164
|
+
autoLaunch: false,
|
|
165
|
+
|
|
166
|
+
// Chrome executable path (for auto-launch)
|
|
167
|
+
// chromePath: '/path/to/chrome',
|
|
168
|
+
|
|
169
|
+
// Additional Chrome arguments
|
|
170
|
+
chromeArgs: [
|
|
171
|
+
'--no-sandbox',
|
|
172
|
+
'--disable-dev-shm-usage',
|
|
173
|
+
'--disable-gpu',
|
|
174
|
+
],
|
|
175
|
+
|
|
176
|
+
// Connection settings
|
|
177
|
+
connectionTimeout: 5000,
|
|
178
|
+
connectionRetries: 3,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export default config;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## CLI Commands
|
|
185
|
+
|
|
186
|
+
### `npx testivai init`
|
|
187
|
+
Initialize TestivAI in your project. Detects your framework and provides setup instructions.
|
|
188
|
+
|
|
189
|
+
### `npx testivai auth <api-key>`
|
|
190
|
+
Authenticate with your TestivAI API key. Get your key from the [dashboard](https://dashboard.testiv.ai).
|
|
191
|
+
|
|
192
|
+
### `npx testivai run <command>`
|
|
193
|
+
Run your test command with automatic visual capture.
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
npx testivai run "npm test"
|
|
197
|
+
npx testivai run "cypress run"
|
|
198
|
+
npx testivai run "pytest tests/"
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Options:
|
|
202
|
+
- `-p, --port <number>` - Specify CDP port (default: 9222)
|
|
203
|
+
- `-b, --batch-id <id>` - Specify batch ID (auto-generated if not provided)
|
|
204
|
+
|
|
205
|
+
### `npx testivai capture <name>`
|
|
206
|
+
Capture a single snapshot without running tests.
|
|
207
|
+
|
|
208
|
+
```bash
|
|
209
|
+
npx testivai capture "my-snapshot" --format json
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Options:
|
|
213
|
+
- `-p, --port <number>` - Specify CDP port
|
|
214
|
+
- `-o, --output <path>` - Output directory (default: .testivai/captures)
|
|
215
|
+
- `-f, --format <format>` - Output format: json|png (default: json)
|
|
216
|
+
|
|
217
|
+
## Chrome Setup
|
|
218
|
+
|
|
219
|
+
### Manual Launch
|
|
220
|
+
|
|
221
|
+
Launch Chrome with remote debugging enabled:
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# macOS
|
|
225
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222
|
|
226
|
+
|
|
227
|
+
# Windows
|
|
228
|
+
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222
|
|
229
|
+
|
|
230
|
+
# Linux
|
|
231
|
+
google-chrome --remote-debugging-port=9222
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Common Chrome Arguments
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
chrome \
|
|
238
|
+
--remote-debugging-port=9222 \
|
|
239
|
+
--no-sandbox \
|
|
240
|
+
--disable-dev-shm-usage \
|
|
241
|
+
--disable-gpu \
|
|
242
|
+
--headless # For CI environments
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
## CI/CD Integration
|
|
246
|
+
|
|
247
|
+
### GitHub Actions
|
|
248
|
+
|
|
249
|
+
```yaml
|
|
250
|
+
name: Visual Tests
|
|
251
|
+
on: [push, pull_request]
|
|
252
|
+
|
|
253
|
+
jobs:
|
|
254
|
+
visual:
|
|
255
|
+
runs-on: ubuntu-latest
|
|
256
|
+
steps:
|
|
257
|
+
- uses: actions/checkout@v3
|
|
258
|
+
|
|
259
|
+
- name: Setup Node.js
|
|
260
|
+
uses: actions/setup-node@v3
|
|
261
|
+
with:
|
|
262
|
+
node-version: '18'
|
|
263
|
+
|
|
264
|
+
- name: Install dependencies
|
|
265
|
+
run: npm ci
|
|
266
|
+
|
|
267
|
+
- name: Install TestivAI CDP SDK
|
|
268
|
+
run: npm install -g @testivai/witness-cdp
|
|
269
|
+
|
|
270
|
+
- name: Start Chrome
|
|
271
|
+
run: |
|
|
272
|
+
google-chrome \
|
|
273
|
+
--remote-debugging-port=9222 \
|
|
274
|
+
--no-sandbox \
|
|
275
|
+
--disable-dev-shm-usage \
|
|
276
|
+
--headless \
|
|
277
|
+
--disable-gpu &
|
|
278
|
+
|
|
279
|
+
- name: Authenticate
|
|
280
|
+
run: testivai auth ${{ secrets.TESTIVAI_API_KEY }}
|
|
281
|
+
|
|
282
|
+
- name: Run visual tests
|
|
283
|
+
run: testivai run "npm test"
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Jenkins
|
|
287
|
+
|
|
288
|
+
```groovy
|
|
289
|
+
pipeline {
|
|
290
|
+
agent any
|
|
291
|
+
|
|
292
|
+
stages {
|
|
293
|
+
stage('Setup') {
|
|
294
|
+
steps {
|
|
295
|
+
sh 'npm ci'
|
|
296
|
+
sh 'npm install -g @testivai/witness-cdp'
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
stage('Start Chrome') {
|
|
301
|
+
steps {
|
|
302
|
+
sh '''
|
|
303
|
+
google-chrome \
|
|
304
|
+
--remote-debugging-port=9222 \
|
|
305
|
+
--no-sandbox \
|
|
306
|
+
--disable-dev-shm-usage \
|
|
307
|
+
--headless &
|
|
308
|
+
'''
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
stage('Visual Tests') {
|
|
313
|
+
steps {
|
|
314
|
+
withCredentials([string(credentialsId: 'testivai-api-key', variable: 'API_KEY')]) {
|
|
315
|
+
sh 'testivai auth $API_KEY'
|
|
316
|
+
sh 'testivai run "npm test"'
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## Troubleshooting
|
|
325
|
+
|
|
326
|
+
### Chrome not found
|
|
327
|
+
```
|
|
328
|
+
❌ Chrome DevTools Protocol not found
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
**Solution**: Make sure Chrome is running with remote debugging:
|
|
332
|
+
```bash
|
|
333
|
+
chrome --remote-debugging-port=9222
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### Connection timeout
|
|
337
|
+
```
|
|
338
|
+
❌ Failed to connect to CDP: Connection timeout
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
**Solution**:
|
|
342
|
+
1. Check if Chrome is running
|
|
343
|
+
2. Verify the port number (default: 9222)
|
|
344
|
+
3. Check for firewall issues
|
|
345
|
+
|
|
346
|
+
### Tests hang after calling testivaiWitness
|
|
347
|
+
**Solution**: The Promise wrapper might not be working. Check browser console for errors and ensure CDP is properly connected.
|
|
348
|
+
|
|
349
|
+
### No snapshots captured
|
|
350
|
+
**Solution**:
|
|
351
|
+
1. Verify `window.testivaiWitness` is available in your tests
|
|
352
|
+
2. Check that the SDK is connected before running tests
|
|
353
|
+
3. Enable verbose logging: `testivai run "npm test" --verbose`
|
|
354
|
+
|
|
355
|
+
## Performance
|
|
356
|
+
|
|
357
|
+
- **Package size**: ~270KB (no browser binaries included)
|
|
358
|
+
- **Memory usage**: ~50MB additional overhead
|
|
359
|
+
- **Capture time**: ~100-500ms per snapshot
|
|
360
|
+
- **Upload time**: Depends on network and snapshot size
|
|
361
|
+
|
|
362
|
+
## API Reference
|
|
363
|
+
|
|
364
|
+
### CdpClient
|
|
365
|
+
Main class for connecting to Chrome DevTools Protocol.
|
|
366
|
+
|
|
367
|
+
```typescript
|
|
368
|
+
import { CdpClient } from '@testivai/witness-cdp';
|
|
369
|
+
|
|
370
|
+
const client = new CdpClient();
|
|
371
|
+
await client.connect(9222);
|
|
372
|
+
await client.send('Page.navigate', { url: 'https://example.com' });
|
|
373
|
+
await client.disconnect();
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### CdpCapture
|
|
377
|
+
Handles screenshot and data capture.
|
|
378
|
+
|
|
379
|
+
```typescript
|
|
380
|
+
import { CdpCapture } from '@testivai/witness-cdp';
|
|
381
|
+
|
|
382
|
+
const capture = new CdpCapture(client);
|
|
383
|
+
const snapshot = await capture.captureSnapshot('my-snapshot');
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### CdpBinding
|
|
387
|
+
Manages the `window.testivaiWitness` binding.
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
import { CdpBinding } from '@testivai/witness-cdp';
|
|
391
|
+
|
|
392
|
+
const binding = new CdpBinding(client);
|
|
393
|
+
await binding.setupBindings();
|
|
394
|
+
const snapshots = binding.getSnapshots();
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## License
|
|
398
|
+
|
|
399
|
+
MIT
|
|
400
|
+
|
|
401
|
+
## Support
|
|
402
|
+
|
|
403
|
+
- Documentation: https://docs.testiv.ai/cdp
|
|
404
|
+
- Issues: https://github.com/testivai/testivai-monorepo/issues
|
|
405
|
+
- Email: support@testiv.ai
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Jest test setup
|
|
4
|
+
*/
|
|
5
|
+
// Mock console methods to reduce noise in tests
|
|
6
|
+
global.console = {
|
|
7
|
+
...console,
|
|
8
|
+
// Uncomment to suppress console.log during tests
|
|
9
|
+
// log: jest.fn(),
|
|
10
|
+
// debug: jest.fn(),
|
|
11
|
+
// info: jest.fn(),
|
|
12
|
+
// warn: jest.fn(),
|
|
13
|
+
// error: jest.fn(),
|
|
14
|
+
};
|
|
15
|
+
// Set test timeout
|
|
16
|
+
jest.setTimeout(10000);
|
|
17
|
+
// Mock environment variables
|
|
18
|
+
process.env.NODE_ENV = 'test';
|
|
19
|
+
process.env.TESTIVAI_API_URL = 'http://localhost:3000';
|
|
20
|
+
// Global test utilities
|
|
21
|
+
global.mockFetch = jest.fn();
|
|
22
|
+
// Mock fetch globally
|
|
23
|
+
global.fetch = global.mockFetch;
|
|
24
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/__tests__/setup.ts"],"names":[],"mappings":";AAAA;;GAEG;AAEH,gDAAgD;AAChD,MAAM,CAAC,OAAO,GAAG;IACf,GAAG,OAAO;IACV,iDAAiD;IACjD,kBAAkB;IAClB,oBAAoB;IACpB,mBAAmB;IACnB,mBAAmB;IACnB,oBAAoB;CACrB,CAAC;AAEF,mBAAmB;AACnB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAEvB,6BAA6B;AAC7B,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,MAAM,CAAC;AAC9B,OAAO,CAAC,GAAG,CAAC,gBAAgB,GAAG,uBAAuB,CAAC;AAEvD,wBAAwB;AACvB,MAAc,CAAC,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEtC,sBAAsB;AACrB,MAAc,CAAC,KAAK,GAAI,MAAc,CAAC,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testivai.d.ts","sourceRoot":"","sources":["../../src/bin/testivai.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const auth_1 = require("../commands/auth");
|
|
10
|
+
const init_1 = require("../commands/init");
|
|
11
|
+
const run_1 = require("../commands/run");
|
|
12
|
+
const capture_1 = require("../commands/capture");
|
|
13
|
+
const packageJson = require('../../package.json');
|
|
14
|
+
const program = new commander_1.Command();
|
|
15
|
+
// Display banner
|
|
16
|
+
const showBanner = () => {
|
|
17
|
+
console.log();
|
|
18
|
+
console.log(chalk_1.default.cyan.bold(' TestivAI'));
|
|
19
|
+
console.log(chalk_1.default.gray(' Catch Visual Bugs Automatically'));
|
|
20
|
+
console.log(chalk_1.default.gray(' AI that catches real bugs, ignores the noise.'));
|
|
21
|
+
console.log();
|
|
22
|
+
};
|
|
23
|
+
program
|
|
24
|
+
.name('testivai')
|
|
25
|
+
.description('TestivAI CDP SDK - Framework-agnostic visual regression testing')
|
|
26
|
+
.version(packageJson.version, '-v, --version', 'Display version number')
|
|
27
|
+
.hook('preAction', () => {
|
|
28
|
+
if (!process.argv.includes('--quiet') && !process.argv.includes('-q')) {
|
|
29
|
+
showBanner();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
// Global options
|
|
33
|
+
program
|
|
34
|
+
.option('-v, --verbose', 'Enable verbose output')
|
|
35
|
+
.option('-q, --quiet', 'Suppress output (ideal for CI)')
|
|
36
|
+
.option('--debug', 'Enable debug mode');
|
|
37
|
+
// Add commands
|
|
38
|
+
program.addCommand(auth_1.authCommand);
|
|
39
|
+
program.addCommand(init_1.initCommand);
|
|
40
|
+
program.addCommand(run_1.runCommand);
|
|
41
|
+
program.addCommand(capture_1.witnessCommand);
|
|
42
|
+
// Parse arguments
|
|
43
|
+
program.parse();
|
|
44
|
+
// Show help if no command provided
|
|
45
|
+
if (!process.argv.slice(2).length) {
|
|
46
|
+
program.outputHelp();
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=testivai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testivai.js","sourceRoot":"","sources":["../../src/bin/testivai.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,kDAA0B;AAC1B,2CAA+C;AAC/C,2CAA+C;AAC/C,yCAA6C;AAC7C,iDAAqD;AAErD,MAAM,WAAW,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAElD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,iBAAiB;AACjB,MAAM,UAAU,GAAG,GAAG,EAAE;IACtB,OAAO,CAAC,GAAG,EAAE,CAAC;IACd,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC,CAAC;IAC3E,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,iEAAiE,CAAC;KAC9E,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,eAAe,EAAE,wBAAwB,CAAC;KACvE,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE;IACtB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtE,UAAU,EAAE,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,iBAAiB;AACjB,OAAO;KACJ,MAAM,CAAC,eAAe,EAAE,uBAAuB,CAAC;KAChD,MAAM,CAAC,aAAa,EAAE,gCAAgC,CAAC;KACvD,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;AAE1C,eAAe;AACf,OAAO,CAAC,UAAU,CAAC,kBAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,kBAAW,CAAC,CAAC;AAChC,OAAO,CAAC,UAAU,CAAC,gBAAU,CAAC,CAAC;AAC/B,OAAO,CAAC,UAAU,CAAC,wBAAc,CAAC,CAAC;AAEnC,kBAAkB;AAClB,OAAO,CAAC,KAAK,EAAE,CAAC;AAEhB,mCAAmC;AACnC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClC,OAAO,CAAC,UAAU,EAAE,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CdpClient } from './client';
|
|
2
|
+
/**
|
|
3
|
+
* CDP Binding management
|
|
4
|
+
*/
|
|
5
|
+
export declare class CdpBinding {
|
|
6
|
+
private client;
|
|
7
|
+
private capture;
|
|
8
|
+
private snapshots;
|
|
9
|
+
private isBindingRegistered;
|
|
10
|
+
private pollInterval?;
|
|
11
|
+
private logger;
|
|
12
|
+
constructor(client: CdpClient, options?: {
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Set up the Runtime bindings
|
|
17
|
+
*/
|
|
18
|
+
setupBindings(): Promise<void>;
|
|
19
|
+
/**
|
|
20
|
+
* Inject the client-side script into all pages
|
|
21
|
+
*/
|
|
22
|
+
private injectClientScript;
|
|
23
|
+
/**
|
|
24
|
+
* Set up polling for capture requests
|
|
25
|
+
*/
|
|
26
|
+
private setupEventListeners;
|
|
27
|
+
/**
|
|
28
|
+
* Handle a witness binding call
|
|
29
|
+
*/
|
|
30
|
+
private handleWitnessCall;
|
|
31
|
+
/**
|
|
32
|
+
* Capture performance metrics using CDP Performance API
|
|
33
|
+
*/
|
|
34
|
+
private capturePerformanceMetrics;
|
|
35
|
+
/**
|
|
36
|
+
* Send ACK to resolve the Promise
|
|
37
|
+
*/
|
|
38
|
+
private sendAck;
|
|
39
|
+
/**
|
|
40
|
+
* Get all captured snapshots
|
|
41
|
+
*/
|
|
42
|
+
getSnapshots(): any[];
|
|
43
|
+
/**
|
|
44
|
+
* Clear all captured snapshots
|
|
45
|
+
*/
|
|
46
|
+
clearSnapshots(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Check if bindings are registered
|
|
49
|
+
*/
|
|
50
|
+
isRegistered(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Clean up resources
|
|
53
|
+
*/
|
|
54
|
+
cleanup(): void;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../../src/cdp/binding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAoCrC;;GAEG;AACH,qBAAa,UAAU;IAOT,OAAO,CAAC,MAAM;IAN1B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,mBAAmB,CAAS;IACpC,OAAO,CAAC,YAAY,CAAC,CAAiB;IACtC,OAAO,CAAC,MAAM,CAAM;gBAEA,MAAM,EAAE,SAAS,EAAE,OAAO,GAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAO;IAOxE;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBpC;;OAEG;YACW,kBAAkB;IA2BhC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA8D3B;;OAEG;YACW,iBAAiB;IAwE/B;;OAEG;YACW,yBAAyB;IA4GvC;;OAEG;YACW,OAAO;IAWrB;;OAEG;IACH,YAAY,IAAI,GAAG,EAAE;IAIrB;;OAEG;IACH,cAAc,IAAI,IAAI;IAKtB;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,OAAO,IAAI,IAAI;CAMhB"}
|