@percy/nightwatch 2.2.0-beta.0 → 2.2.1-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/commands/percySnapshot.js +9 -1
- package/lib/snapshot.js +47 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
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');
|
|
4
|
+
const { captureDOM, waitForReady } = require('../lib/snapshot');
|
|
5
5
|
const { createRegion } = require('../lib/regions');
|
|
6
6
|
const CLIENT_INFO = `${sdkPkg.name}/${sdkPkg.version}`;
|
|
7
7
|
const ENV_INFO = `${nightwatchPkg.name}/${nightwatchPkg.version}`;
|
|
@@ -43,9 +43,17 @@ module.exports = class PercySnapshotCommand {
|
|
|
43
43
|
// Inject the DOM serialization script
|
|
44
44
|
await injectPercyDOM(this.api, domScript);
|
|
45
45
|
|
|
46
|
+
// Readiness gate — runs before serialize when CLI supports it.
|
|
47
|
+
const readinessDiagnostics = await waitForReady(this.api, options, utils, log);
|
|
48
|
+
|
|
46
49
|
// Serialize and capture the DOM
|
|
47
50
|
let { domSnapshot, url } = await captureDOM(this.api, options, utils, log, domScript);
|
|
48
51
|
|
|
52
|
+
// Attach readiness diagnostics so the CLI can log timing and pass/fail
|
|
53
|
+
if (readinessDiagnostics && domSnapshot && typeof domSnapshot === 'object' && !Array.isArray(domSnapshot)) {
|
|
54
|
+
domSnapshot.readiness_diagnostics = readinessDiagnostics;
|
|
55
|
+
}
|
|
56
|
+
|
|
49
57
|
// Filter out DOM-only serialization options that shouldn't be posted to Percy
|
|
50
58
|
const {
|
|
51
59
|
ignoreCanvasSerializationErrors,
|
package/lib/snapshot.js
CHANGED
|
@@ -41,6 +41,51 @@ function executeScript(browser, fn, args = []) {
|
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
function executeAsyncScript(browser, fn, args = []) {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
try {
|
|
47
|
+
const cb = result => {
|
|
48
|
+
let value = unwrapResult(result);
|
|
49
|
+
if (result && result.status && result.status !== 0 && result.error) {
|
|
50
|
+
return reject(result.error);
|
|
51
|
+
}
|
|
52
|
+
resolve(value);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
if (typeof browser.executeAsync === 'function') {
|
|
56
|
+
browser.executeAsync(fn, args, cb);
|
|
57
|
+
} else if (typeof browser.executeAsyncScript === 'function') {
|
|
58
|
+
browser.executeAsyncScript(fn, args, cb);
|
|
59
|
+
} else {
|
|
60
|
+
resolve(undefined);
|
|
61
|
+
}
|
|
62
|
+
} catch (error) {
|
|
63
|
+
reject(error);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Readiness gate. Runs *before* serialize when CLI exposes
|
|
69
|
+
// PercyDOM.waitForReady. Falls back silently on older CLI builds and never
|
|
70
|
+
// blocks snapshot capture. Uses sdk-utils.waitForReadyScript({ callback: true })
|
|
71
|
+
// as the shared in-browser invoker — uses `arguments[arguments.length - 1]`
|
|
72
|
+
// for the executeAsync done callback.
|
|
73
|
+
async function waitForReady(browser, options = {}, utils, log) {
|
|
74
|
+
// All readiness orchestration (disabled check + shallow-merge config +
|
|
75
|
+
// callback-mode script generation + try/catch) lives in @percy/sdk-utils
|
|
76
|
+
// 1.31.15+ as runReadinessGate. Degrade to no-op when the helper is
|
|
77
|
+
// absent — same behaviour as an old CLI without PercyDOM.waitForReady.
|
|
78
|
+
if (typeof utils?.runReadinessGate !== 'function') return undefined;
|
|
79
|
+
const result = await utils.runReadinessGate(
|
|
80
|
+
(script) => executeAsyncScript(browser, script),
|
|
81
|
+
options,
|
|
82
|
+
{ callback: true, log }
|
|
83
|
+
);
|
|
84
|
+
// sdk-utils returns null on no-op / failure; nightwatch's contract is
|
|
85
|
+
// `undefined`, so normalise.
|
|
86
|
+
return result == null ? undefined : result;
|
|
87
|
+
}
|
|
88
|
+
|
|
44
89
|
function getCookies(browser) {
|
|
45
90
|
if (typeof browser.getCookies !== 'function') return Promise.resolve([]);
|
|
46
91
|
return new Promise((resolve, reject) => {
|
|
@@ -357,5 +402,6 @@ module.exports = {
|
|
|
357
402
|
captureDOM,
|
|
358
403
|
slowScrollToBottom,
|
|
359
404
|
ignoreCanvasSerializationErrors,
|
|
360
|
-
ignoreStyleSheetSerializationErrors
|
|
405
|
+
ignoreStyleSheetSerializationErrors,
|
|
406
|
+
waitForReady
|
|
361
407
|
};
|
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.2.
|
|
4
|
+
"version": "2.2.1-beta.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Perceptual Inc.",
|
|
7
7
|
"repository": "https://github.com/percy/percy-nightwatch",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"test:types": "tsd"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@percy/sdk-utils": "^1.31.
|
|
32
|
+
"@percy/sdk-utils": "^1.31.15-beta.0",
|
|
33
33
|
"@percy/selenium-webdriver": "^2.2.3"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|