@percy/nightwatch 2.1.0 → 2.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +209 -139
- package/commands/percySnapshot.js +50 -22
- package/lib/regions.js +59 -0
- package/lib/snapshot.js +361 -0
- package/package.json +17 -14
- package/types/percySnapshot.d.ts +64 -1
package/README.md
CHANGED
|
@@ -1,139 +1,209 @@
|
|
|
1
|
-
# @percy/nightwatch
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@percy/nightwatch)
|
|
4
|
-

|
|
5
|
-
|
|
6
|
-
[Percy](https://percy.io) visual testing for [Nightwatch.js](http://nightwatchjs.org).
|
|
7
|
-
|
|
8
|
-
## Installation
|
|
9
|
-
|
|
10
|
-
```sh-session
|
|
11
|
-
$ npm install --save-dev @percy/cli @percy/nightwatch
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
### Nightwatch configuration
|
|
15
|
-
|
|
16
|
-
Add the path exported by `@percy/nightwatch` to your Nightwatch configuration's
|
|
17
|
-
`custom_commands_path` property.
|
|
18
|
-
|
|
19
|
-
```javascript
|
|
20
|
-
const percy = require('@percy/nightwatch');
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
// ...
|
|
24
|
-
custom_commands_path: [percy.path],
|
|
25
|
-
// ...
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Usage
|
|
30
|
-
|
|
31
|
-
This is an example test using the `browser.percySnapshot()` command. For other examples of how to
|
|
32
|
-
write Nightwatch tests, check out [the official Nightwatch
|
|
33
|
-
guides](https://nightwatchjs.org/guide/using-nightwatch/writing-tests.html).
|
|
34
|
-
|
|
35
|
-
```javascript
|
|
36
|
-
module.exports = {
|
|
37
|
-
|
|
38
|
-
browser
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[percy]
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
[
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
- `
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
1
|
+
# @percy/nightwatch
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@percy/nightwatch)
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
[Percy](https://percy.io) visual testing for [Nightwatch.js](http://nightwatchjs.org).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh-session
|
|
11
|
+
$ npm install --save-dev @percy/cli @percy/nightwatch
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Nightwatch configuration
|
|
15
|
+
|
|
16
|
+
Add the path exported by `@percy/nightwatch` to your Nightwatch configuration's
|
|
17
|
+
`custom_commands_path` property.
|
|
18
|
+
|
|
19
|
+
```javascript
|
|
20
|
+
const percy = require('@percy/nightwatch');
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
// ...
|
|
24
|
+
custom_commands_path: [percy.path],
|
|
25
|
+
// ...
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
This is an example test using the `browser.percySnapshot()` command. For other examples of how to
|
|
32
|
+
write Nightwatch tests, check out [the official Nightwatch
|
|
33
|
+
guides](https://nightwatchjs.org/guide/using-nightwatch/writing-tests.html).
|
|
34
|
+
|
|
35
|
+
```javascript
|
|
36
|
+
module.exports = {
|
|
37
|
+
"Snapshots pages": function (browser) {
|
|
38
|
+
browser.url("http://example.com").assert.containsText("h1", "Example Domain").percySnapshot("Example snapshot");
|
|
39
|
+
browser.url("http://google.com").assert.elementPresent('img[alt="Google"]').percySnapshot("Google homepage");
|
|
40
|
+
browser.end();
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Running the test above directly will result in the following logs:
|
|
46
|
+
|
|
47
|
+
```sh-session
|
|
48
|
+
$ nightwatch
|
|
49
|
+
|
|
50
|
+
[Example] Test Suite
|
|
51
|
+
====================
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
Running: Snapshots pages
|
|
55
|
+
|
|
56
|
+
✔ Testing if element <h1> contains text 'Example Domain'
|
|
57
|
+
[percy] Percy is not running, disabling snapshots
|
|
58
|
+
✔ Testing if element <img[alt="Google"]> is present
|
|
59
|
+
|
|
60
|
+
OK. 2 assertions passed.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
When running with [`percy
|
|
64
|
+
exec`](https://github.com/percy/cli/tree/master/packages/cli-exec#percy-exec), and your project's
|
|
65
|
+
`PERCY_TOKEN`, a new Percy build will be created and snapshots will be uploaded to your project.
|
|
66
|
+
|
|
67
|
+
```sh-session
|
|
68
|
+
$ export PERCY_TOKEN=[your-project-token]
|
|
69
|
+
$ percy exec -- nightwatch
|
|
70
|
+
[percy] Percy has started!
|
|
71
|
+
[percy] Created build #1: https://percy.io/[your-project]
|
|
72
|
+
[percy] Running "nightwatch"
|
|
73
|
+
|
|
74
|
+
[Example] Test Suite
|
|
75
|
+
====================
|
|
76
|
+
...
|
|
77
|
+
|
|
78
|
+
Running: Snapshots pages
|
|
79
|
+
|
|
80
|
+
✔ Testing if element <h1> contains text 'Example Domain'
|
|
81
|
+
[percy] Snapshot taken "Snapshots pages"
|
|
82
|
+
✔ Testing if element <img[alt="Google"]> is present
|
|
83
|
+
[percy] Snapshot taken "Google homepage"
|
|
84
|
+
|
|
85
|
+
OK. 2 assertions passed.
|
|
86
|
+
[percy] Stopping percy...
|
|
87
|
+
[percy] Finalized build #1: https://percy.io/[your-project]
|
|
88
|
+
[percy] Done!
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
|
|
93
|
+
`percySnapshot([name][, options])`
|
|
94
|
+
|
|
95
|
+
- `name` - The snapshot name; must be unique to each snapshot
|
|
96
|
+
- `options` - [See per-snapshot configuration options](https://www.browserstack.com/docs/percy/take-percy-snapshots/overview#per-snapshot-configuration)
|
|
97
|
+
|
|
98
|
+
### Responsive snapshots
|
|
99
|
+
|
|
100
|
+
Set `responsiveSnapshotCapture: true` (and optionally `widths`) to have the Nightwatch SDK resize the browser window and capture DOM snapshots at multiple breakpoints in a single Percy snapshot. The SDK implementation:
|
|
101
|
+
|
|
102
|
+
- Calling `PercyDOM.waitForResize()` once and waiting on `window.resizeCount` before each snapshot.
|
|
103
|
+
- Using Chrome DevTools Protocol resizing when available (disable with `PERCY_DISABLE_CDP_RESIZE=true`) and falling back to WebDriver window APIs.
|
|
104
|
+
- Honoring the environment toggles:
|
|
105
|
+
- `PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT` – ensure a minimum viewport height using `snapshot.minHeight`.
|
|
106
|
+
- `PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE` – reload the page (and re-inject Percy DOM) between widths.
|
|
107
|
+
- `RESPONSIVE_CAPTURE_SLEEP_TIME` – wait (in seconds) between width changes.
|
|
108
|
+
- `PERCY_ENABLE_LAZY_LOADING_SCROLL` – trigger the lazy-load scroll helper described below.
|
|
109
|
+
- Resetting the window back to its original dimensions after the final width.
|
|
110
|
+
|
|
111
|
+
### Lazy-loading scroll helper
|
|
112
|
+
|
|
113
|
+
When `PERCY_ENABLE_LAZY_LOADING_SCROLL` is set the SDK scrolls the page in increments (up to 25,000px) to trigger lazy-loaded content before each snapshot. Additional environment variables control the behavior:
|
|
114
|
+
|
|
115
|
+
- `PERCY_LAZY_LOAD_SCROLL_TIME` – seconds to pause between scroll steps (default `0.45`).
|
|
116
|
+
- `BYPASS_SCROLL_TO_TOP=true` – skip scrolling back to the top of the page.
|
|
117
|
+
- `PERCY_SLEEP_AFTER_LAZY_LOAD_COMPLETE` – seconds to wait after finishing the scroll sequence.
|
|
118
|
+
|
|
119
|
+
### Running tests
|
|
120
|
+
|
|
121
|
+
All unit and Nightwatch integration tests can be executed with:
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
yarn test
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Additional scripts are available when iterating locally:
|
|
128
|
+
|
|
129
|
+
- `yarn test:unit` — runs the mocha suite under `test/unit/**`.
|
|
130
|
+
- `yarn test:nightwatch` — runs the Nightwatch suite (wrapped by `percy exec`) in headless Firefox.
|
|
131
|
+
|
|
132
|
+
### E2E Visual Testing
|
|
133
|
+
|
|
134
|
+
The repository includes comprehensive end-to-end (E2E) visual regression tests that create actual Percy builds and validate all SDK features. These tests use real HTML fixtures and test scenarios to ensure the SDK works correctly.
|
|
135
|
+
|
|
136
|
+
**Running E2E tests locally:**
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
# Terminal 1 - Start test server
|
|
140
|
+
yarn e2e:server
|
|
141
|
+
|
|
142
|
+
# Terminal 2 - Run tests with Percy
|
|
143
|
+
PERCY_TOKEN=your_token yarn e2e:chrome # Chrome (with CDP)
|
|
144
|
+
PERCY_TOKEN=your_token yarn e2e:firefox # Firefox (WebDriver)
|
|
145
|
+
|
|
146
|
+
# Or run everything in one command
|
|
147
|
+
PERCY_TOKEN=your_token yarn e2e:local
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**What's tested:**
|
|
151
|
+
- ✅ Responsive snapshots with multiple widths (CDP + WebDriver fallbacks)
|
|
152
|
+
- ✅ Lazy loading with scroll helper
|
|
153
|
+
- ✅ Canvas and stylesheet serialization
|
|
154
|
+
- ✅ Region algorithms (ignore, standard, layout, intelliignore)
|
|
155
|
+
- ✅ Percy CSS, scope selectors, and DOM transformation
|
|
156
|
+
- ✅ Cookie capture and attachment
|
|
157
|
+
- ✅ Shadow DOM serialization
|
|
158
|
+
- ✅ Complex real-world integration scenarios
|
|
159
|
+
|
|
160
|
+
**E2E test structure:**
|
|
161
|
+
- `test/e2e/fixtures/` - 7 comprehensive HTML test pages
|
|
162
|
+
- `test/e2e/e2e.test.js` - 13 optimized test scenarios covering all features
|
|
163
|
+
- `test/e2e/server.js` - Static file server for fixtures
|
|
164
|
+
- `test/e2e/nightwatch.e2e.conf.js` - E2E-specific configuration
|
|
165
|
+
|
|
166
|
+
**Snapshot count:**
|
|
167
|
+
- PRs: ~25-30 snapshots (Chrome only, optimized for quick review)
|
|
168
|
+
- Main branch: ~75-90 snapshots (Chrome + Firefox + environment tests)
|
|
169
|
+
|
|
170
|
+
See [`test/e2e/README.md`](test/e2e/README.md) for detailed documentation, environment variables, and troubleshooting.
|
|
171
|
+
|
|
172
|
+
**CI/CD:** E2E tests run automatically on pull requests (Chrome) and main branch pushes (Chrome + Firefox) via GitHub Actions (`.github/workflows/e2e-percy.yml`).
|
|
173
|
+
|
|
174
|
+
## Upgrading
|
|
175
|
+
|
|
176
|
+
### Automatically with `@percy/migrate`
|
|
177
|
+
|
|
178
|
+
We built a tool to help automate migrating to the new CLI toolchain! Migrating
|
|
179
|
+
can be done by running the following commands and following the prompts:
|
|
180
|
+
|
|
181
|
+
```shell
|
|
182
|
+
$ npx @percy/migrate
|
|
183
|
+
? Are you currently using @percy/nightwatch? Yes
|
|
184
|
+
? Install @percy/cli (required to run percy)? Yes
|
|
185
|
+
? Migrate Percy config file? Yes
|
|
186
|
+
? Upgrade SDK to @percy/nightwatch@2.0.0? Yes
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This will automatically run the changes described below for you.
|
|
190
|
+
|
|
191
|
+
### Manually
|
|
192
|
+
|
|
193
|
+
#### Installing `@percy/cli`
|
|
194
|
+
|
|
195
|
+
If you're coming from a pre-2.0 version of this package, make sure to install `@percy/cli` after
|
|
196
|
+
upgrading to retain any existing scripts that reference the Percy CLI command.
|
|
197
|
+
|
|
198
|
+
```sh-session
|
|
199
|
+
$ npm install --save-dev @percy/cli
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### Migrating Config
|
|
203
|
+
|
|
204
|
+
If you have a previous Percy configuration file, migrate it to the newest version with the
|
|
205
|
+
[`config:migrate`](https://github.com/percy/cli/tree/master/packages/cli-config#percy-configmigrate-filepath-output) command:
|
|
206
|
+
|
|
207
|
+
```sh-session
|
|
208
|
+
$ percy config:migrate
|
|
209
|
+
```
|
|
@@ -1,52 +1,80 @@
|
|
|
1
1
|
// Collect client and environment information
|
|
2
2
|
const sdkPkg = require('../package.json');
|
|
3
3
|
const nightwatchPkg = require('nightwatch/package.json');
|
|
4
|
+
const { captureDOM } = require('../lib/snapshot');
|
|
5
|
+
const { createRegion } = require('../lib/regions');
|
|
4
6
|
const CLIENT_INFO = `${sdkPkg.name}/${sdkPkg.version}`;
|
|
5
7
|
const ENV_INFO = `${nightwatchPkg.name}/${nightwatchPkg.version}`;
|
|
8
|
+
const NOT_RUNNING_ERROR = 'Percy is not running, disabling snapshots.';
|
|
9
|
+
const AUTOMATE_ERROR = 'Invalid function call - percySnapshot(). Please use percyScreenshot() function while using Percy with Automate. For more information on usage of percyScreenshot, refer https://www.browserstack.com/docs/percy/integrate/functional-and-visual';
|
|
6
10
|
|
|
7
11
|
// Take a DOM snapshot and post it to the snapshot endpoint
|
|
12
|
+
function injectPercyDOM(browser, domScript) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
browser.execute(domScript, [], (result) => {
|
|
15
|
+
if (result && result.status && result.status !== 0 && result.error) {
|
|
16
|
+
return reject(result.error);
|
|
17
|
+
}
|
|
18
|
+
resolve();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
8
23
|
module.exports = class PercySnapshotCommand {
|
|
9
|
-
async command(name, options) {
|
|
24
|
+
async command(name, options = {}) {
|
|
10
25
|
let utils = await import('@percy/sdk-utils');
|
|
11
|
-
|
|
12
|
-
if (!(await utils.isPercyEnabled())) return;
|
|
13
26
|
name = name || this.api.currentTest.name;
|
|
14
27
|
let log = utils.logger('nightwatch');
|
|
15
28
|
|
|
29
|
+
if (!(await utils.isPercyEnabled())) {
|
|
30
|
+
if (process.env.PERCY_RAISE_ERROR === 'true') {
|
|
31
|
+
throw new Error(NOT_RUNNING_ERROR);
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (utils.percy?.type === 'automate') {
|
|
37
|
+
throw new Error(AUTOMATE_ERROR);
|
|
38
|
+
}
|
|
39
|
+
|
|
16
40
|
try {
|
|
41
|
+
let domScript = await utils.fetchPercyDOM();
|
|
42
|
+
|
|
17
43
|
// Inject the DOM serialization script
|
|
18
|
-
await this.api
|
|
44
|
+
await injectPercyDOM(this.api, domScript);
|
|
19
45
|
|
|
20
46
|
// Serialize and capture the DOM
|
|
21
|
-
|
|
22
|
-
let { domSnapshot, url } = await new Promise((resolve) => {
|
|
23
|
-
this.api.execute(function(options) {
|
|
24
|
-
return {
|
|
25
|
-
/* eslint-disable-next-line no-undef */
|
|
26
|
-
domSnapshot: PercyDOM.serialize(options),
|
|
27
|
-
url: document.URL
|
|
28
|
-
};
|
|
29
|
-
}, [options], function(result) {
|
|
30
|
-
// Check if we're in Nightwatch 1.x (which returns with `.value`)
|
|
31
|
-
result.value ? resolve(result.value) : resolve(result);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
47
|
+
let { domSnapshot, url } = await captureDOM(this.api, options, utils, log, domScript);
|
|
34
48
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
49
|
+
// Filter out DOM-only serialization options that shouldn't be posted to Percy
|
|
50
|
+
const {
|
|
51
|
+
ignoreCanvasSerializationErrors,
|
|
52
|
+
ignoreStyleSheetSerializationErrors,
|
|
53
|
+
...snapshotOptions
|
|
54
|
+
} = options;
|
|
55
|
+
|
|
56
|
+
const postData = {
|
|
57
|
+
...snapshotOptions,
|
|
58
|
+
domSnapshot,
|
|
38
59
|
environmentInfo: ENV_INFO,
|
|
39
60
|
clientInfo: CLIENT_INFO,
|
|
40
|
-
domSnapshot,
|
|
41
61
|
name,
|
|
42
62
|
url
|
|
43
|
-
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Post the DOM to the snapshot endpoint with snapshot options and other info
|
|
66
|
+
await utils.postSnapshot(postData);
|
|
44
67
|
} catch (error) {
|
|
45
68
|
// Handle errors
|
|
46
69
|
log.error(`Could not take DOM snapshot "${name}"`);
|
|
47
70
|
log.error(error);
|
|
71
|
+
|
|
72
|
+
if (process.env.PERCY_RAISE_ERROR === 'true') {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
48
75
|
}
|
|
49
76
|
}
|
|
50
77
|
};
|
|
51
78
|
|
|
79
|
+
module.exports.createRegion = createRegion;
|
|
52
80
|
module.exports.path = __dirname;
|
package/lib/regions.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const AVAILABLE_ALGORITHMS = ['standard', 'layout', 'ignore', 'intelliignore'];
|
|
2
|
+
|
|
3
|
+
function createRegion({
|
|
4
|
+
boundingBox = null,
|
|
5
|
+
elementXpath = null,
|
|
6
|
+
elementCSS = null,
|
|
7
|
+
padding = null,
|
|
8
|
+
algorithm = 'ignore',
|
|
9
|
+
diffSensitivity = null,
|
|
10
|
+
imageIgnoreThreshold = null,
|
|
11
|
+
carouselsEnabled = null,
|
|
12
|
+
bannersEnabled = null,
|
|
13
|
+
adsEnabled = null,
|
|
14
|
+
diffIgnoreThreshold = null
|
|
15
|
+
} = {}) {
|
|
16
|
+
if (!AVAILABLE_ALGORITHMS.includes(algorithm)) {
|
|
17
|
+
throw new Error(`Invalid algorithm "${algorithm}". Expected one of: ${AVAILABLE_ALGORITHMS.join(', ')}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const elementSelector = {};
|
|
21
|
+
if (boundingBox) elementSelector.boundingBox = boundingBox;
|
|
22
|
+
if (elementXpath) elementSelector.elementXpath = elementXpath;
|
|
23
|
+
if (elementCSS) elementSelector.elementCSS = elementCSS;
|
|
24
|
+
|
|
25
|
+
const region = { algorithm };
|
|
26
|
+
if (Object.keys(elementSelector).length > 0) {
|
|
27
|
+
region.elementSelector = elementSelector;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (padding) {
|
|
31
|
+
region.padding = padding;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const configuration = {};
|
|
35
|
+
if (['standard', 'intelliignore'].includes(algorithm)) {
|
|
36
|
+
if (diffSensitivity !== null) configuration.diffSensitivity = diffSensitivity;
|
|
37
|
+
if (imageIgnoreThreshold !== null) configuration.imageIgnoreThreshold = imageIgnoreThreshold;
|
|
38
|
+
if (carouselsEnabled !== null) configuration.carouselsEnabled = carouselsEnabled;
|
|
39
|
+
if (bannersEnabled !== null) configuration.bannersEnabled = bannersEnabled;
|
|
40
|
+
if (adsEnabled !== null) configuration.adsEnabled = adsEnabled;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (Object.keys(configuration).length > 0) {
|
|
44
|
+
region.configuration = configuration;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const assertion = {};
|
|
48
|
+
if (diffIgnoreThreshold !== null) assertion.diffIgnoreThreshold = diffIgnoreThreshold;
|
|
49
|
+
|
|
50
|
+
if (Object.keys(assertion).length > 0) {
|
|
51
|
+
region.assertion = assertion;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return region;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
createRegion
|
|
59
|
+
};
|
package/lib/snapshot.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
const CS_MAX_SCREENSHOT_LIMIT = 25000;
|
|
2
|
+
const SCROLL_DEFAULT_SLEEP_TIME = 0.45; // 450ms
|
|
3
|
+
|
|
4
|
+
function ignoreCanvasSerializationErrors(options = {}, utils) {
|
|
5
|
+
return options?.ignoreCanvasSerializationErrors ??
|
|
6
|
+
utils?.percy?.config?.snapshot?.ignoreCanvasSerializationErrors ??
|
|
7
|
+
false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function ignoreStyleSheetSerializationErrors(options = {}, utils) {
|
|
11
|
+
return options?.ignoreStyleSheetSerializationErrors ??
|
|
12
|
+
utils?.percy?.config?.snapshot?.ignoreStyleSheetSerializationErrors ??
|
|
13
|
+
false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function unwrapResult(result) {
|
|
17
|
+
if (!result) return result;
|
|
18
|
+
if (typeof result === 'object' && 'value' in result && result.value !== undefined) {
|
|
19
|
+
return result.value;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function sleep(ms) {
|
|
25
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function executeScript(browser, fn, args = []) {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
try {
|
|
31
|
+
browser.execute(fn, args, result => {
|
|
32
|
+
let value = unwrapResult(result);
|
|
33
|
+
if (result && result.status && result.status !== 0 && result.error) {
|
|
34
|
+
return reject(result.error);
|
|
35
|
+
}
|
|
36
|
+
resolve(value);
|
|
37
|
+
});
|
|
38
|
+
} catch (error) {
|
|
39
|
+
reject(error);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getCookies(browser) {
|
|
45
|
+
if (typeof browser.getCookies !== 'function') return Promise.resolve([]);
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
try {
|
|
48
|
+
browser.getCookies(result => {
|
|
49
|
+
if (result && result.status && result.status !== 0 && result.error) {
|
|
50
|
+
return reject(result.error);
|
|
51
|
+
}
|
|
52
|
+
resolve(Array.isArray(result?.value) ? result.value : (result?.value || []));
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
reject(error);
|
|
56
|
+
}
|
|
57
|
+
}).catch(() => []);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function captureSerializedDOM(browser, options = {}, utils) {
|
|
61
|
+
const serializeOptions = {
|
|
62
|
+
...options,
|
|
63
|
+
ignoreCanvasSerializationErrors: ignoreCanvasSerializationErrors(options, utils),
|
|
64
|
+
ignoreStyleSheetSerializationErrors: ignoreStyleSheetSerializationErrors(options, utils)
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
let { domSnapshot, url } = await executeScript(browser, function(opts) {
|
|
68
|
+
return {
|
|
69
|
+
/* eslint-disable-next-line no-undef */
|
|
70
|
+
domSnapshot: PercyDOM.serialize(opts),
|
|
71
|
+
url: document.URL
|
|
72
|
+
};
|
|
73
|
+
}, [serializeOptions]);
|
|
74
|
+
|
|
75
|
+
if (!domSnapshot) domSnapshot = {};
|
|
76
|
+
domSnapshot.cookies = await getCookies(browser);
|
|
77
|
+
|
|
78
|
+
return { domSnapshot, url };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isResponsiveOptionEnabled(options = {}, utils) {
|
|
82
|
+
if (utils?.percy?.config?.percy?.deferUploads) return false;
|
|
83
|
+
|
|
84
|
+
if (Object.prototype.hasOwnProperty.call(options, 'responsiveSnapshotCapture')) {
|
|
85
|
+
return Boolean(options.responsiveSnapshotCapture);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (Object.prototype.hasOwnProperty.call(options, 'responsive_snapshot_capture')) {
|
|
89
|
+
return Boolean(options.responsive_snapshot_capture);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return Boolean(utils?.percy?.config?.snapshot?.responsiveSnapshotCapture);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function getWidthsForMultiDOM(userPassedWidths = [], eligibleWidths = {}) {
|
|
96
|
+
let widths = [];
|
|
97
|
+
|
|
98
|
+
if (eligibleWidths?.mobile?.length) widths = widths.concat(eligibleWidths.mobile);
|
|
99
|
+
|
|
100
|
+
if (userPassedWidths.length) {
|
|
101
|
+
widths = widths.concat(userPassedWidths);
|
|
102
|
+
} else if (eligibleWidths?.config?.length) {
|
|
103
|
+
widths = widths.concat(eligibleWidths.config);
|
|
104
|
+
} else if (Array.isArray(eligibleWidths)) {
|
|
105
|
+
widths = widths.concat(eligibleWidths);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return [...new Set(widths)].filter(width => !!width);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function promisifyBrowserCommand(browser, command, ...args) {
|
|
112
|
+
if (typeof browser[command] !== 'function') return Promise.resolve();
|
|
113
|
+
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
try {
|
|
116
|
+
browser[command](...args, result => {
|
|
117
|
+
if (result && result.status && result.status !== 0 && result.error) {
|
|
118
|
+
return reject(result.error);
|
|
119
|
+
}
|
|
120
|
+
resolve(unwrapResult(result));
|
|
121
|
+
});
|
|
122
|
+
} catch (error) {
|
|
123
|
+
reject(error);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function getWindowRect(browser) {
|
|
129
|
+
let rect = await executeScript(browser, function() {
|
|
130
|
+
return { width: window.innerWidth, height: window.innerHeight };
|
|
131
|
+
}) || {};
|
|
132
|
+
|
|
133
|
+
if (typeof rect.width !== 'number' || Number.isNaN(rect.width)) rect.width = 1280;
|
|
134
|
+
if (typeof rect.height !== 'number' || Number.isNaN(rect.height)) rect.height = 720;
|
|
135
|
+
return rect;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async function setWindowRect(browser, { width, height }) {
|
|
139
|
+
const rect = { width, height };
|
|
140
|
+
if (typeof browser.setWindowRect === 'function') {
|
|
141
|
+
return await promisifyBrowserCommand(browser, 'setWindowRect', rect);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (typeof browser.setWindowSize === 'function') {
|
|
145
|
+
return await promisifyBrowserCommand(browser, 'setWindowSize', width, height);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if (typeof browser.resizeWindow === 'function') {
|
|
149
|
+
return await promisifyBrowserCommand(browser, 'resizeWindow', width, height);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return await executeScript(browser, function(dimensions) {
|
|
153
|
+
window.resizeTo(dimensions.width, dimensions.height);
|
|
154
|
+
}, [rect]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function waitForCondition(condition, { timeout = 1000, interval = 100 } = {}) {
|
|
158
|
+
const end = Date.now() + timeout;
|
|
159
|
+
|
|
160
|
+
while (Date.now() < end) {
|
|
161
|
+
if (await condition()) return true;
|
|
162
|
+
await sleep(interval);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return await condition();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function waitForResizeEvent(browser, resizeCount) {
|
|
169
|
+
await waitForCondition(async () => {
|
|
170
|
+
/* istanbul ignore next */
|
|
171
|
+
const current = await executeScript(browser, function() {
|
|
172
|
+
return window.resizeCount;
|
|
173
|
+
});
|
|
174
|
+
return current === resizeCount;
|
|
175
|
+
}).catch(() => {});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function sendCDPResize(browser, width, height) {
|
|
179
|
+
const driver = browser?.driver || browser?.transport?.driver;
|
|
180
|
+
if (!driver || typeof driver.sendDevToolsCommand !== 'function') return false;
|
|
181
|
+
|
|
182
|
+
await driver.sendDevToolsCommand('Emulation.setDeviceMetricsOverride', {
|
|
183
|
+
height,
|
|
184
|
+
width,
|
|
185
|
+
deviceScaleFactor: 1,
|
|
186
|
+
mobile: false
|
|
187
|
+
});
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function changeWindowDimensionAndWait(browser, width, height, resizeCount, log) {
|
|
192
|
+
if (typeof width !== 'number' || Number.isNaN(width)) return;
|
|
193
|
+
if (typeof height !== 'number' || Number.isNaN(height)) {
|
|
194
|
+
({ height } = await getWindowRect(browser));
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const caps = browser?.options?.capabilities || browser?.options?.desiredCapabilities;
|
|
198
|
+
const browserName = caps?.browserName || caps?.browser || '';
|
|
199
|
+
let usedCDP = false;
|
|
200
|
+
|
|
201
|
+
if (
|
|
202
|
+
typeof process !== 'undefined' &&
|
|
203
|
+
process.env.PERCY_DISABLE_CDP_RESIZE !== 'true' &&
|
|
204
|
+
browserName.toLowerCase() === 'chrome'
|
|
205
|
+
) {
|
|
206
|
+
try {
|
|
207
|
+
usedCDP = await sendCDPResize(browser, width, height);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
log?.debug?.(`Resizing using CDP failed for width ${width}`, error);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (!usedCDP) {
|
|
214
|
+
await setWindowRect(browser, { width, height });
|
|
215
|
+
}
|
|
216
|
+
} catch (error) {
|
|
217
|
+
log?.debug?.(`Resizing window failed for width ${width}`, error);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
await waitForResizeEvent(browser, resizeCount);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
log?.debug?.(`Timed out waiting for window resize event for width ${width}`, error);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function maybeReloadPage(browser, domScript) {
|
|
228
|
+
if (!process.env.PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE) return false;
|
|
229
|
+
await promisifyBrowserCommand(browser, 'refresh');
|
|
230
|
+
if (domScript) await executeScript(browser, domScript);
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function maybeSleepForResponsiveCapture() {
|
|
235
|
+
if (!process.env.RESPONSIVE_CAPTURE_SLEEP_TIME) return;
|
|
236
|
+
const sleepTime = parseFloat(process.env.RESPONSIVE_CAPTURE_SLEEP_TIME);
|
|
237
|
+
if (!Number.isFinite(sleepTime)) return;
|
|
238
|
+
await sleep(sleepTime * 1000);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async function maybeScrollForLazyLoad(browser) {
|
|
242
|
+
if (!process.env.PERCY_ENABLE_LAZY_LOADING_SCROLL) return;
|
|
243
|
+
await slowScrollToBottom(browser);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function getResponsiveHeight(browser, currentHeight, utils) {
|
|
247
|
+
if (!process.env.PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT) return currentHeight;
|
|
248
|
+
const minHeight = utils?.percy?.config?.snapshot?.minHeight || currentHeight;
|
|
249
|
+
return await executeScript(browser, function(height) {
|
|
250
|
+
return window.outerHeight - window.innerHeight + height;
|
|
251
|
+
}, [minHeight]);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function captureResponsiveDOM(browser, options, utils, log, domScript) {
|
|
255
|
+
const widths = getWidthsForMultiDOM(options.widths || [], utils?.percy?.widths || {});
|
|
256
|
+
const domSnapshots = [];
|
|
257
|
+
const { width: originalWidth, height: originalHeight } = await getWindowRect(browser);
|
|
258
|
+
let lastWindowWidth = originalWidth;
|
|
259
|
+
let resizeCount = 0;
|
|
260
|
+
|
|
261
|
+
log?.info?.('Responsive snapshot capture enabled');
|
|
262
|
+
await executeScript(browser, function() {
|
|
263
|
+
/* eslint-disable-next-line no-undef */
|
|
264
|
+
PercyDOM.waitForResize();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
const height = await getResponsiveHeight(browser, originalHeight, utils);
|
|
268
|
+
const responsiveWidths = widths.length ? widths : [originalWidth];
|
|
269
|
+
let lastURL;
|
|
270
|
+
|
|
271
|
+
for (let width of responsiveWidths) {
|
|
272
|
+
if (lastWindowWidth !== width) {
|
|
273
|
+
resizeCount += 1;
|
|
274
|
+
await changeWindowDimensionAndWait(browser, width, height, resizeCount, log);
|
|
275
|
+
lastWindowWidth = width;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
log?.info?.(`Capturing responsive snapshot at width ${width}px`);
|
|
279
|
+
const reloaded = await maybeReloadPage(browser, domScript);
|
|
280
|
+
if (reloaded) {
|
|
281
|
+
await executeScript(browser, function() {
|
|
282
|
+
/* eslint-disable-next-line no-undef */
|
|
283
|
+
PercyDOM.waitForResize();
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
await maybeSleepForResponsiveCapture();
|
|
287
|
+
await maybeScrollForLazyLoad(browser);
|
|
288
|
+
|
|
289
|
+
let { domSnapshot, url } = await captureSerializedDOM(browser, options, utils);
|
|
290
|
+
domSnapshot.width = width;
|
|
291
|
+
domSnapshots.push(domSnapshot);
|
|
292
|
+
lastURL = url;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
await changeWindowDimensionAndWait(browser, originalWidth, originalHeight, resizeCount + 1, log);
|
|
296
|
+
return { domSnapshot: domSnapshots, url: lastURL };
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
async function captureDOM(browser, options = {}, utils, log, domScript) {
|
|
300
|
+
const responsiveEnabled = isResponsiveOptionEnabled(options, utils);
|
|
301
|
+
if (responsiveEnabled) {
|
|
302
|
+
return await captureResponsiveDOM(browser, options, utils, log, domScript);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return await captureSerializedDOM(browser, options, utils);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function slowScrollToBottom(browser, scrollSleep = SCROLL_DEFAULT_SLEEP_TIME) {
|
|
309
|
+
if (process.env.PERCY_LAZY_LOAD_SCROLL_TIME) {
|
|
310
|
+
scrollSleep = parseFloat(process.env.PERCY_LAZY_LOAD_SCROLL_TIME);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const scrollHeightCommand = function() {
|
|
314
|
+
return Math.max(
|
|
315
|
+
document.body.scrollHeight,
|
|
316
|
+
document.body.clientHeight,
|
|
317
|
+
document.body.offsetHeight,
|
|
318
|
+
document.documentElement.scrollHeight,
|
|
319
|
+
document.documentElement.clientHeight,
|
|
320
|
+
document.documentElement.offsetHeight
|
|
321
|
+
);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
let scrollHeight = Math.min(await executeScript(browser, scrollHeightCommand), CS_MAX_SCREENSHOT_LIMIT);
|
|
325
|
+
const clientHeight = await executeScript(browser, function() {
|
|
326
|
+
return document.documentElement.clientHeight;
|
|
327
|
+
});
|
|
328
|
+
let current = 0;
|
|
329
|
+
let page = 1;
|
|
330
|
+
|
|
331
|
+
while (scrollHeight > current && current < CS_MAX_SCREENSHOT_LIMIT) {
|
|
332
|
+
current = clientHeight * page;
|
|
333
|
+
page += 1;
|
|
334
|
+
await executeScript(browser, function(position) {
|
|
335
|
+
window.scrollTo(0, position);
|
|
336
|
+
}, [current]);
|
|
337
|
+
await sleep(scrollSleep * 1000);
|
|
338
|
+
scrollHeight = await executeScript(browser, scrollHeightCommand);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (process.env.BYPASS_SCROLL_TO_TOP !== 'true') {
|
|
342
|
+
await executeScript(browser, function() {
|
|
343
|
+
window.scrollTo(0, 0);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
let sleepAfterScroll = 1;
|
|
348
|
+
if (process.env.PERCY_SLEEP_AFTER_LAZY_LOAD_COMPLETE) {
|
|
349
|
+
sleepAfterScroll = parseFloat(process.env.PERCY_SLEEP_AFTER_LAZY_LOAD_COMPLETE);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
await sleep(sleepAfterScroll * 1000);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
module.exports = {
|
|
356
|
+
captureSerializedDOM,
|
|
357
|
+
captureDOM,
|
|
358
|
+
slowScrollToBottom,
|
|
359
|
+
ignoreCanvasSerializationErrors,
|
|
360
|
+
ignoreStyleSheetSerializationErrors
|
|
361
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@percy/nightwatch",
|
|
3
3
|
"description": "Nightwatch client library for visual testing with Percy",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.0-beta.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Perceptual Inc.",
|
|
7
7
|
"repository": "https://github.com/percy/percy-nightwatch",
|
|
@@ -14,37 +14,40 @@
|
|
|
14
14
|
"types": "types/percySnapshot.d.ts",
|
|
15
15
|
"files": [
|
|
16
16
|
"commands/percySnapshot.js",
|
|
17
|
+
"lib",
|
|
17
18
|
"types/percySnapshot.d.ts"
|
|
18
19
|
],
|
|
19
20
|
"engines": {
|
|
20
21
|
"node": ">=14"
|
|
21
22
|
},
|
|
22
23
|
"scripts": {
|
|
23
|
-
"lint": "eslint
|
|
24
|
-
"test": "
|
|
25
|
-
"test:
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"test": "yarn test:unit && yarn test:nightwatch",
|
|
26
|
+
"test:unit": "mocha \"test/unit/**/*.test.js\"",
|
|
27
|
+
"test:nightwatch": "cross-env MOZ_HEADLESS=1 percy exec --testing -- nightwatch",
|
|
28
|
+
"test:coverage": "nyc yarn test:unit",
|
|
26
29
|
"test:types": "tsd"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@percy/sdk-utils": "^1.
|
|
32
|
+
"@percy/sdk-utils": "^1.31.4",
|
|
33
|
+
"@percy/selenium-webdriver": "^2.2.3"
|
|
30
34
|
},
|
|
31
35
|
"peerDependencies": {
|
|
32
|
-
"nightwatch": ">=1"
|
|
36
|
+
"nightwatch": ">=1 || >=2 || >=3"
|
|
33
37
|
},
|
|
34
38
|
"devDependencies": {
|
|
35
|
-
"@percy/
|
|
36
|
-
"
|
|
39
|
+
"@percy/cli": "^1.31.4",
|
|
40
|
+
"cross-env": "^10.1.0",
|
|
37
41
|
"eslint": "^7.11.0",
|
|
38
42
|
"eslint-config-standard": "^16.0.1",
|
|
39
43
|
"eslint-plugin-import": "^2.22.1",
|
|
40
44
|
"eslint-plugin-node": "^11.1.0",
|
|
41
45
|
"eslint-plugin-promise": "^5.1.0",
|
|
42
46
|
"eslint-plugin-standard": "^5.0.0",
|
|
43
|
-
"expect": "^
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"tsd": "^0.20.0"
|
|
47
|
+
"expect": "^30.2.0",
|
|
48
|
+
"mocha": "^11.7.5",
|
|
49
|
+
"nightwatch": "^3.12.3",
|
|
50
|
+
"nyc": "^17.1.0",
|
|
51
|
+
"tsd": "^0.33.0"
|
|
49
52
|
}
|
|
50
53
|
}
|
package/types/percySnapshot.d.ts
CHANGED
|
@@ -1,12 +1,75 @@
|
|
|
1
1
|
import { SnapshotOptions } from '@percy/core';
|
|
2
2
|
import { NightwatchAPI, NightwatchCustomCommands } from 'nightwatch';
|
|
3
3
|
|
|
4
|
+
export type PercyRegionAlgorithm = 'standard' | 'layout' | 'ignore' | 'intelliignore';
|
|
5
|
+
|
|
6
|
+
export interface PercyRegionBoundingBox {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface PercyRegionPadding {
|
|
14
|
+
top?: number;
|
|
15
|
+
right?: number;
|
|
16
|
+
bottom?: number;
|
|
17
|
+
left?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface PercyRegionSelector {
|
|
21
|
+
boundingBox?: PercyRegionBoundingBox;
|
|
22
|
+
elementXpath?: string;
|
|
23
|
+
elementCSS?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface PercyRegionConfiguration {
|
|
27
|
+
diffSensitivity?: number;
|
|
28
|
+
imageIgnoreThreshold?: number;
|
|
29
|
+
carouselsEnabled?: boolean;
|
|
30
|
+
bannersEnabled?: boolean;
|
|
31
|
+
adsEnabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PercyRegionAssertion {
|
|
35
|
+
diffIgnoreThreshold?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface PercyRegion {
|
|
39
|
+
algorithm: PercyRegionAlgorithm;
|
|
40
|
+
elementSelector?: PercyRegionSelector;
|
|
41
|
+
padding?: PercyRegionPadding;
|
|
42
|
+
configuration?: PercyRegionConfiguration;
|
|
43
|
+
assertion?: PercyRegionAssertion;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface CreateRegionOptions extends PercyRegionSelector {
|
|
47
|
+
padding?: PercyRegionPadding;
|
|
48
|
+
algorithm?: PercyRegionAlgorithm;
|
|
49
|
+
diffSensitivity?: number;
|
|
50
|
+
imageIgnoreThreshold?: number;
|
|
51
|
+
carouselsEnabled?: boolean;
|
|
52
|
+
bannersEnabled?: boolean;
|
|
53
|
+
adsEnabled?: boolean;
|
|
54
|
+
diffIgnoreThreshold?: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export type CreateRegion = (options?: CreateRegionOptions) => PercyRegion;
|
|
58
|
+
|
|
59
|
+
export interface PercyNightwatchExports {
|
|
60
|
+
path: string;
|
|
61
|
+
createRegion: CreateRegion;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
declare const percyNightwatch: PercyNightwatchExports;
|
|
65
|
+
export default percyNightwatch;
|
|
66
|
+
|
|
4
67
|
declare module 'nightwatch' {
|
|
5
68
|
interface NightwatchCustomCommands {
|
|
6
69
|
percySnapshot(
|
|
7
70
|
this: NightwatchAPI,
|
|
8
71
|
name?: string,
|
|
9
72
|
options?: SnapshotOptions
|
|
10
|
-
): this
|
|
73
|
+
): this;
|
|
11
74
|
}
|
|
12
75
|
}
|