Skip to content

Commit d8187eb

Browse files
committed
🐛 Gracefully handle errors in vizzlyScreenshot
- Add VizzlyDiffError class for intentional test failures - Only re-throw VizzlyDiffError (when failOnDiff is true) - All other errors (network, parsing, etc.) log a warning and skip - Never break user's test suite due to Vizzly connectivity issues
1 parent a3e895c commit d8187eb

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

clients/ember/src/test-support/index.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,24 @@
2424
* });
2525
*/
2626

27+
/**
28+
* Custom error class for intentional visual diff failures.
29+
* Only this error type will be re-thrown to fail tests.
30+
*
31+
* Note: Unlike the core SDK which auto-disables on errors, the Ember client
32+
* returns a skipped result instead. This is intentional - Ember tests often
33+
* run in partitions/parallel where auto-disabling would affect other tests.
34+
*/
35+
class VizzlyDiffError extends Error {
36+
constructor(message) {
37+
super(message);
38+
this.name = 'VizzlyDiffError';
39+
if (Error.captureStackTrace) {
40+
Error.captureStackTrace(this, VizzlyDiffError);
41+
}
42+
}
43+
}
44+
2745
/**
2846
* Detect browser type from user agent
2947
* @returns {string} Browser type: chromium, firefox, or webkit
@@ -278,7 +296,7 @@ export async function vizzlyScreenshot(name, options = {}) {
278296
let shouldFail = failOnDiff !== null ? failOnDiff : shouldFailOnDiff();
279297

280298
if (shouldFail) {
281-
throw new Error(
299+
throw new VizzlyDiffError(
282300
`Visual difference detected for '${name}' (${result.diffPercentage?.toFixed(2)}% diff). ` +
283301
`View diff in Vizzly dashboard.`
284302
);
@@ -289,6 +307,15 @@ export async function vizzlyScreenshot(name, options = {}) {
289307
}
290308

291309
return result;
310+
} catch (error) {
311+
// Only re-throw intentional diff failures - everything else should skip gracefully
312+
// We never want to break the user's test suite due to Vizzly issues
313+
if (error instanceof VizzlyDiffError) {
314+
throw error;
315+
}
316+
// Log the error for debugging but don't fail the test
317+
console.warn(`[vizzly] Screenshot skipped due to error: ${error.message}`);
318+
return { status: 'skipped', reason: 'error', error: error.message };
292319
} finally {
293320
// Always restore original styles
294321
cleanup();

0 commit comments

Comments
 (0)