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 May 2, 2022
1 parent 4b202cf commit b630c89
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 1,090 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
4 changes: 2 additions & 2 deletions 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 All @@ -43,7 +43,7 @@
"expect": "^27.0.2",
"geckodriver": "^3.0.1",
"mocha": "^10.0.0",
"nightwatch": "^1.5.1",
"nightwatch": "^2.1.3",
"nyc": "^15.1.0",
"tsd": "^0.20.0"
}
Expand Down
Loading

0 comments on commit b630c89

Please sign in to comment.