Skip to content

Commit

Permalink
🐛 Fix additional snapshots executing string functions (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wil Wilsman authored Dec 8, 2021
1 parent 19b4909 commit 72734e4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions packages/core/src/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ export default class Page {
}

// execute any javascript
await this.evaluate(typeof execute === 'function'
? execute : execute?.beforeSnapshot);
await this.evaluate(
typeof execute === 'object' && !Array.isArray(execute)
? execute.beforeSnapshot : execute);

// wait for any final network activity before capturing the dom snapshot
await this.network.idle();
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,16 @@ export async function* discoverSnapshotResources(percy, snapshot, callback) {
yield waitForDiscoveryNetworkIdle(page, snapshot.discovery);
handleSnapshotResources(snapshot, resources, callback);
} else {
let { enableJavaScript } = snapshot;

// capture snapshots sequentially
for (let snap of allSnapshots) {
// shallow merge snapshot options
let options = { ...snapshot, ...snap };
// will wait for timeouts, selectors, and additional network activity
let { url, dom } = yield page.snapshot(options);

// handle resources and remove previously captured dom snapshots
let { url, dom } = yield page.snapshot({ enableJavaScript, ...snap });
resources.set(url, createRootResource(url, dom));
handleSnapshotResources(options, resources, callback);
// shallow merge with root snapshot options
handleSnapshotResources({ ...snapshot, ...snap }, resources, callback);
// remove the previously captured dom snapshot
resources.delete(url);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ describe('Snapshot', () => {
execute: () => document.querySelector('p').classList.add('eval-1'),
additionalSnapshots: [
{ suffix: ' 2', execute: () => document.querySelector('p').classList.add('eval-2') },
{ suffix: ' 3', execute: () => document.querySelector('p').classList.add('eval-3') },
{ suffix: ' 3', execute: "document.querySelector('p').classList.add('eval-3')" },
{ suffix: ' 4' }
]
});
Expand Down

0 comments on commit 72734e4

Please sign in to comment.