@vizzly-testing/cli 0.1.0 → 0.2.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,412 @@
1
+ # Test Integration Guide
2
+
3
+ The `vizzly run` command integrates Vizzly directly into your test suite, automatically capturing screenshots during test execution and processing them through Vizzly's visual comparison pipeline.
4
+
5
+ ## Command Options
6
+
7
+ **`--build-name <name>`** - Custom build name
8
+ ```bash
9
+ vizzly run "npm test" --build-name "PR-123"
10
+ ```
11
+
12
+ **`--environment <env>`** - Environment name (default: "test")
13
+ ```bash
14
+ vizzly run "npm test" --environment "staging"
15
+ ```
16
+
17
+ **`--branch <branch>`** - Git branch override
18
+ ```bash
19
+ vizzly run "npm test" --branch "feature/new-ui"
20
+ ```
21
+
22
+ **`--commit <sha>`** - Git commit SHA override
23
+ ```bash
24
+ vizzly run "npm test" --commit "abc123def456"
25
+ ```
26
+
27
+ **`--message <msg>`** - Commit message override
28
+ ```bash
29
+ vizzly run "npm test" --message "Add new component"
30
+ ```## Basic Usage
31
+
32
+ ```bash
33
+ vizzly run "<your-test-command>"
34
+ ```
35
+
36
+ Examples with different test frameworks:
37
+
38
+ ```bash
39
+ vizzly run "npm test"
40
+ vizzly run "npx playwright test"
41
+ vizzly run "npx cypress run"
42
+ vizzly run "bundle exec rspec"
43
+ vizzly run "python -m pytest"
44
+ ```
45
+
46
+ ## How It Works
47
+
48
+ When you run `vizzly run`:
49
+
50
+ 1. **Starts a local server** - Creates a screenshot capture endpoint
51
+ 2. **Sets environment variables** - Makes Vizzly available to your tests
52
+ 3. **Runs your test command** - Executes your normal test suite
53
+ 4. **Captures screenshots** - Collects screenshots from `vizzlyScreenshot()` calls
54
+ 5. **Uploads results** - Sends all screenshots to Vizzly for processing
55
+
56
+ ## Environment Variables
57
+
58
+ The CLI automatically sets these variables for your test process:
59
+
60
+ - `VIZZLY_SERVER_URL` - Local server URL for screenshot uploads
61
+ - `VIZZLY_BUILD_ID` - Unique identifier for this test run
62
+ - `VIZZLY_ENABLED` - Set to `true` to enable screenshot capture
63
+ - `VIZZLY_TDD_MODE` - Set to `true` when using `--tdd` flag
64
+
65
+ ## Adding Screenshots to Tests
66
+
67
+ Import the client and use `vizzlyScreenshot()` in your tests:
68
+
69
+ ```javascript
70
+ import { vizzlyScreenshot } from '@vizzly-testing/cli/client';
71
+
72
+ // Your test framework takes the screenshot
73
+ const screenshot = await page.screenshot();
74
+
75
+ // Send to Vizzly
76
+ await vizzlyScreenshot('homepage', screenshot, {
77
+ properties: {
78
+ browser: 'chrome',
79
+ viewport: '1920x1080'
80
+ }
81
+ });
82
+ ```
83
+
84
+ ## Framework Examples
85
+
86
+ ### Playwright
87
+
88
+ ```javascript
89
+ import { test } from '@playwright/test';
90
+ import { vizzlyScreenshot } from '@vizzly-testing/cli/client';
91
+
92
+ test('homepage test', async ({ page }) => {
93
+ await page.goto('/');
94
+
95
+ const screenshot = await page.screenshot();
96
+ await vizzlyScreenshot('homepage', screenshot, {
97
+ properties: {
98
+ browser: 'chrome',
99
+ viewport: '1920x1080',
100
+ page: 'home'
101
+ }
102
+ });
103
+ });
104
+ ```
105
+
106
+ ### Cypress
107
+
108
+ ```javascript
109
+ // cypress/support/commands.js
110
+ import { vizzlyScreenshot } from '@vizzly-testing/cli/client';
111
+
112
+ Cypress.Commands.add('vizzlyScreenshot', (name, properties = {}) => {
113
+ cy.screenshot(name, { capture: 'viewport' });
114
+
115
+ cy.readFile(`cypress/screenshots/${name}.png`, 'base64').then((imageBase64) => {
116
+ const imageBuffer = Buffer.from(imageBase64, 'base64');
117
+ return vizzlyScreenshot(name, imageBuffer, {
118
+ properties: {
119
+ browser: Cypress.browser.name,
120
+ framework: 'cypress',
121
+ ...properties
122
+ }
123
+ });
124
+ });
125
+ });
126
+
127
+ // In your test
128
+ describe('Homepage', () => {
129
+ it('should render correctly', () => {
130
+ cy.visit('/');
131
+ cy.vizzlyScreenshot('homepage', {
132
+ page: 'home',
133
+ state: 'logged-out'
134
+ });
135
+ });
136
+ });
137
+ ```
138
+
139
+ ### Puppeteer
140
+
141
+ ```javascript
142
+ import puppeteer from 'puppeteer';
143
+ import { vizzlyScreenshot } from '@vizzly-testing/cli/client';
144
+
145
+ describe('Visual tests', () => {
146
+ test('homepage screenshot', async () => {
147
+ const browser = await puppeteer.launch();
148
+ const page = await browser.newPage();
149
+ await page.goto('/');
150
+
151
+ const screenshot = await page.screenshot();
152
+ await vizzlyScreenshot('homepage', screenshot, {
153
+ properties: {
154
+ browser: 'chrome',
155
+ framework: 'puppeteer'
156
+ }
157
+ });
158
+
159
+ await browser.close();
160
+ });
161
+ });
162
+ ```
163
+
164
+ ## Command Options
165
+
166
+ ### Server Configuration
167
+
168
+ **`--port <port>`** - Server port (default: 47392)
169
+ ```bash
170
+ vizzly run "npm test" --port 3002
171
+ ```
172
+
173
+ **`--timeout <ms>`** - Server timeout in milliseconds (default: 30000)
174
+ ```bash
175
+ vizzly run "npm test" --timeout 60000
176
+ ```
177
+
178
+ ### Build Configuration
179
+
180
+ **`--build-name <name>`** - Custom build name
181
+ ```bash
182
+ vizzly run "npm test" --build-name "PR-123"
183
+ ```
184
+
185
+ **`--environment <env>`** - Environment name (default: "test")
186
+ ```bash
187
+ vizzly run "npm test" --environment "staging"
188
+ ```
189
+
190
+ **`--branch <branch>`** - Git branch override
191
+ ```bash
192
+ vizzly run "npm test" --branch "feature/new-ui"
193
+ ```
194
+
195
+ ### Processing Options
196
+
197
+ **`--wait`** - Wait for build completion
198
+ ```bash
199
+ vizzly run "npm test" --wait
200
+ ```
201
+
202
+ **`--eager`** - Create build immediately (default: lazy)
203
+ ```bash
204
+ vizzly run "npm test" --eager
205
+ ```
206
+
207
+ **`--threshold <number>`** - Comparison threshold (0-1, default: 0.01)
208
+ ```bash
209
+ vizzly run "npm test" --threshold 0.02
210
+ ```
211
+
212
+ ### Development Options
213
+
214
+ **`--tdd`** - Enable TDD mode (see [TDD Mode Guide](./tdd-mode.md))
215
+ ```bash
216
+ vizzly run "npm test" --tdd
217
+ ```
218
+
219
+ **`--allow-no-token`** - Allow running without API token
220
+ ```bash
221
+ vizzly run "npm test" --allow-no-token
222
+ ```
223
+
224
+ **`--token <token>`** - API token override
225
+ ```bash
226
+ vizzly run "npm test" --token "your-token-here"
227
+ ```
228
+
229
+ ### Baseline Configuration
230
+
231
+ **`--baseline-build <id>`** - Use specific build as baseline
232
+ ```bash
233
+ vizzly run "npm test" --baseline-build "build_123"
234
+ ```
235
+
236
+ **`--baseline-comparison <id>`** - Use specific comparison as baseline
237
+ ```bash
238
+ vizzly run "npm test" --baseline-comparison "comp_456"
239
+ ```
240
+
241
+ ## Screenshot Properties
242
+
243
+ The `properties` object in `vizzlyScreenshot()` is flexible and can contain any metadata:
244
+
245
+ ```javascript
246
+ await vizzlyScreenshot('dashboard', screenshot, {
247
+ properties: {
248
+ // Technical metadata
249
+ browser: 'chrome',
250
+ os: 'macos',
251
+ viewport: '1920x1080',
252
+ device: 'desktop',
253
+
254
+ // Organizational metadata
255
+ component: 'dashboard',
256
+ page: 'home',
257
+ feature: 'analytics',
258
+ theme: 'dark',
259
+
260
+ // Test metadata
261
+ testSuite: 'smoke-tests',
262
+ userType: 'admin',
263
+ state: 'logged-in',
264
+
265
+ // Custom metadata
266
+ buildNumber: process.env.BUILD_NUMBER,
267
+ environment: 'staging'
268
+ }
269
+ });
270
+ ```
271
+
272
+ ## CI/CD Integration
273
+
274
+ ### GitHub Actions
275
+
276
+ ```yaml
277
+ name: Visual Tests
278
+ on: [push, pull_request]
279
+
280
+ jobs:
281
+ visual-tests:
282
+ runs-on: ubuntu-latest
283
+ steps:
284
+ - uses: actions/checkout@v4
285
+ - uses: actions/setup-node@v4
286
+ with:
287
+ node-version: '20'
288
+ - run: npm ci
289
+ - run: npx vizzly run "npm test" --wait
290
+ env:
291
+ VIZZLY_TOKEN: ${{ secrets.VIZZLY_TOKEN }}
292
+ ```
293
+
294
+ ### GitLab CI
295
+
296
+ ```yaml
297
+ visual-tests:
298
+ stage: test
299
+ image: node:20
300
+ script:
301
+ - npm ci
302
+ - npx vizzly run "npm test" --wait
303
+ variables:
304
+ VIZZLY_TOKEN: $VIZZLY_TOKEN
305
+ ```
306
+
307
+ ## Advanced Usage
308
+
309
+ ### Conditional Screenshots
310
+
311
+ Only take screenshots when Vizzly is enabled:
312
+
313
+ ```javascript
314
+ import { isVizzlyEnabled, vizzlyScreenshot } from '@vizzly-testing/cli/client';
315
+
316
+ if (isVizzlyEnabled()) {
317
+ const screenshot = await page.screenshot();
318
+ await vizzlyScreenshot('homepage', screenshot);
319
+ }
320
+ ```
321
+
322
+ ### Batch Screenshot Processing
323
+
324
+ Wait for all screenshots to be processed:
325
+
326
+ ```javascript
327
+ import { vizzlyFlush } from '@vizzly-testing/cli/client';
328
+
329
+ // Take multiple screenshots
330
+ await vizzlyScreenshot('page1', screenshot1);
331
+ await vizzlyScreenshot('page2', screenshot2);
332
+ await vizzlyScreenshot('page3', screenshot3);
333
+
334
+ // Wait for all to be processed
335
+ await vizzlyFlush();
336
+ ```
337
+
338
+ ### Custom Configuration
339
+
340
+ Use a custom configuration per test run:
341
+
342
+ ```javascript
343
+ import { configure } from '@vizzly-testing/cli/client';
344
+
345
+ // Configure before taking screenshots
346
+ configure({
347
+ serverUrl: 'http://localhost:3001',
348
+ enabled: true
349
+ });
350
+ ```
351
+
352
+ ## Troubleshooting
353
+
354
+ **Port already in use**
355
+ ```bash
356
+ vizzly run "npm test" --port 3002
357
+ ```
358
+
359
+ **Screenshots not captured**
360
+ - Verify you're calling `vizzlyScreenshot()` in your tests
361
+ - Check that your test framework supports the Buffer API
362
+ - Ensure the image data is valid PNG format
363
+
364
+ **Test command not found**
365
+ - Use absolute paths or ensure commands are in PATH
366
+ - Quote complex commands properly
367
+ - Test your command works independently first
368
+
369
+ **Server timeout**
370
+ - Increase timeout for long-running test suites
371
+ - Check for hanging processes or infinite loops
372
+
373
+ ```bash
374
+ vizzly run "npm test" --timeout 120000 # 2 minutes
375
+ ```
376
+
377
+ ## Best Practices
378
+
379
+ ### Screenshot Naming
380
+ Use descriptive, consistent names:
381
+ ```javascript
382
+ // Good
383
+ await vizzlyScreenshot('homepage-logged-out', screenshot);
384
+ await vizzlyScreenshot('dashboard-admin-view', screenshot);
385
+
386
+ // Avoid
387
+ await vizzlyScreenshot('test1', screenshot);
388
+ await vizzlyScreenshot('screenshot', screenshot);
389
+ ```
390
+
391
+ ### Organizing Tests
392
+ Group related screenshots with properties:
393
+ ```javascript
394
+ await vizzlyScreenshot('user-profile', screenshot, {
395
+ properties: {
396
+ component: 'profile',
397
+ state: 'editing',
398
+ userType: 'admin'
399
+ }
400
+ });
401
+ ```
402
+
403
+ ### Performance
404
+ - Take screenshots only when necessary
405
+ - Use appropriate image sizes
406
+ - Consider screenshot timing in your tests
407
+
408
+ ## Next Steps
409
+
410
+ - Learn about [TDD Mode](./tdd-mode.md) for local development
411
+ - Explore [Upload Command](./upload-command.md) for direct uploads
412
+ - Check the [API Reference](./api-reference.md) for detailed function documentation
@@ -0,0 +1,189 @@
1
+ # Upload Command Guide
2
+
3
+ The `vizzly upload` command is the simplest way to get started with Vizzly. It uploads screenshots directly from a directory without requiring test integration.
4
+
5
+ ## Basic Usage
6
+
7
+ ```bash
8
+ vizzly upload <path>
9
+ ```
10
+
11
+ Upload all screenshots from a directory:
12
+
13
+ ```bash
14
+ vizzly upload ./screenshots
15
+ vizzly upload ./test-results/screenshots
16
+ vizzly upload ./cypress/screenshots
17
+ ```
18
+
19
+ ## Options
20
+
21
+ ### Build Information
22
+
23
+ **`--build-name <name>`** - Custom build name
24
+ ```bash
25
+ vizzly upload ./screenshots --build-name "Release v1.2.3"
26
+ vizzly upload ./screenshots --build-name "PR-456"
27
+ ```
28
+
29
+ **`--environment <env>`** - Environment name (default: "test")
30
+ ```bash
31
+ vizzly upload ./screenshots --environment "staging"
32
+ vizzly upload ./screenshots --environment "production"
33
+ ```
34
+
35
+ ### Git Integration
36
+
37
+ The CLI automatically detects git information, but you can override:
38
+
39
+ **`--branch <branch>`** - Git branch override
40
+ ```bash
41
+ vizzly upload ./screenshots --branch "feature/new-ui"
42
+ ```
43
+
44
+ **`--commit <sha>`** - Git commit SHA override
45
+ ```bash
46
+ vizzly upload ./screenshots --commit "abc123def456"
47
+ ```
48
+
49
+ **`--message <msg>`** - Commit message override
50
+ ```bash
51
+ vizzly upload ./screenshots --message "Fix header layout"
52
+ ```
53
+
54
+ ### Comparison Settings
55
+
56
+ **`--threshold <number>`** - Comparison threshold (0-1, default: 0.01)
57
+ ```bash
58
+ vizzly upload ./screenshots --threshold 0.05 # More tolerant
59
+ vizzly upload ./screenshots --threshold 0.001 # More strict
60
+ ```
61
+
62
+ ### Processing
63
+
64
+ **`--wait`** - Wait for build completion
65
+ ```bash
66
+ vizzly upload ./screenshots --wait
67
+ ```
68
+
69
+ This will:
70
+ - Upload all screenshots
71
+ - Wait for processing to complete
72
+ - Show progress and results
73
+ - Exit with appropriate status code
74
+
75
+ **`--metadata <json>`** - Additional metadata as JSON
76
+ ```bash
77
+ vizzly upload ./screenshots --metadata '{"browser": "chrome", "viewport": "1920x1080"}'
78
+ ```
79
+
80
+ ## Examples
81
+
82
+ ### Basic Upload
83
+ ```bash
84
+ # Simple upload with auto-detected git info
85
+ vizzly upload ./screenshots
86
+ ```
87
+
88
+ ### Release Build
89
+ ```bash
90
+ # Upload with specific build name and wait for results
91
+ vizzly upload ./screenshots \
92
+ --build-name "Release v2.1.0" \
93
+ --environment "production" \
94
+ --wait
95
+ ```
96
+
97
+ ### CI/CD Integration
98
+ ```bash
99
+ # Upload with CI-specific metadata
100
+ vizzly upload ./test-results/screenshots \
101
+ --build-name "CI-Build-${BUILD_NUMBER}" \
102
+ --branch "${GIT_BRANCH}" \
103
+ --commit "${GIT_COMMIT}" \
104
+ --message "${GIT_COMMIT_MESSAGE}" \
105
+ --wait
106
+ ```
107
+
108
+ ### Manual Testing
109
+ ```bash
110
+ # Upload with custom metadata for manual test session
111
+ vizzly upload ./manual-screenshots \
112
+ --build-name "Manual Test Session" \
113
+ --metadata '{"tester": "john.doe", "device": "iPhone 13"}' \
114
+ --environment "staging"
115
+ ```
116
+
117
+ ## File Support
118
+
119
+ The upload command supports:
120
+
121
+ - **PNG files** - Primary format for screenshots
122
+ - **JPG/JPEG files** - Also supported
123
+ - **Recursive directory scanning** - Finds images in subdirectories
124
+ - **Automatic filtering** - Ignores non-image files
125
+
126
+ ## Build Processing
127
+
128
+ When you upload screenshots, Vizzly:
129
+
130
+ 1. **Creates a build** - Groups your screenshots together
131
+ 2. **Finds baselines** - Matches against previous approved screenshots
132
+ 3. **Generates comparisons** - Creates visual diffs for changed screenshots
133
+ 4. **Provides results** - Shows what changed, what's new, what's approved
134
+
135
+ ## Status Codes
136
+
137
+ The upload command exits with different status codes:
138
+
139
+ - **0** - Success (all screenshots approved or no changes)
140
+ - **1** - Changes detected (requires review)
141
+ - **2** - Upload failed or error occurred
142
+
143
+ This makes it perfect for CI/CD pipelines where you want the build to fail if visual changes are detected.
144
+
145
+ ## Common Workflows
146
+
147
+ ### First Time Setup
148
+ ```bash
149
+ # Upload initial baseline screenshots
150
+ vizzly upload ./screenshots --build-name "Initial Baseline"
151
+ ```
152
+
153
+ ### Regular Development
154
+ ```bash
155
+ # Upload after making changes
156
+ vizzly upload ./screenshots --build-name "Feature: New Dashboard"
157
+ ```
158
+
159
+ ### Release Process
160
+ ```bash
161
+ # Upload release candidate screenshots
162
+ vizzly upload ./screenshots \
163
+ --build-name "Release Candidate v2.0" \
164
+ --environment "production" \
165
+ --wait
166
+ ```
167
+
168
+ ## Troubleshooting
169
+
170
+ **No screenshots found**
171
+ - Check the path exists and contains image files
172
+ - Verify file permissions
173
+ - Use absolute paths if relative paths aren't working
174
+
175
+ **Upload failed**
176
+ - Verify your API token is set: `echo $VIZZLY_TOKEN`
177
+ - Check network connectivity
178
+ - Try with `--verbose` for detailed error information
179
+
180
+ **Slow uploads**
181
+ - Large image files take longer to upload
182
+ - Network speed affects upload time
183
+ - Use `--wait` to see progress information
184
+
185
+ ## Next Steps
186
+
187
+ - Learn about [Test Integration](./test-integration.md) for automated screenshot capture
188
+ - Explore [TDD Mode](./tdd-mode.md) for local development
189
+ - Check the [API Reference](./api-reference.md) for programmatic usage
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizzly-testing/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Visual review platform for UI developers and designers",
5
5
  "keywords": [
6
6
  "visual-testing",
@@ -13,10 +13,10 @@
13
13
  "cli"
14
14
  ],
