@visual-check/cli 0.1.2 → 0.2.1
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/dist/addon-child/image-files.js +1 -1
- package/dist/addon-child/image-files.js.map +1 -1
- package/dist/agent-skill/skill-files.d.ts +4 -0
- package/dist/agent-skill/skill-files.d.ts.map +1 -1
- package/dist/agent-skill/skill-files.js +4 -0
- package/dist/agent-skill/skill-files.js.map +1 -1
- package/dist/baselines/baseline-error.d.ts +15 -2
- package/dist/baselines/baseline-error.d.ts.map +1 -1
- package/dist/baselines/baseline-error.js +32 -2
- package/dist/baselines/baseline-error.js.map +1 -1
- package/dist/capture/capture-session.d.ts +161 -30
- package/dist/capture/capture-session.d.ts.map +1 -1
- package/dist/capture/capture-session.js +291 -72
- package/dist/capture/capture-session.js.map +1 -1
- package/dist/capture/driver/cdp/cdp-page.d.ts.map +1 -1
- package/dist/capture/driver/cdp/cdp-page.js +120 -31
- package/dist/capture/driver/cdp/cdp-page.js.map +1 -1
- package/dist/capture/driver/cdp/failed-loads.d.ts +16 -0
- package/dist/capture/driver/cdp/failed-loads.d.ts.map +1 -0
- package/dist/capture/driver/cdp/failed-loads.js +71 -0
- package/dist/capture/driver/cdp/failed-loads.js.map +1 -0
- package/dist/capture/driver/cdp/launch-arguments.d.ts +7 -1
- package/dist/capture/driver/cdp/launch-arguments.d.ts.map +1 -1
- package/dist/capture/driver/cdp/launch-arguments.js +8 -1
- package/dist/capture/driver/cdp/launch-arguments.js.map +1 -1
- package/dist/capture/driver/driver.d.ts +88 -4
- package/dist/capture/driver/driver.d.ts.map +1 -1
- package/dist/capture/driver/driver.js +33 -0
- package/dist/capture/driver/driver.js.map +1 -1
- package/dist/capture/frames.d.ts +10 -0
- package/dist/capture/frames.d.ts.map +1 -1
- package/dist/capture/frames.js +67 -0
- package/dist/capture/frames.js.map +1 -1
- package/dist/capture/page-script.d.ts +19 -8
- package/dist/capture/page-script.d.ts.map +1 -1
- package/dist/capture/page-script.js +46 -12
- package/dist/capture/page-script.js.map +1 -1
- package/dist/capture/prepare-capture.d.ts +50 -3
- package/dist/capture/prepare-capture.d.ts.map +1 -1
- package/dist/capture/prepare-capture.js +157 -16
- package/dist/capture/prepare-capture.js.map +1 -1
- package/dist/commands/check-storybooks.d.ts +5 -4
- package/dist/commands/check-storybooks.d.ts.map +1 -1
- package/dist/commands/check-storybooks.js +11 -8
- package/dist/commands/check-storybooks.js.map +1 -1
- package/dist/commands/consistency-output.d.ts.map +1 -1
- package/dist/commands/consistency-output.js +3 -3
- package/dist/commands/consistency-output.js.map +1 -1
- package/dist/commands/failed-loads-hint.d.ts +7 -0
- package/dist/commands/failed-loads-hint.d.ts.map +1 -0
- package/dist/commands/failed-loads-hint.js +16 -0
- package/dist/commands/failed-loads-hint.js.map +1 -0
- package/dist/commands/local-update.d.ts +22 -0
- package/dist/commands/local-update.d.ts.map +1 -0
- package/dist/commands/local-update.js +39 -0
- package/dist/commands/local-update.js.map +1 -0
- package/dist/commands/network-warning.d.ts.map +1 -1
- package/dist/commands/network-warning.js +2 -18
- package/dist/commands/network-warning.js.map +1 -1
- package/dist/commands/plan-snapshots.d.ts +23 -8
- package/dist/commands/plan-snapshots.d.ts.map +1 -1
- package/dist/commands/plan-snapshots.js +15 -9
- package/dist/commands/plan-snapshots.js.map +1 -1
- package/dist/commands/report-entries.d.ts +5 -2
- package/dist/commands/report-entries.d.ts.map +1 -1
- package/dist/commands/report-entries.js +63 -15
- package/dist/commands/report-entries.js.map +1 -1
- package/dist/commands/run-browser.d.ts +5 -5
- package/dist/commands/run-browser.d.ts.map +1 -1
- package/dist/commands/run-browser.js +1 -0
- package/dist/commands/run-browser.js.map +1 -1
- package/dist/commands/run-cli.d.ts +16 -5
- package/dist/commands/run-cli.d.ts.map +1 -1
- package/dist/commands/run-cli.js +74 -54
- package/dist/commands/run-cli.js.map +1 -1
- package/dist/commands/run-report.d.ts +3 -3
- package/dist/commands/run-report.d.ts.map +1 -1
- package/dist/commands/run-report.js +4 -2
- package/dist/commands/run-report.js.map +1 -1
- package/dist/commands/run-snapshots.d.ts +7 -4
- package/dist/commands/run-snapshots.d.ts.map +1 -1
- package/dist/commands/run-snapshots.js +49 -17
- package/dist/commands/run-snapshots.js.map +1 -1
- package/dist/commands/snapshot-result.d.ts +66 -9
- package/dist/commands/snapshot-result.d.ts.map +1 -1
- package/dist/commands/snapshot-result.js +46 -6
- package/dist/commands/snapshot-result.js.map +1 -1
- package/dist/commands/stop-message.d.ts.map +1 -1
- package/dist/commands/stop-message.js +6 -1
- package/dist/commands/stop-message.js.map +1 -1
- package/dist/commands/stopped-run.d.ts +10 -5
- package/dist/commands/stopped-run.d.ts.map +1 -1
- package/dist/commands/stopped-run.js +35 -22
- package/dist/commands/stopped-run.js.map +1 -1
- package/dist/commands/take-snapshot.d.ts +9 -6
- package/dist/commands/take-snapshot.d.ts.map +1 -1
- package/dist/commands/take-snapshot.js +16 -7
- package/dist/commands/take-snapshot.js.map +1 -1
- package/dist/commands/test-snapshot.d.ts +2 -2
- package/dist/commands/test-snapshot.d.ts.map +1 -1
- package/dist/commands/test-snapshot.js.map +1 -1
- package/dist/commands/update-baselines.d.ts.map +1 -1
- package/dist/commands/update-baselines.js +3 -2
- package/dist/commands/update-baselines.js.map +1 -1
- package/dist/commands/update-snapshot.d.ts +22 -4
- package/dist/commands/update-snapshot.d.ts.map +1 -1
- package/dist/commands/update-snapshot.js +79 -18
- package/dist/commands/update-snapshot.js.map +1 -1
- package/dist/config/checks.d.ts +26 -0
- package/dist/config/checks.d.ts.map +1 -1
- package/dist/config/checks.js +68 -6
- package/dist/config/checks.js.map +1 -1
- package/dist/config/define-config.d.ts +38 -2
- package/dist/config/define-config.d.ts.map +1 -1
- package/dist/config/define-config.js.map +1 -1
- package/dist/config/resolve-config.d.ts +15 -2
- package/dist/config/resolve-config.d.ts.map +1 -1
- package/dist/config/resolve-config.js +6 -0
- package/dist/config/resolve-config.js.map +1 -1
- package/dist/config/story-options.d.ts +32 -4
- package/dist/config/story-options.d.ts.map +1 -1
- package/dist/config/story-options.js +38 -7
- package/dist/config/story-options.js.map +1 -1
- package/dist/config/unrunnable-regexp.d.ts +22 -0
- package/dist/config/unrunnable-regexp.d.ts.map +1 -0
- package/dist/config/unrunnable-regexp.js +25 -0
- package/dist/config/unrunnable-regexp.js.map +1 -0
- package/dist/config/validate-config.d.ts.map +1 -1
- package/dist/config/validate-config.js +6 -21
- package/dist/config/validate-config.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/init/find-storybooks.d.ts +5 -0
- package/dist/init/find-storybooks.d.ts.map +1 -1
- package/dist/init/find-storybooks.js +8 -1
- package/dist/init/find-storybooks.js.map +1 -1
- package/dist/init/ignored-skill.d.ts +50 -0
- package/dist/init/ignored-skill.d.ts.map +1 -0
- package/dist/init/ignored-skill.js +61 -0
- package/dist/init/ignored-skill.js.map +1 -0
- package/dist/init/install.d.ts +24 -9
- package/dist/init/install.d.ts.map +1 -1
- package/dist/init/install.js +66 -26
- package/dist/init/install.js.map +1 -1
- package/dist/init/package-manager.d.ts +6 -0
- package/dist/init/package-manager.d.ts.map +1 -1
- package/dist/init/package-manager.js +4 -0
- package/dist/init/package-manager.js.map +1 -1
- package/dist/init/run-init.d.ts +17 -4
- package/dist/init/run-init.d.ts.map +1 -1
- package/dist/init/run-init.js +31 -11
- package/dist/init/run-init.js.map +1 -1
- package/dist/init/workspace.d.ts +2 -0
- package/dist/init/workspace.d.ts.map +1 -1
- package/dist/init/workspace.js +2 -0
- package/dist/init/workspace.js.map +1 -1
- package/dist/page-errors/judge-page-errors.d.ts +50 -0
- package/dist/page-errors/judge-page-errors.d.ts.map +1 -0
- package/dist/page-errors/judge-page-errors.js +39 -0
- package/dist/page-errors/judge-page-errors.js.map +1 -0
- package/dist/page-errors/page-error-policy.d.ts +36 -0
- package/dist/page-errors/page-error-policy.d.ts.map +1 -0
- package/dist/page-errors/page-error-policy.js +15 -0
- package/dist/page-errors/page-error-policy.js.map +1 -0
- package/dist/real-network-requests/judge-real-requests.d.ts +26 -0
- package/dist/real-network-requests/judge-real-requests.d.ts.map +1 -0
- package/dist/real-network-requests/judge-real-requests.js +17 -0
- package/dist/real-network-requests/judge-real-requests.js.map +1 -0
- package/dist/real-network-requests/real-request-policy.d.ts +29 -0
- package/dist/real-network-requests/real-request-policy.d.ts.map +1 -0
- package/dist/real-network-requests/real-request-policy.js +10 -0
- package/dist/real-network-requests/real-request-policy.js.map +1 -0
- package/dist/real-network-requests/silenced-hosts.d.ts +9 -0
- package/dist/real-network-requests/silenced-hosts.d.ts.map +1 -0
- package/dist/real-network-requests/silenced-hosts.js +28 -0
- package/dist/real-network-requests/silenced-hosts.js.map +1 -0
- package/dist/report/report-document.d.ts +154 -9
- package/dist/report/report-document.d.ts.map +1 -1
- package/dist/report/report-document.js +1 -1
- package/dist/report/report-document.js.map +1 -1
- package/dist/report/report-folder.d.ts +7 -3
- package/dist/report/report-folder.d.ts.map +1 -1
- package/dist/report/report-folder.js +5 -5
- package/dist/report/report-folder.js.map +1 -1
- package/dist/reporter/end-block.d.ts +32 -3
- package/dist/reporter/end-block.d.ts.map +1 -1
- package/dist/reporter/end-block.js +55 -3
- package/dist/reporter/end-block.js.map +1 -1
- package/dist/reporter/page-errors-block.d.ts +52 -0
- package/dist/reporter/page-errors-block.d.ts.map +1 -0
- package/dist/reporter/page-errors-block.js +98 -0
- package/dist/reporter/page-errors-block.js.map +1 -0
- package/dist/reporter/real-requests-block.d.ts +33 -0
- package/dist/reporter/real-requests-block.d.ts.map +1 -0
- package/dist/reporter/real-requests-block.js +53 -0
- package/dist/reporter/real-requests-block.js.map +1 -0
- package/dist/step-summary/step-summary.d.ts +27 -7
- package/dist/step-summary/step-summary.d.ts.map +1 -1
- package/dist/step-summary/step-summary.js +107 -15
- package/dist/step-summary/step-summary.js.map +1 -1
- package/dist/storybook/options-encoding.d.ts +18 -5
- package/dist/storybook/options-encoding.d.ts.map +1 -1
- package/dist/storybook/options-encoding.js +12 -4
- package/dist/storybook/options-encoding.js.map +1 -1
- package/dist/storybook/options-read.d.ts +3 -2
- package/dist/storybook/options-read.d.ts.map +1 -1
- package/dist/storybook/options-read.js +17 -0
- package/dist/storybook/options-read.js.map +1 -1
- package/dist/storybook/read-stories.d.ts +15 -0
- package/dist/storybook/read-stories.d.ts.map +1 -1
- package/dist/storybook/read-stories.js +60 -14
- package/dist/storybook/read-stories.js.map +1 -1
- package/package.json +2 -1
- package/skill/SKILL.md +25 -7
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { readStoryWait, storyWaitExpression } from '../storybook/preview-script.js';
|
|
2
2
|
import { testPathUserAgentSuffix } from '../storybook/test-path.js';
|
|
3
3
|
import { readWaitHookRun, waitHookExpression } from '../storybook/wait-hook.js';
|
|
4
|
-
import { BrowserExitedError, CaptureTooLargeError, maxCaptureSide, PageCrashedError, PageNavigatedAwayError, PageTimeoutError, } from './driver/driver.js';
|
|
4
|
+
import { BrowserExitedError, CaptureTooLargeError, eachPageErrorOnce, maxCaptureSide, PageCrashedError, PageNavigatedAwayError, PageTimeoutError, } from './driver/driver.js';
|
|
5
5
|
import { readEndState } from './end-state.js';
|
|
6
|
-
import { assetsReadyExpression, endStateExpression, framesAfterGrowthExpression, pageInitScript, prepareCaptureExpression, readAssetsReadiness, readFramesPassed, } from './page-script.js';
|
|
6
|
+
import { assetsReadyExpression, endStateExpression, framesAfterGrowthExpression, heightSettledExpression, pageInitScript, prepareCaptureExpression, readAssetsReadiness, readFramesPassed, } from './page-script.js';
|
|
7
7
|
import { readCapturePrep, } from './prepare-capture.js';
|
|
8
8
|
/**
|
|
9
9
|
* How much longer than a wait in the page the driver waits for its answer, in ms. The wait in the page gives up first
|
|
@@ -16,6 +16,22 @@ export const waitMarginMs = 1_000;
|
|
|
16
16
|
* @public
|
|
17
17
|
*/
|
|
18
18
|
export const brokenImageTimeLimitMs = 5_000;
|
|
19
|
+
/**
|
|
20
|
+
* What the page reacts to in each wait for frames, as the messages name it.
|
|
21
|
+
*/
|
|
22
|
+
const framesTargets = {
|
|
23
|
+
'frames-after-grow': 'the grown viewport',
|
|
24
|
+
'settle-after-reset': 'the viewport set again after its wait hook',
|
|
25
|
+
'frames-after-regrow': 'the viewport grown after its wait hook',
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The expression each wait for frames evaluates in the page, for what's left of readyTimeout.
|
|
29
|
+
*/
|
|
30
|
+
const framesExpressions = {
|
|
31
|
+
'frames-after-grow': framesAfterGrowthExpression,
|
|
32
|
+
'settle-after-reset': heightSettledExpression,
|
|
33
|
+
'frames-after-regrow': framesAfterGrowthExpression,
|
|
34
|
+
};
|
|
19
35
|
/**
|
|
20
36
|
* What each step does, as a phrase that follows "while".
|
|
21
37
|
*/
|
|
@@ -29,6 +45,10 @@ const stepNames = {
|
|
|
29
45
|
'assets-after-grow': 'waiting for images and fonts after growing the viewport',
|
|
30
46
|
wait: "running the story's wait hook",
|
|
31
47
|
'assets-after-wait': 'waiting for images and fonts after its wait hook',
|
|
48
|
+
'regrow-viewport': 'growing the viewport to the page again after its wait hook',
|
|
49
|
+
'settle-after-reset': 'letting the page react to the viewport set again after its wait hook',
|
|
50
|
+
'frames-after-regrow': 'letting the page react to the viewport grown after its wait hook',
|
|
51
|
+
'assets-after-regrow': 'waiting for images and fonts once the viewport was set again after its wait hook',
|
|
32
52
|
'end-state': 'bringing the story to its end state',
|
|
33
53
|
'assets-after-end-state': 'waiting for images and fonts after its end state',
|
|
34
54
|
masks: 'painting its masks and hiding the caret',
|
|
@@ -46,6 +66,9 @@ const stepTimeouts = {
|
|
|
46
66
|
'assets-after-grow': 'its page stopped answering while visual-check waited for its images and fonts after growing the viewport',
|
|
47
67
|
wait: 'its page stopped answering while its wait hook ran',
|
|
48
68
|
'assets-after-wait': 'its page stopped answering while visual-check waited for its images and fonts after its wait hook',
|
|
69
|
+
'settle-after-reset': 'its page stopped answering while visual-check let it react to the viewport set again after its wait hook',
|
|
70
|
+
'frames-after-regrow': 'its page stopped answering while visual-check let it react to the viewport grown after its wait hook',
|
|
71
|
+
'assets-after-regrow': 'its page stopped answering while visual-check waited for its images and fonts once the viewport was set again after its wait hook',
|
|
49
72
|
'end-state': 'its page stopped answering while visual-check brought it to its end state',
|
|
50
73
|
'assets-after-end-state': 'its page stopped answering while visual-check waited for its images and fonts after its end state',
|
|
51
74
|
masks: 'its page stopped answering while visual-check painted its masks and hid the caret',
|
|
@@ -57,6 +80,7 @@ const assetsCheckSuffixes = {
|
|
|
57
80
|
assets: '',
|
|
58
81
|
'assets-after-grow': ' after growing the viewport',
|
|
59
82
|
'assets-after-wait': ' after its wait hook',
|
|
83
|
+
'assets-after-regrow': ' once the viewport was set again after its wait hook',
|
|
60
84
|
'assets-after-end-state': ' after its end state',
|
|
61
85
|
};
|
|
62
86
|
/**
|
|
@@ -67,13 +91,52 @@ const endStateTimeouts = {
|
|
|
67
91
|
media: 'visual-check was still putting its media on their first frame',
|
|
68
92
|
};
|
|
69
93
|
/**
|
|
70
|
-
* Gives
|
|
94
|
+
* Gives the broken story with the loads of Storybook's own files that failed at the network level on its page, and a
|
|
95
|
+
* sentence at the end of its message naming the first, its path shown against the story's URL, and how many there were
|
|
96
|
+
* when more than one. A `play-threw` story whose error Storybook described as nothing keeps the message without that
|
|
97
|
+
* sentence as its error text, for the report's play details. Gives it as it is when none failed.
|
|
71
98
|
*/
|
|
72
|
-
function
|
|
99
|
+
function withFailedLoads(broken, failedLoads, storyUrl) {
|
|
100
|
+
const [first] = failedLoads;
|
|
101
|
+
if (first === undefined) {
|
|
102
|
+
return broken;
|
|
103
|
+
}
|
|
104
|
+
const path = displayUrlOf(first.url, storyUrl);
|
|
105
|
+
const files = failedLoads.length === 1
|
|
106
|
+
? `${path} from Storybook`
|
|
107
|
+
: `${failedLoads.length} files from Storybook, the first ${path}`;
|
|
108
|
+
return {
|
|
109
|
+
...broken,
|
|
110
|
+
...(broken.reason === 'play-threw' && broken.errorText === '' ? { errorText: broken.message } : {}),
|
|
111
|
+
message: `${broken.message} Its page couldn't load ${files}: ${first.error}.`,
|
|
112
|
+
failedLoads,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Gives the readyTimeout a story's capture runs under: the story's own when it sets one, else the settings'.
|
|
117
|
+
*/
|
|
118
|
+
function readyTimeoutOf(story, settings) {
|
|
119
|
+
if (story.readyTimeoutMs === undefined) {
|
|
120
|
+
return { ms: settings.readyTimeoutMs, setIn: 'config' };
|
|
121
|
+
}
|
|
122
|
+
return { ms: story.readyTimeoutMs, setIn: 'story' };
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Names a readyTimeout in a message: how long it is and where it was set.
|
|
126
|
+
*/
|
|
127
|
+
function readyTimeoutText({ ms, setIn }) {
|
|
128
|
+
const where = setIn === 'story' ? "the story's parameters.visualCheck" : 'the config';
|
|
129
|
+
return `readyTimeout (${ms} ms, from ${where})`;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Gives a story that wasn't ready within its readyTimeout, saying what it was doing.
|
|
133
|
+
*/
|
|
134
|
+
function notReady(readyTimeout, doing) {
|
|
73
135
|
return {
|
|
74
136
|
reason: 'timeout',
|
|
75
|
-
message: `The story wasn't ready within
|
|
76
|
-
readyTimeoutMs,
|
|
137
|
+
message: `The story wasn't ready within ${readyTimeoutText(readyTimeout)}: ${doing}.`,
|
|
138
|
+
readyTimeoutMs: readyTimeout.ms,
|
|
139
|
+
readyTimeoutSetIn: readyTimeout.setIn,
|
|
77
140
|
};
|
|
78
141
|
}
|
|
79
142
|
/**
|
|
@@ -118,14 +181,14 @@ function stillWaitingFor(wait) {
|
|
|
118
181
|
/**
|
|
119
182
|
* Says why a story isn't ready to capture, from what the story wait found.
|
|
120
183
|
*/
|
|
121
|
-
function describeStoryWait(wait,
|
|
184
|
+
function describeStoryWait(wait, readyTimeout) {
|
|
122
185
|
switch (wait.outcome) {
|
|
123
186
|
case 'play-threw':
|
|
124
187
|
return { reason: 'play-threw', message: wait.message, errorText: wait.errorText, stack: wait.stack };
|
|
125
188
|
case 'errored':
|
|
126
189
|
return { reason: 'error', message: wait.message };
|
|
127
190
|
case 'timed-out':
|
|
128
|
-
return notReady(
|
|
191
|
+
return notReady(readyTimeout, stillWaitingFor(wait));
|
|
129
192
|
case 'script-missing':
|
|
130
193
|
return {
|
|
131
194
|
reason: 'error',
|
|
@@ -146,7 +209,7 @@ function imagesStillLoading(pending) {
|
|
|
146
209
|
* Says why a story isn't ready to capture, from what a check of its images and fonts found. `suffix` follows what the
|
|
147
210
|
* message says the story was doing, so it names the check.
|
|
148
211
|
*/
|
|
149
|
-
function describeAssetsWait(assets,
|
|
212
|
+
function describeAssetsWait(assets, readyTimeout, suffix) {
|
|
150
213
|
if (assets.outcome === 'script-missing') {
|
|
151
214
|
return {
|
|
152
215
|
reason: 'error',
|
|
@@ -154,47 +217,49 @@ function describeAssetsWait(assets, readyTimeoutMs, suffix) {
|
|
|
154
217
|
};
|
|
155
218
|
}
|
|
156
219
|
if (assets.step === 'images') {
|
|
157
|
-
return notReady(
|
|
220
|
+
return notReady(readyTimeout, `${imagesStillLoading(assets.pending)}${suffix}`);
|
|
158
221
|
}
|
|
159
222
|
const faces = assets.pendingFaces;
|
|
160
223
|
if (faces.length === 0) {
|
|
161
|
-
return notReady(
|
|
224
|
+
return notReady(readyTimeout, `document.fonts.ready hadn't resolved${suffix}`);
|
|
162
225
|
}
|
|
163
226
|
return {
|
|
164
227
|
reason: 'fonts-not-loaded',
|
|
165
|
-
message: `The story's fonts hadn't loaded within
|
|
228
|
+
message: `The story's fonts hadn't loaded within ${readyTimeoutText(readyTimeout)}${suffix}. Still loading: ${faces.join(', ')}.`,
|
|
166
229
|
faces,
|
|
167
|
-
readyTimeoutMs,
|
|
230
|
+
readyTimeoutMs: readyTimeout.ms,
|
|
231
|
+
readyTimeoutSetIn: readyTimeout.setIn,
|
|
168
232
|
};
|
|
169
233
|
}
|
|
170
234
|
/**
|
|
171
|
-
* Says why a story isn't ready to capture, from what letting frames pass
|
|
235
|
+
* Says why a story isn't ready to capture, from what letting frames pass found in the wait `framesStep` names: once the
|
|
236
|
+
* viewport grew, once it was set again after the wait hook, or once it grew after the hook.
|
|
172
237
|
*/
|
|
173
|
-
function
|
|
238
|
+
function describeFrames(frames, readyTimeout, framesStep) {
|
|
174
239
|
if (frames.outcome === 'script-missing') {
|
|
175
240
|
return {
|
|
176
241
|
reason: 'error',
|
|
177
|
-
message:
|
|
242
|
+
message: `visual-check's page script didn't run in the story's page, so it couldn't let the page react to ${framesTargets[framesStep]}.`,
|
|
178
243
|
};
|
|
179
244
|
}
|
|
180
|
-
return notReady(
|
|
245
|
+
return notReady(readyTimeout, `visual-check was still letting the page react to ${framesTargets[framesStep]}`);
|
|
181
246
|
}
|
|
182
247
|
/**
|
|
183
248
|
* Says why a story isn't ready to capture, from what bringing it to its end state found.
|
|
184
249
|
*/
|
|
185
|
-
function describeEndState(endState,
|
|
250
|
+
function describeEndState(endState, readyTimeout) {
|
|
186
251
|
if (endState.outcome === 'script-missing') {
|
|
187
252
|
return {
|
|
188
253
|
reason: 'error',
|
|
189
254
|
message: "visual-check's page script didn't run in the story's page, so it couldn't bring it to its end state.",
|
|
190
255
|
};
|
|
191
256
|
}
|
|
192
|
-
return notReady(
|
|
257
|
+
return notReady(readyTimeout, endStateTimeouts[endState.step]);
|
|
193
258
|
}
|
|
194
259
|
/**
|
|
195
260
|
* Says why a story can't be captured, from what preparing its capture found. `element` is the story's element selector.
|
|
196
261
|
*/
|
|
197
|
-
function describeCapturePrep(prep, element,
|
|
262
|
+
function describeCapturePrep(prep, element, readyTimeout) {
|
|
198
263
|
switch (prep.outcome) {
|
|
199
264
|
case 'element-missing':
|
|
200
265
|
return {
|
|
@@ -211,7 +276,7 @@ function describeCapturePrep(prep, element, readyTimeoutMs) {
|
|
|
211
276
|
: `The selector of mask ${JSON.stringify(prep.name)} isn't valid CSS: ${failureReasonOf(prep.message)}`,
|
|
212
277
|
};
|
|
213
278
|
case 'timed-out':
|
|
214
|
-
return notReady(
|
|
279
|
+
return notReady(readyTimeout, 'visual-check was still looking for remote content to mask');
|
|
215
280
|
case 'script-missing':
|
|
216
281
|
return {
|
|
217
282
|
reason: 'error',
|
|
@@ -227,14 +292,14 @@ function describeCapturePrep(prep, element, readyTimeoutMs) {
|
|
|
227
292
|
/**
|
|
228
293
|
* Says why a story isn't ready to capture, from what running its wait hook found.
|
|
229
294
|
*/
|
|
230
|
-
function describeWaitHookRun(run,
|
|
295
|
+
function describeWaitHookRun(run, readyTimeout) {
|
|
231
296
|
switch (run.outcome) {
|
|
232
297
|
case 'threw':
|
|
233
298
|
return { reason: 'wait-threw', message: run.message };
|
|
234
299
|
case 'context-failed':
|
|
235
300
|
return { reason: 'error', message: run.message };
|
|
236
301
|
case 'timed-out':
|
|
237
|
-
return notReady(
|
|
302
|
+
return notReady(readyTimeout, "its wait hook hadn't finished");
|
|
238
303
|
case 'no-render':
|
|
239
304
|
return {
|
|
240
305
|
reason: 'error',
|
|
@@ -253,7 +318,7 @@ function describeWaitHookRun(run, readyTimeoutMs) {
|
|
|
253
318
|
* capture: the hint says to set `element` for the full page, or to capture a smaller element. `story` shows a URL on
|
|
254
319
|
* the story's own origin as a path.
|
|
255
320
|
*/
|
|
256
|
-
function describeFailure(error, step, story,
|
|
321
|
+
function describeFailure(error, step, story, readyTimeout) {
|
|
257
322
|
if (error instanceof PageCrashedError) {
|
|
258
323
|
return {
|
|
259
324
|
reason: 'crashed',
|
|
@@ -277,7 +342,7 @@ function describeFailure(error, step, story, readyTimeoutMs) {
|
|
|
277
342
|
}
|
|
278
343
|
const doing = stepTimeouts[step];
|
|
279
344
|
if (error instanceof PageTimeoutError && doing !== undefined) {
|
|
280
|
-
return notReady(
|
|
345
|
+
return notReady(readyTimeout, doing);
|
|
281
346
|
}
|
|
282
347
|
const name = stepNames[step];
|
|
283
348
|
return {
|
|
@@ -356,6 +421,63 @@ export function gridProblemOf(grid, viewport) {
|
|
|
356
421
|
size: { width: deviceWidth, height: deviceHeight },
|
|
357
422
|
};
|
|
358
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* Says how far content reaches past each edge that counts, such as `12 px past the page's top edge`, from pairs of a
|
|
426
|
+
* distance in CSS pixels and an edge. An edge whose distance is 0 doesn't count.
|
|
427
|
+
*/
|
|
428
|
+
function edgePhrasesOf(edges) {
|
|
429
|
+
return edges.filter(([distance]) => distance > 0).map(([distance, edge]) => `${distance} px past ${edge}`);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Says how far an element's capture would cut content, as a sentence of at most two clauses: first the element past
|
|
433
|
+
* the page's top and left edges, then its content past its right and bottom edges, each clause naming only the sides
|
|
434
|
+
* that count. The content's clause names the element when it comes first. Two clauses are joined with `, and` when
|
|
435
|
+
* either names two sides, and with `and` otherwise.
|
|
436
|
+
*/
|
|
437
|
+
function elementOverflowSentenceOf({ top, right, bottom, left }) {
|
|
438
|
+
const pageEdges = edgePhrasesOf([
|
|
439
|
+
[top, "the page's top edge"],
|
|
440
|
+
[left, top > 0 ? 'its left edge' : "the page's left edge"],
|
|
441
|
+
]);
|
|
442
|
+
const contentEdges = edgePhrasesOf([
|
|
443
|
+
[right, 'its right edge'],
|
|
444
|
+
[bottom, 'its bottom edge'],
|
|
445
|
+
]);
|
|
446
|
+
const contentSubject = pageEdges.length > 0 ? 'its content' : "the element's content";
|
|
447
|
+
const clauses = [
|
|
448
|
+
{ subject: 'the element', edges: pageEdges },
|
|
449
|
+
{ subject: contentSubject, edges: contentEdges },
|
|
450
|
+
]
|
|
451
|
+
.filter(({ edges }) => edges.length > 0)
|
|
452
|
+
.map(({ subject, edges }) => `${subject} reaches ${edges.join(' and ')}`);
|
|
453
|
+
const sentence = clauses.join(pageEdges.length > 1 || contentEdges.length > 1 ? ', and ' : ' and ');
|
|
454
|
+
return `${sentence.charAt(0).toUpperCase()}${sentence.slice(1)}`;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Says why a story whose capture would cut content its page shows can't be captured, or gives nothing when it would cut
|
|
458
|
+
* nothing or the story sets `allowOverflow: true`. For the full page, it names how far content reaches past the
|
|
459
|
+
* viewport's right edge; for an element's box, each side that counts. `area` is what the capture takes, and the
|
|
460
|
+
* story's viewport is the snapshot's: its mode's when it has one.
|
|
461
|
+
*/
|
|
462
|
+
export function overflowProblemOf(overflow, area, story) {
|
|
463
|
+
if (overflow === undefined || story.allowOverflow === true) {
|
|
464
|
+
return undefined;
|
|
465
|
+
}
|
|
466
|
+
const viewportWidth = story.viewport.width;
|
|
467
|
+
const { top, right, bottom, left } = overflow;
|
|
468
|
+
if (area === 'full-page') {
|
|
469
|
+
return {
|
|
470
|
+
reason: 'overflows',
|
|
471
|
+
message: `Content reaches ${right} px past the right edge of the ${viewportWidth} px viewport, so the capture would cut it. Fix the layout, give the story a wider viewport or list modes without the narrow ones, or set allowOverflow when the cut is intended.`,
|
|
472
|
+
overflow: { area: 'full-page', top, right, bottom, left, viewportWidth },
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
return {
|
|
476
|
+
reason: 'overflows',
|
|
477
|
+
message: `${elementOverflowSentenceOf(overflow)}, so the capture would cut it. Fix the layout, capture an element that holds the content, or set allowOverflow when the cut is intended.`,
|
|
478
|
+
overflow: { area: 'element', top, right, bottom, left, viewportWidth },
|
|
479
|
+
};
|
|
480
|
+
}
|
|
359
481
|
/**
|
|
360
482
|
* What a snapshot comes with besides its bytes, read right after the capture: the remote content it shows, in pixels
|
|
361
483
|
* of its image, when the story asked for it with `findRemoteContent` and the page gave it, and the hosts the story
|
|
@@ -373,33 +495,50 @@ function capturedExtrasOf(page, story, settings, prepared) {
|
|
|
373
495
|
...(hosts === undefined ? {} : { hosts }),
|
|
374
496
|
};
|
|
375
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* What an attempt reads of its page's loads once it's done: the page errors, and the hosts of the real network requests
|
|
500
|
+
* when the story asks for them with `watchRequests`.
|
|
501
|
+
*/
|
|
502
|
+
function loadsReadOf(page, story) {
|
|
503
|
+
return {
|
|
504
|
+
pageErrors: page.pageErrors(),
|
|
505
|
+
...(story.watchRequests === true ? { requestHosts: page.requestHosts() } : {}),
|
|
506
|
+
};
|
|
507
|
+
}
|
|
376
508
|
/**
|
|
377
509
|
* Captures a story on an open page: sets the story's viewport, loads the story, waits until Storybook reports it
|
|
378
510
|
* finished with nothing gone wrong, waits for its images and fonts, grows the viewport to the page for a full-page
|
|
379
|
-
* capture, runs its wait hook,
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
511
|
+
* capture, runs its wait hook, measures the page again for a full-page capture once its wait hook ran, brings it to its
|
|
512
|
+
* end state, measures its element, paints its masks, hides the caret and captures the element's box, or the full page
|
|
513
|
+
* when the story has no element. When the viewport grew, two frames pass so the page reacts to the new size, then its
|
|
514
|
+
* images and fonts are checked again. When the story's wait hook ran, they're checked again after it, then, for a
|
|
515
|
+
* full-page capture, the story's viewport is set again and the page's height settles when the viewport grew before
|
|
516
|
+
* the hook, the viewport grows to the page, two frames pass when it grew, and they're checked again. When the end state changed anything, they're checked again before the masks.
|
|
517
|
+
* Loading, the waits, the frames, the hook, the end state, those checks and the masks share readyTimeout, the story's
|
|
518
|
+
* own when it sets `readyTimeoutMs` and the settings' otherwise, each getting only what's left of it. When the story asks for it with `findRemoteContent`, the snapshot comes with the remote content it shows, unless the search didn't answer in time.
|
|
385
519
|
* When the settings ask to list hosts, it also gives the hosts the page sent requests to, read once the capture is
|
|
386
520
|
* done, and the hosts of the remote content the story shows, from the same search as the host masks. A story whose page
|
|
387
521
|
* shows a grid wider than the viewport, or too tall to capture, is broken before anything is captured, as
|
|
388
|
-
* `gridProblemOf` says.
|
|
389
|
-
*
|
|
522
|
+
* `gridProblemOf` says. Then one whose capture would cut content its page shows is broken, as `overflowProblemOf` says,
|
|
523
|
+
* unless it sets `allowOverflow: true`; a capture too tall is only found as it's taken, after that. Gives the area the
|
|
524
|
+
* snapshot was captured from beside it, and leaves the story's `captureAgainIf` to the caller. A story that can't be captured comes back as a broken story. Either way it comes with
|
|
390
525
|
* the console messages and errors the page sent, read once the capture is done or the story broke, while the page is
|
|
391
|
-
* still open
|
|
526
|
+
* still open, and a broken story with the loads of Storybook's files that failed on the page and its page errors. A
|
|
527
|
+
* snapshot's page errors are left to the caller, read once `captureAgainIf` ran. Rejects only with a
|
|
528
|
+
* `BrowserExitedError`.
|
|
392
529
|
*/
|
|
393
530
|
async function captureOnPage(page, story, settings) {
|
|
394
|
-
const
|
|
531
|
+
const readyTimeout = readyTimeoutOf(story, settings);
|
|
532
|
+
const deadline = performance.now() + readyTimeout.ms;
|
|
395
533
|
const timeLeft = () => Math.max(0, Math.ceil(deadline - performance.now()));
|
|
396
534
|
let step = 'viewport';
|
|
397
535
|
/**
|
|
398
|
-
* Gives the broken story with the messages the page sent.
|
|
536
|
+
* Gives the broken story with the messages the page sent and the loads of Storybook's files that failed on it.
|
|
399
537
|
*/
|
|
400
538
|
const brokenBy = (broken) => ({
|
|
401
|
-
broken,
|
|
539
|
+
broken: withFailedLoads(broken, page.failedLoads(), story.url),
|
|
402
540
|
console: page.consoleMessages(),
|
|
541
|
+
...loadsReadOf(page, story),
|
|
403
542
|
});
|
|
404
543
|
/**
|
|
405
544
|
* Evaluates a wait in the page, built by `expressionFor` for what's left of readyTimeout, and gives the page's
|
|
@@ -419,16 +558,27 @@ async function captureOnPage(page, story, settings) {
|
|
|
419
558
|
if (assets.outcome === 'ready') {
|
|
420
559
|
return undefined;
|
|
421
560
|
}
|
|
422
|
-
return describeAssetsWait(assets,
|
|
561
|
+
return describeAssetsWait(assets, readyTimeout, assetsCheckSuffixes[assetsStep]);
|
|
423
562
|
};
|
|
424
563
|
/**
|
|
425
|
-
*
|
|
426
|
-
*
|
|
564
|
+
* Whether the capture is of the full page with the viewport's growth on: the viewport grows to the page before the
|
|
565
|
+
* wait hook and is measured again after a hook that ran.
|
|
427
566
|
*/
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
567
|
+
const growsViewport = story.element === undefined && story.growViewport !== false;
|
|
568
|
+
/**
|
|
569
|
+
* Whether the viewport grew before the wait hook, so it's taller than the story's own until it's set again.
|
|
570
|
+
*/
|
|
571
|
+
let grewBeforeHook = false;
|
|
572
|
+
/**
|
|
573
|
+
* Lets the page react to its viewport once it grew, was set again or grew again, as `framesStep` names: two frames
|
|
574
|
+
* pass, so its observers and `resize` listeners call back and the render they cause is done. Once it was set again,
|
|
575
|
+
* the page's height also has to settle, so a debounced `resize` handler has answered too. Gives why the story isn't
|
|
576
|
+
* ready, or nothing when it is.
|
|
577
|
+
*/
|
|
578
|
+
const letPageReact = async (framesStep) => {
|
|
579
|
+
step = framesStep;
|
|
580
|
+
const frames = readFramesPassed(await waitInPage(framesExpressions[framesStep]));
|
|
581
|
+
return frames.outcome === 'passed' ? undefined : describeFrames(frames, readyTimeout, framesStep);
|
|
432
582
|
};
|
|
433
583
|
/**
|
|
434
584
|
* Grows the viewport's height to the page's for a full-page capture, unless the story turns that off. When it grew,
|
|
@@ -436,18 +586,45 @@ async function captureOnPage(page, story, settings) {
|
|
|
436
586
|
* nothing when it is.
|
|
437
587
|
*/
|
|
438
588
|
const growViewport = async () => {
|
|
439
|
-
if (
|
|
589
|
+
if (!growsViewport) {
|
|
440
590
|
return undefined;
|
|
441
591
|
}
|
|
442
592
|
step = 'grow-viewport';
|
|
443
593
|
if (!(await page.growViewportToContent())) {
|
|
444
594
|
return undefined;
|
|
445
595
|
}
|
|
446
|
-
|
|
596
|
+
grewBeforeHook = true;
|
|
597
|
+
return (await letPageReact('frames-after-grow')) ?? (await checkAssets('assets-after-grow'));
|
|
447
598
|
};
|
|
448
599
|
/**
|
|
449
|
-
*
|
|
450
|
-
*
|
|
600
|
+
* Measures the page again once the story's wait hook ran, for a full-page capture with the growth on. When the
|
|
601
|
+
* viewport grew before the hook, sets the story's own viewport again, so a `min-height: 100vh` page doesn't keep its
|
|
602
|
+
* last growth, and lets the page react to it until its height settles, so a page sized by a `resize` handler doesn't
|
|
603
|
+
* keep it either. A viewport that didn't grow is still the story's own, so setting it again would change nothing and
|
|
604
|
+
* fire no `resize`: it's measured as it is. Then grows it to the page's height when the page is taller. A page the
|
|
605
|
+
* hook made shorter shrinks back, and one too tall to capture stays at the story's viewport. When it grew, lets two
|
|
606
|
+
* frames pass so the page reacts to the new size. Then checks the images and fonts again. Gives why the story isn't
|
|
607
|
+
* ready, or nothing when it is.
|
|
608
|
+
*/
|
|
609
|
+
const regrowViewport = async () => {
|
|
610
|
+
if (!growsViewport) {
|
|
611
|
+
return undefined;
|
|
612
|
+
}
|
|
613
|
+
step = 'regrow-viewport';
|
|
614
|
+
if (grewBeforeHook) {
|
|
615
|
+
await page.setViewport(story.viewport);
|
|
616
|
+
const unsettled = await letPageReact('settle-after-reset');
|
|
617
|
+
if (unsettled !== undefined) {
|
|
618
|
+
return unsettled;
|
|
619
|
+
}
|
|
620
|
+
step = 'regrow-viewport';
|
|
621
|
+
}
|
|
622
|
+
const unreacted = (await page.growViewportToContent()) ? await letPageReact('frames-after-regrow') : undefined;
|
|
623
|
+
return unreacted ?? (await checkAssets('assets-after-regrow'));
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* Runs the story's wait hook, if it has one. Once it ran, checks its images and fonts again, then measures the page
|
|
627
|
+
* again for a full-page capture. Gives why the story isn't ready, or nothing when it is.
|
|
451
628
|
*/
|
|
452
629
|
const runWaitHook = async () => {
|
|
453
630
|
step = 'wait';
|
|
@@ -455,9 +632,10 @@ async function captureOnPage(page, story, settings) {
|
|
|
455
632
|
if (run.outcome === 'none') {
|
|
456
633
|
return undefined;
|
|
457
634
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
635
|
+
if (run.outcome !== 'done') {
|
|
636
|
+
return describeWaitHookRun(run, readyTimeout);
|
|
637
|
+
}
|
|
638
|
+
return (await checkAssets('assets-after-wait')) ?? (await regrowViewport());
|
|
461
639
|
};
|
|
462
640
|
/**
|
|
463
641
|
* Brings the story to its end state, and checks its images and fonts again when that changed anything. Gives why the
|
|
@@ -467,14 +645,14 @@ async function captureOnPage(page, story, settings) {
|
|
|
467
645
|
step = 'end-state';
|
|
468
646
|
const endState = readEndState(await waitInPage(endStateExpression));
|
|
469
647
|
if (endState.outcome !== 'settled') {
|
|
470
|
-
return describeEndState(endState,
|
|
648
|
+
return describeEndState(endState, readyTimeout);
|
|
471
649
|
}
|
|
472
650
|
return endState.changed ? await checkAssets('assets-after-end-state') : undefined;
|
|
473
651
|
};
|
|
474
652
|
/**
|
|
475
653
|
* Gets the finished story ready to capture: waits for its images and fonts, grows the viewport, runs its wait hook
|
|
476
|
-
* and brings it to its end state, stopping at the first that leaves it not
|
|
477
|
-
* or nothing when it is.
|
|
654
|
+
* and measures the page again after it, and brings it to its end state, stopping at the first that leaves it not
|
|
655
|
+
* ready. Gives why the story isn't ready, or nothing when it is.
|
|
478
656
|
*/
|
|
479
657
|
const getReady = async () => (await checkAssets('assets')) ?? (await growViewport()) ?? (await runWaitHook()) ?? (await bringToEndState());
|
|
480
658
|
/**
|
|
@@ -493,9 +671,14 @@ async function captureOnPage(page, story, settings) {
|
|
|
493
671
|
};
|
|
494
672
|
const prep = readCapturePrep(await waitInPage((limit) => prepareCaptureExpression(request, limit)));
|
|
495
673
|
if (prep.outcome !== 'ready') {
|
|
496
|
-
return { broken: describeCapturePrep(prep, element,
|
|
674
|
+
return { broken: describeCapturePrep(prep, element, readyTimeout) };
|
|
497
675
|
}
|
|
498
|
-
return {
|
|
676
|
+
return {
|
|
677
|
+
area: prep.box ?? 'full-page',
|
|
678
|
+
remote: request.findRemote ? prep.remote : undefined,
|
|
679
|
+
grid: prep.grid,
|
|
680
|
+
overflow: prep.overflow,
|
|
681
|
+
};
|
|
499
682
|
};
|
|
500
683
|
try {
|
|
501
684
|
await page.setViewport(story.viewport);
|
|
@@ -504,7 +687,7 @@ async function captureOnPage(page, story, settings) {
|
|
|
504
687
|
step = 'story';
|
|
505
688
|
const wait = readStoryWait(await waitInPage((limit) => storyWaitExpression(story.id, limit)));
|
|
506
689
|
if (wait.outcome !== 'finished') {
|
|
507
|
-
return brokenBy(describeStoryWait(wait,
|
|
690
|
+
return brokenBy(describeStoryWait(wait, readyTimeout));
|
|
508
691
|
}
|
|
509
692
|
const broken = await getReady();
|
|
510
693
|
if (broken !== undefined) {
|
|
@@ -518,6 +701,10 @@ async function captureOnPage(page, story, settings) {
|
|
|
518
701
|
if (gridBroken !== undefined) {
|
|
519
702
|
return brokenBy(gridBroken);
|
|
520
703
|
}
|
|
704
|
+
const overflowBroken = overflowProblemOf(prepared.overflow, prepared.area, story);
|
|
705
|
+
if (overflowBroken !== undefined) {
|
|
706
|
+
return brokenBy(overflowBroken);
|
|
707
|
+
}
|
|
521
708
|
step = 'capture';
|
|
522
709
|
const snapshot = await page.capture(prepared.area);
|
|
523
710
|
return {
|
|
@@ -534,7 +721,7 @@ async function captureOnPage(page, story, settings) {
|
|
|
534
721
|
if (error instanceof BrowserExitedError) {
|
|
535
722
|
throw error;
|
|
536
723
|
}
|
|
537
|
-
return brokenBy(describeFailure(error, step, story,
|
|
724
|
+
return brokenBy(describeFailure(error, step, story, readyTimeout));
|
|
538
725
|
}
|
|
539
726
|
}
|
|
540
727
|
/**
|
|
@@ -550,6 +737,7 @@ const imagedReasons = [
|
|
|
550
737
|
'wait-threw',
|
|
551
738
|
'element-missing',
|
|
552
739
|
'grid-too-wide',
|
|
740
|
+
'overflows',
|
|
553
741
|
];
|
|
554
742
|
/**
|
|
555
743
|
* Captures the full page of a story that just broke, as it is. Gives nothing when the capture fails or doesn't finish
|
|
@@ -588,26 +776,29 @@ async function withBrokenImage(page, story, settings, capture) {
|
|
|
588
776
|
* Calls the story's `captureAgainIf` with a snapshot just captured on the page, leaving the page as it is. When it
|
|
589
777
|
* resolves true, captures the area the snapshot was captured from again at once, doing nothing to the page in between,
|
|
590
778
|
* bound by the driver's own capture limit, and gives the snapshot with the second capture as `capturedAgain`. Gives the
|
|
591
|
-
* snapshot as it is when the story has no `captureAgainIf` or it resolves false.
|
|
592
|
-
*
|
|
593
|
-
*
|
|
594
|
-
*
|
|
779
|
+
* snapshot as it is when the story has no `captureAgainIf` or it resolves false. Either way the page errors are read
|
|
780
|
+
* again, so one the page raised during `captureAgainIf` counts. A second capture that fails comes back as a broken
|
|
781
|
+
* story, with the messages and page errors the page sent, read again, and the loads that failed on it. Rejects with a
|
|
782
|
+
* `BrowserExitedError` when the browser exits during the second capture, and with whatever `captureAgainIf` rejects
|
|
783
|
+
* with: it runs outside the handling that turns the page's failures into a broken story.
|
|
595
784
|
*/
|
|
596
785
|
async function captureAgainIfAsked(page, story, settings, captured) {
|
|
597
786
|
const again = await story.captureAgainIf?.(captured.result.snapshot);
|
|
598
787
|
if (again !== true) {
|
|
599
|
-
return captured.result;
|
|
788
|
+
return { ...captured.result, ...loadsReadOf(page, story) };
|
|
600
789
|
}
|
|
601
790
|
try {
|
|
602
|
-
|
|
791
|
+
const capturedAgain = await page.capture(captured.area);
|
|
792
|
+
return { ...captured.result, ...loadsReadOf(page, story), capturedAgain };
|
|
603
793
|
}
|
|
604
794
|
catch (error) {
|
|
605
795
|
if (error instanceof BrowserExitedError) {
|
|
606
796
|
throw error;
|
|
607
797
|
}
|
|
608
798
|
return {
|
|
609
|
-
broken: describeFailure(error, 'capture-again', story, settings.
|
|
799
|
+
broken: withFailedLoads(describeFailure(error, 'capture-again', story, readyTimeoutOf(story, settings)), page.failedLoads(), story.url),
|
|
610
800
|
console: page.consoleMessages(),
|
|
801
|
+
...loadsReadOf(page, story),
|
|
611
802
|
};
|
|
612
803
|
}
|
|
613
804
|
}
|
|
@@ -642,6 +833,11 @@ export function pageSetupOf(settings) {
|
|
|
642
833
|
* capture, set up with the settings, a user agent ending in `StorybookTestRunner` and the page script. After a broken
|
|
643
834
|
* story, it closes the page and opens a fresh one, in a fresh browser context, for the next story.
|
|
644
835
|
*
|
|
836
|
+
* A page watches its real network requests when the settings list hosts, or when the story it opens for asks with
|
|
837
|
+
* `watchRequests`. A story that asks, on a page that doesn't watch, gets a fresh page that does, the old one closed
|
|
838
|
+
* first. A page that watches is kept for the stories after it, since watching costs less than a fresh page, but only
|
|
839
|
+
* a story that asks gets the hosts of its real network requests, from every attempt, each once.
|
|
840
|
+
*
|
|
645
841
|
* Before each later capture on that page, it clears the cookies, `localStorage`, `sessionStorage` and IndexedDB the
|
|
646
842
|
* previous story left, keeping Cache Storage and service workers. The previous story's document stays loaded until the
|
|
647
843
|
* next story's commits, so a timer or handler of it can still write storage after the clearing. When the clearing
|
|
@@ -651,15 +847,21 @@ export function pageSetupOf(settings) {
|
|
|
651
847
|
* A story that navigates away is captured again at once, up to 2 more times, each on a fresh page in a fresh browser
|
|
652
848
|
* context. When the third attempt navigates away too, the story is broken, with that attempt's message and URL. Any
|
|
653
849
|
* other outcome of a retry, a snapshot or another broken reason, is the story's outcome, and no other reason is
|
|
654
|
-
* retried.
|
|
850
|
+
* retried. The capture keeps the page errors of every attempt, each once, in the order first seen, though only the
|
|
851
|
+
* last attempt's outcome counts.
|
|
655
852
|
*
|
|
656
853
|
* A story whose page shows a grid wider than the viewport, or too tall to capture, is broken with `grid-too-wide` or
|
|
657
|
-
* `too-tall` before anything is captured.
|
|
854
|
+
* `too-tall` before anything is captured. Then a story whose capture would cut content its page shows is broken with
|
|
855
|
+
* `overflows`, unless it sets `allowOverflow: true`.
|
|
856
|
+
*
|
|
857
|
+
* A broken story whose page couldn't load some of Storybook's own files at the network level, such as a connection the
|
|
858
|
+
* server dropped, keeps them as `failedLoads`, and its message gains a sentence naming the first and the browser's
|
|
859
|
+
* error, with how many there were when more than one. Its reason stays as it was, and nothing more is retried.
|
|
658
860
|
*
|
|
659
861
|
* A story that asks for it with `imageWhenBroken` and breaks while its page still shows something, for the reasons
|
|
660
|
-
* `error`, `play-threw`, `timeout`, `fonts-not-loaded`, `wait-threw`, `element-missing
|
|
661
|
-
* with an image of the full page, captured before the page is closed, unless that capture fails or
|
|
662
|
-
* the settings' `brokenImageTimeLimitMs`. A browser exit during it rejects the capture with a `BrowserExitedError`.
|
|
862
|
+
* `error`, `play-threw`, `timeout`, `fonts-not-loaded`, `wait-threw`, `element-missing`, `grid-too-wide` and
|
|
863
|
+
* `overflows`, comes with an image of the full page, captured before the page is closed, unless that capture fails or
|
|
864
|
+
* takes longer than the settings' `brokenImageTimeLimitMs`. A browser exit during it rejects the capture with a `BrowserExitedError`.
|
|
663
865
|
*
|
|
664
866
|
* When a story has `captureAgainIf`, each attempt that captured a snapshot calls it with the snapshot, the page left as
|
|
665
867
|
* it is, and captures the same area again at once when it resolves true. A second capture that fails makes the story
|
|
@@ -671,6 +873,7 @@ export function pageSetupOf(settings) {
|
|
|
671
873
|
export function openCaptureSession(driver, settings) {
|
|
672
874
|
const setup = pageSetupOf(settings);
|
|
673
875
|
let page;
|
|
876
|
+
let pageWatchesRequests = false;
|
|
674
877
|
const closePage = async () => {
|
|
675
878
|
const closing = page;
|
|
676
879
|
page = undefined;
|
|
@@ -702,7 +905,11 @@ export function openCaptureSession(driver, settings) {
|
|
|
702
905
|
*/
|
|
703
906
|
const captureOnOpenPage = async (story) => {
|
|
704
907
|
try {
|
|
705
|
-
page
|
|
908
|
+
if (page === undefined) {
|
|
909
|
+
const watchRequests = setup.watchRequests || story.watchRequests === true;
|
|
910
|
+
page = await driver.newPage({ ...setup, watchRequests });
|
|
911
|
+
pageWatchesRequests = watchRequests;
|
|
912
|
+
}
|
|
706
913
|
}
|
|
707
914
|
catch (error) {
|
|
708
915
|
if (error instanceof BrowserExitedError) {
|
|
@@ -713,6 +920,7 @@ export function openCaptureSession(driver, settings) {
|
|
|
713
920
|
reason: 'error',
|
|
714
921
|
message: `visual-check couldn't open a page for the story: ${failureReasonOf(error)}`,
|
|
715
922
|
},
|
|
923
|
+
pageErrors: [],
|
|
716
924
|
};
|
|
717
925
|
}
|
|
718
926
|
try {
|
|
@@ -737,12 +945,23 @@ export function openCaptureSession(driver, settings) {
|
|
|
737
945
|
};
|
|
738
946
|
return {
|
|
739
947
|
capture: async (story) => {
|
|
948
|
+
if (story.watchRequests === true && !pageWatchesRequests) {
|
|
949
|
+
await closePage();
|
|
950
|
+
}
|
|
740
951
|
await clearOpenPage();
|
|
741
952
|
let capture = await captureOnOpenPage(story);
|
|
953
|
+
const attempts = [capture];
|
|
742
954
|
for (let retry = 0; retry < navigatedAwayRetries && navigatedAway(capture); retry += 1) {
|
|
743
955
|
capture = await captureOnOpenPage(story);
|
|
956
|
+
attempts.push(capture);
|
|
744
957
|
}
|
|
745
|
-
return
|
|
958
|
+
return {
|
|
959
|
+
...capture,
|
|
960
|
+
pageErrors: eachPageErrorOnce(...attempts.map(({ pageErrors }) => pageErrors)),
|
|
961
|
+
...(story.watchRequests === true
|
|
962
|
+
? { requestHosts: [...new Set(attempts.flatMap(({ requestHosts }) => requestHosts ?? []))] }
|
|
963
|
+
: {}),
|
|
964
|
+
};
|
|
746
965
|
},
|
|
747
966
|
close: closePage,
|
|
748
967
|
};
|