Skip to content

Commit 8b96272

Browse files
authored
✨ Add support for ignoreStyleSheetSerializationErrors in percySnapshot (#676)
1 parent 5a8f728 commit 8b96272

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,21 @@ function ignoreCanvasSerializationErrors(options) {
109109
false;
110110
}
111111

112+
function ignoreStyleSheetSerializationErrors(options) {
113+
return options?.ignoreStyleSheetSerializationErrors ??
114+
utils.percy?.config?.snapshot?.ignoreStyleSheetSerializationErrors ??
115+
false;
116+
}
117+
112118
async function captureSerializedDOM(driver, options) {
113119
/* istanbul ignore next: no instrumenting injected code */
114120
let { domSnapshot } = await driver.executeScript(options => ({
115121
/* eslint-disable-next-line no-undef */
116122
domSnapshot: PercyDOM.serialize(options)
117123
}), {
118124
...options,
119-
ignoreCanvasSerializationErrors: ignoreCanvasSerializationErrors(options)
125+
ignoreCanvasSerializationErrors: ignoreCanvasSerializationErrors(options),
126+
ignoreStyleSheetSerializationErrors: ignoreStyleSheetSerializationErrors(options)
120127
});
121128

122129
/* istanbul ignore next: no instrumenting injected code */

test/index.test.mjs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,99 @@ describe('percySnapshot', () => {
387387
);
388388
});
389389
});
390+
391+
describe('ignoreStyleSheetSerializationErrors via percySnapshot', () => {
392+
393+
it('should default to false when no options are provided', async () => {
394+
spyOn(driver, 'executeScript').and.returnValue(Promise.resolve({
395+
domSnapshot: { html: '<html></html>', resources: [] }
396+
}));
397+
398+
await percySnapshot(driver, 'Default canvas test');
399+
400+
expect(driver.executeScript).toHaveBeenCalledWith(
401+
jasmine.any(Function),
402+
jasmine.objectContaining({
403+
ignoreStyleSheetSerializationErrors: false
404+
})
405+
);
406+
});
407+
408+
it('should use value from options when provided as true', async () => {
409+
spyOn(driver, 'executeScript').and.returnValue(Promise.resolve({
410+
domSnapshot: { html: '<html></html>', resources: [] }
411+
}));
412+
413+
await percySnapshot(driver, 'Options true test', {
414+
ignoreStyleSheetSerializationErrors: true
415+
});
416+
417+
expect(driver.executeScript).toHaveBeenCalledWith(
418+
jasmine.any(Function),
419+
jasmine.objectContaining({
420+
ignoreStyleSheetSerializationErrors: true
421+
})
422+
);
423+
});
424+
425+
it('should use value from options when provided as false', async () => {
426+
spyOn(driver, 'executeScript').and.returnValue(Promise.resolve({
427+
domSnapshot: { html: '<html></html>', resources: [] }
428+
}));
429+
430+
await percySnapshot(driver, 'Options false test', {
431+
ignoreStyleSheetSerializationErrors: false
432+
});
433+
434+
expect(driver.executeScript).toHaveBeenCalledWith(
435+
jasmine.any(Function),
436+
jasmine.objectContaining({
437+
ignoreStyleSheetSerializationErrors: false
438+
})
439+
);
440+
});
441+
442+
it('should prefer options value over config value', async () => {
443+
utils.percy.config = { snapshot: { ignoreStyleSheetSerializationErrors: true } };
444+
445+
spyOn(driver, 'executeScript').and.returnValue(Promise.resolve({
446+
domSnapshot: { html: '<html></html>', resources: [] }
447+
}));
448+
449+
await percySnapshot(driver, 'Options override test', {
450+
ignoreStyleSheetSerializationErrors: false
451+
});
452+
453+
expect(driver.executeScript).toHaveBeenCalledWith(
454+
jasmine.any(Function),
455+
jasmine.objectContaining({
456+
ignoreStyleSheetSerializationErrors: false
457+
})
458+
);
459+
});
460+
461+
it('should return false when both options and config are undefined', async () => {
462+
utils.percy.config = {
463+
...utils.percy.config,
464+
snapshot: {
465+
...utils.percy.config?.snapshot,
466+
}
467+
};
468+
469+
spyOn(driver, 'executeScript').and.returnValue(Promise.resolve({
470+
domSnapshot: { html: '<html></html>', resources: [] }
471+
}));
472+
473+
await percySnapshot(driver, 'Both undefined test', {});
474+
475+
expect(driver.executeScript).toHaveBeenCalledWith(
476+
jasmine.any(Function),
477+
jasmine.objectContaining({
478+
ignoreStyleSheetSerializationErrors: false
479+
})
480+
);
481+
});
482+
});
390483
});
391484

392485
describe('#slowScrollToBottom', () => {

0 commit comments

Comments
 (0)