Skip to content

Commit

Permalink
✨ Add support for Nightwatch 2.x (#390)
Browse files Browse the repository at this point in the history
* ✨ Add support for Nightwatch 2.x

This also retains compatibility with Nightwatch 1.x

* ✅ Force headless in CI
  • Loading branch information
Robdel12 committed May 2, 2022
1 parent 4b202cf commit 3338c39
Show file tree
Hide file tree
Showing 4 changed files with 361 additions and 1,091 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
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
},
"scripts": {
"lint": "eslint --ignore-path .gitignore .",
"test": "nightwatch",
"test": "MOZ_HEADLESS=1 nightwatch",
"test:coverage": "nyc yarn test",
"test:types": "tsd"
},
"dependencies": {
"@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 3338c39

Please sign in to comment.