From ada07c19dd956e88f12277e402c9860f50eab245 Mon Sep 17 00:00:00 2001 From: Robert DeLuca Date: Thu, 28 Apr 2022 17:25:34 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20Nightwatch=20?= =?UTF-8?q?2.x?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also retains compatibility with Nightwatch 1.x --- .gitignore | 1 + commands/percySnapshot.js | 11 +++++++---- package.json | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index ec1fc5d..01eabac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules geckodriver.log .nyc_output +logs/ diff --git a/commands/percySnapshot.js b/commands/percySnapshot.js index 391551b..20b9f36 100644 --- a/commands/percySnapshot.js +++ b/commands/percySnapshot.js @@ -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({ diff --git a/package.json b/package.json index ca64ac9..8d4058d 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@percy/sdk-utils": "^1.0.0" }, "peerDependencies": { - "nightwatch": "~1" + "nightwatch": ">=1" }, "devDependencies": { "@percy/core": "^1.0.0",