Skip to content

Commit

Permalink
✨ Add support for Nightwatch 2.x
Browse files Browse the repository at this point in the history
This also retains compatibility with Nightwatch 1.x
  • Loading branch information
Robdel12 committed Apr 28, 2022
1 parent e990234 commit ada07c1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
geckodriver.log
.nyc_output
logs/
11 changes: 7 additions & 4 deletions commands/percySnapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ module.exports = class PercySnapshotCommand {

// Serialize and capture the DOM
/* istanbul ignore next: no instrumenting injected code */
let { value: { domSnapshot, url } } = (
await this.api.execute(function(options) {
let { domSnapshot, url } = await new Promise((resolve) => {
this.api.execute(function(options) {
return {
/* eslint-disable-next-line no-undef */
domSnapshot: PercyDOM.serialize(options),
url: document.URL
};
}, [options])
);
}, [options], function(result) {
// Check if we're in Nightwatch 1.x (which returns with `.value`)
result.value ? resolve(result.value) : resolve(result);
});
});

// Post the DOM to the snapshot endpoint with snapshot options and other info
await utils.postSnapshot({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@percy/sdk-utils": "^1.0.0"
},
"peerDependencies": {
"nightwatch": "~1"
"nightwatch": ">=1"
},
"devDependencies": {
"@percy/core": "^1.0.0",
Expand Down

0 comments on commit ada07c1

Please sign in to comment.