Skip to content

Commit 507cd47

Browse files
authored
⚡ Add explicit type field to all SDK clients (#175)
## Summary Adds the `type` field to all SDK clients that send screenshot image data. This completes the performance optimization from #174 by ensuring all clients benefit from O(1) type detection on the server. ## Changes | SDK | File | Type Sent | |-----|------|-----------| | Full SDK | `src/sdk/index.js` | `type: 'base64'` | | Vitest | `clients/vitest/src/setup.js` | `type: 'file-path'` | | Ruby | `clients/ruby/lib/vizzly.rb` | `type: 'base64'` | | Swift | `clients/swift/.../VizzlyClient.swift` | `type: 'base64'` | **No changes needed:** - **Core client** (`src/client/index.js`) - Already updated in #174 - **Static-site** - Uses core client SDK - **Storybook** - Uses core client SDK - **Ember** - Different architecture (sends selector, server takes screenshot) ## Packages to Release After merging, the following packages need new releases: | Package | Registry | Notes | |---------|----------|-------| | `@vizzly-testing/cli` | npm | Main CLI package | | `@vizzly-testing/vitest` | npm | Vitest plugin | | `vizzly` | RubyGems | Ruby gem | | `Vizzly` | Swift Package Manager | Swift package | ## Test Plan - [x] All 1751 tests pass - [x] Backwards compatible (server falls back to detection if `type` missing)
1 parent 235dd65 commit 507cd47

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

clients/ruby/lib/vizzly.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def screenshot(name, image_data, options = {})
5555
payload = {
5656
name: name,
5757
image: image_base64,
58+
type: 'base64',
5859
buildId: ENV.fetch('VIZZLY_BUILD_ID', nil),
5960
threshold: options[:threshold] || 0,
6061
fullPage: options[:full_page] || false,

clients/ruby/test/integration_test.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def test_screenshot_with_running_server
3939
result = Vizzly.screenshot('test-screenshot', image_data,
4040
properties: { browser: 'chrome', viewport: { width: 1920, height: 1080 } })
4141

42-
assert result
43-
assert_equal true, result['success']
42+
assert result, 'Expected result to be non-nil'
43+
# TDD mode returns status: 'new' for first screenshot, 'match' for subsequent
44+
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
4445
end
4546

4647
def test_screenshot_with_auto_discovery
@@ -57,8 +58,9 @@ def test_screenshot_with_auto_discovery
5758
image_data = create_test_png
5859
result = client.screenshot('auto-discovered', image_data)
5960

60-
assert result
61-
assert_equal true, result['success']
61+
assert result, 'Expected result to be non-nil'
62+
# TDD mode returns status: 'new' for first screenshot, 'match' for subsequent
63+
assert %w[new match].include?(result['status']), "Expected status 'new' or 'match', got: #{result['status']}"
6264
end
6365

6466
private

clients/swift/Sources/Vizzly/VizzlyClient.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public final class VizzlyClient {
7979
var payload: [String: Any] = [
8080
"name": name,
8181
"image": imageBase64,
82+
"type": "base64",
8283
"threshold": threshold,
8384
"fullPage": fullPage
8485
]

clients/vitest/src/setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ async function toMatchScreenshot(element, name, options = {}) {
6060
body: JSON.stringify({
6161
name: screenshotName,
6262
image: screenshotPath, // Send file path directly
63+
type: 'file-path',
6364
buildId: buildId || null,
6465
threshold,
6566
fullPage,

src/sdk/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export class VizzlySDK extends EventEmitter {
252252
buildId,
253253
name,
254254
image: imageBase64,
255+
type: 'base64',
255256
properties: options.properties || {},
256257
};
257258

0 commit comments

Comments
 (0)