Skip to content

Commit

Permalink
🐛 Fix multi-dom capture when using the snapshot command (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman authored Oct 6, 2022
1 parent 54fa2c1 commit c13f7d1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ async function* captureSnapshotResources(page, snapshot, options) {
for (let additionalSnapshot of [baseSnapshot, ...additionalSnapshots]) {
let isBaseSnapshot = additionalSnapshot === baseSnapshot;
let snap = { ...baseSnapshot, ...additionalSnapshot };
let width, { widths, execute } = snap;
let { widths, execute } = snap;
let [width] = widths;

// iterate over widths to trigger reqeusts and capture other widths
if (isBaseSnapshot || captureWidths) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export function createSnapshotsQueue(percy) {
if (percy.dryRun) percy.log.info(`Snapshot found: ${name}`, meta);

// immediately flush when uploads are delayed but not skipped
if (percy.delayUploads && !percy.skipUploads) queue.flush();
if (percy.delayUploads && !percy.deferUploads) queue.flush();
// overwrite any existing snapshot when not deferred or when resources is a function
if (!percy.deferUploads || typeof snapshot.resources === 'function') return snapshot;
// merge snapshot options when uploads are deferred
Expand Down
15 changes: 14 additions & 1 deletion packages/core/test/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@ describe('Snapshot', () => {
// stop and recreate a percy instance with the desired option
await percy.stop(true);
await api.mock();
logger.reset();

testDOM = `
<p id="test"></p>
Expand All @@ -379,7 +380,10 @@ describe('Snapshot', () => {

percy = await Percy.start({
token: 'PERCY_TOKEN',
deferUploads: true
deferUploads: true,
loglevel: 'debug',
// delay should do nothing
delayUploads: true
});

percy.snapshot({
Expand All @@ -397,6 +401,15 @@ describe('Snapshot', () => {

await percy.stop();

expect(logger.stderr).toEqual(jasmine.arrayContaining([
'[percy:core:page] Taking snapshot: Snapshot 0 @600px',
'[percy:core:page] Taking snapshot: Snapshot 0 @1000px',
'[percy:core:page] Taking snapshot: Snapshot 0 @1600px',
'[percy:core:page] Taking snapshot: Snapshot 1 @600px',
'[percy:core:page] Taking snapshot: Snapshot 1 @1000px',
'[percy:core:page] Taking snapshot: Snapshot 1 @1600px'
]));

// snapshots uploaded after stopping
expect(api.requests['/builds/123/snapshots']).toHaveSize(2);

Expand Down

0 comments on commit c13f7d1

Please sign in to comment.