15
15
  "homepage": "https://vizzly.dev",
16
- "bugs": "https://github.com/vizzly/cli/issues",
16
+ "bugs": "https://github.com/vizzly-testing/cli/issues",
17
17
  "repository": {
18
18
  "type": "git",
19
- "url": "https://github.com/vizzly/cli.git"
19
+ "url": "https://github.com/vizzly-testing/cli.git"
20
20
  },
21
21
  "license": "MIT",
22
22
  "author": "Stubborn Mule Software <support@vizzly.dev>",
@@ -47,6 +47,7 @@
47
47
  "files": [
48
48
  "bin",
49
49
  "dist",
50
+ "docs",
50
51
  "README.md",
51
52
  "LICENSE"
52
53
  ],
@@ -72,13 +73,10 @@
72
73
  "registry": "https://registry.npmjs.org/"
73
74
  },
74
75
  "dependencies": {
75
- "@babel/runtime": "^7.23.6",
76
- "@vitejs/plugin-react": "^4.7.0",
77
76
  "commander": "^11.1.0",
78
77
  "cosmiconfig": "^9.0.0",
79
78
  "form-data": "^4.0.0",
80
79
  "glob": "^10.3.10",
81
- "inquirer": "^12.9.1",
82
80
  "odiff-bin": "^3.2.1"
83
81
  },
84
82
  "devDependencies": {