@visual-check/cli 0.1.1 → 0.2.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.
Files changed (219) hide show
  1. package/dist/addon-child/image-files.js +1 -1
  2. package/dist/addon-child/image-files.js.map +1 -1
  3. package/dist/agent-skill/skill-files.d.ts +4 -0
  4. package/dist/agent-skill/skill-files.d.ts.map +1 -1
  5. package/dist/agent-skill/skill-files.js +4 -0
  6. package/dist/agent-skill/skill-files.js.map +1 -1
  7. package/dist/baselines/baseline-error.d.ts +15 -2
  8. package/dist/baselines/baseline-error.d.ts.map +1 -1
  9. package/dist/baselines/baseline-error.js +32 -2
  10. package/dist/baselines/baseline-error.js.map +1 -1
  11. package/dist/capture/capture-session.d.ts +161 -30
  12. package/dist/capture/capture-session.d.ts.map +1 -1
  13. package/dist/capture/capture-session.js +284 -64
  14. package/dist/capture/capture-session.js.map +1 -1
  15. package/dist/capture/driver/cdp/cdp-page.d.ts.map +1 -1
  16. package/dist/capture/driver/cdp/cdp-page.js +120 -31
  17. package/dist/capture/driver/cdp/cdp-page.js.map +1 -1
  18. package/dist/capture/driver/cdp/failed-loads.d.ts +16 -0
  19. package/dist/capture/driver/cdp/failed-loads.d.ts.map +1 -0
  20. package/dist/capture/driver/cdp/failed-loads.js +71 -0
  21. package/dist/capture/driver/cdp/failed-loads.js.map +1 -0
  22. package/dist/capture/driver/cdp/launch-arguments.d.ts +7 -1
  23. package/dist/capture/driver/cdp/launch-arguments.d.ts.map +1 -1
  24. package/dist/capture/driver/cdp/launch-arguments.js +8 -1
  25. package/dist/capture/driver/cdp/launch-arguments.js.map +1 -1
  26. package/dist/capture/driver/driver.d.ts +88 -4
  27. package/dist/capture/driver/driver.d.ts.map +1 -1
  28. package/dist/capture/driver/driver.js +33 -0
  29. package/dist/capture/driver/driver.js.map +1 -1
  30. package/dist/capture/end-state.d.ts +3 -5
  31. package/dist/capture/end-state.d.ts.map +1 -1
  32. package/dist/capture/end-state.js +7 -43
  33. package/dist/capture/end-state.js.map +1 -1
  34. package/dist/capture/frames.d.ts +18 -0
  35. package/dist/capture/frames.d.ts.map +1 -0
  36. package/dist/capture/frames.js +54 -0
  37. package/dist/capture/frames.js.map +1 -0
  38. package/dist/capture/page-script.d.ts +34 -1
  39. package/dist/capture/page-script.d.ts.map +1 -1
  40. package/dist/capture/page-script.js +58 -2
  41. package/dist/capture/page-script.js.map +1 -1
  42. package/dist/capture/prepare-capture.d.ts +50 -3
  43. package/dist/capture/prepare-capture.d.ts.map +1 -1
  44. package/dist/capture/prepare-capture.js +157 -16
  45. package/dist/capture/prepare-capture.js.map +1 -1
  46. package/dist/commands/check-storybooks.d.ts +5 -4
  47. package/dist/commands/check-storybooks.d.ts.map +1 -1
  48. package/dist/commands/check-storybooks.js +11 -8
  49. package/dist/commands/check-storybooks.js.map +1 -1
  50. package/dist/commands/consistency-output.d.ts.map +1 -1
  51. package/dist/commands/consistency-output.js +3 -3
  52. package/dist/commands/consistency-output.js.map +1 -1
  53. package/dist/commands/failed-loads-hint.d.ts +7 -0
  54. package/dist/commands/failed-loads-hint.d.ts.map +1 -0
  55. package/dist/commands/failed-loads-hint.js +16 -0
  56. package/dist/commands/failed-loads-hint.js.map +1 -0
  57. package/dist/commands/local-update.d.ts +22 -0
  58. package/dist/commands/local-update.d.ts.map +1 -0
  59. package/dist/commands/local-update.js +39 -0
  60. package/dist/commands/local-update.js.map +1 -0
  61. package/dist/commands/network-warning.d.ts.map +1 -1
  62. package/dist/commands/network-warning.js +2 -18
  63. package/dist/commands/network-warning.js.map +1 -1
  64. package/dist/commands/plan-snapshots.d.ts +23 -8
  65. package/dist/commands/plan-snapshots.d.ts.map +1 -1
  66. package/dist/commands/plan-snapshots.js +15 -9
  67. package/dist/commands/plan-snapshots.js.map +1 -1
  68. package/dist/commands/report-entries.d.ts +5 -2
  69. package/dist/commands/report-entries.d.ts.map +1 -1
  70. package/dist/commands/report-entries.js +63 -15
  71. package/dist/commands/report-entries.js.map +1 -1
  72. package/dist/commands/run-browser.d.ts +5 -5
  73. package/dist/commands/run-browser.d.ts.map +1 -1
  74. package/dist/commands/run-browser.js +1 -0
  75. package/dist/commands/run-browser.js.map +1 -1
  76. package/dist/commands/run-cli.d.ts +16 -5
  77. package/dist/commands/run-cli.d.ts.map +1 -1
  78. package/dist/commands/run-cli.js +74 -54
  79. package/dist/commands/run-cli.js.map +1 -1
  80. package/dist/commands/run-report.d.ts +3 -3
  81. package/dist/commands/run-report.d.ts.map +1 -1
  82. package/dist/commands/run-report.js +4 -2
  83. package/dist/commands/run-report.js.map +1 -1
  84. package/dist/commands/run-snapshots.d.ts +7 -4
  85. package/dist/commands/run-snapshots.d.ts.map +1 -1
  86. package/dist/commands/run-snapshots.js +49 -17
  87. package/dist/commands/run-snapshots.js.map +1 -1
  88. package/dist/commands/snapshot-result.d.ts +66 -9
  89. package/dist/commands/snapshot-result.d.ts.map +1 -1
  90. package/dist/commands/snapshot-result.js +46 -6
  91. package/dist/commands/snapshot-result.js.map +1 -1
  92. package/dist/commands/stop-message.d.ts.map +1 -1
  93. package/dist/commands/stop-message.js +6 -1
  94. package/dist/commands/stop-message.js.map +1 -1
  95. package/dist/commands/stopped-run.d.ts +10 -5
  96. package/dist/commands/stopped-run.d.ts.map +1 -1
  97. package/dist/commands/stopped-run.js +35 -22
  98. package/dist/commands/stopped-run.js.map +1 -1
  99. package/dist/commands/take-snapshot.d.ts +9 -6
  100. package/dist/commands/take-snapshot.d.ts.map +1 -1
  101. package/dist/commands/take-snapshot.js +16 -7
  102. package/dist/commands/take-snapshot.js.map +1 -1
  103. package/dist/commands/test-snapshot.d.ts +2 -2
  104. package/dist/commands/test-snapshot.d.ts.map +1 -1
  105. package/dist/commands/test-snapshot.js.map +1 -1
  106. package/dist/commands/update-baselines.d.ts.map +1 -1
  107. package/dist/commands/update-baselines.js +3 -2
  108. package/dist/commands/update-baselines.js.map +1 -1
  109. package/dist/commands/update-snapshot.d.ts +22 -4
  110. package/dist/commands/update-snapshot.d.ts.map +1 -1
  111. package/dist/commands/update-snapshot.js +79 -18
  112. package/dist/commands/update-snapshot.js.map +1 -1
  113. package/dist/config/checks.d.ts +26 -0
  114. package/dist/config/checks.d.ts.map +1 -1
  115. package/dist/config/checks.js +68 -6
  116. package/dist/config/checks.js.map +1 -1
  117. package/dist/config/define-config.d.ts +38 -2
  118. package/dist/config/define-config.d.ts.map +1 -1
  119. package/dist/config/define-config.js.map +1 -1
  120. package/dist/config/resolve-config.d.ts +15 -2
  121. package/dist/config/resolve-config.d.ts.map +1 -1
  122. package/dist/config/resolve-config.js +6 -0
  123. package/dist/config/resolve-config.js.map +1 -1
  124. package/dist/config/story-options.d.ts +32 -4
  125. package/dist/config/story-options.d.ts.map +1 -1
  126. package/dist/config/story-options.js +38 -7
  127. package/dist/config/story-options.js.map +1 -1
  128. package/dist/config/unrunnable-regexp.d.ts +22 -0
  129. package/dist/config/unrunnable-regexp.d.ts.map +1 -0
  130. package/dist/config/unrunnable-regexp.js +25 -0
  131. package/dist/config/unrunnable-regexp.js.map +1 -0
  132. package/dist/config/validate-config.d.ts.map +1 -1
  133. package/dist/config/validate-config.js +6 -21
  134. package/dist/config/validate-config.js.map +1 -1
  135. package/dist/index.d.ts +3 -3
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js.map +1 -1
  138. package/dist/init/find-storybooks.d.ts +5 -0
  139. package/dist/init/find-storybooks.d.ts.map +1 -1
  140. package/dist/init/find-storybooks.js +8 -1
  141. package/dist/init/find-storybooks.js.map +1 -1
  142. package/dist/init/ignored-skill.d.ts +50 -0
  143. package/dist/init/ignored-skill.d.ts.map +1 -0
  144. package/dist/init/ignored-skill.js +61 -0
  145. package/dist/init/ignored-skill.js.map +1 -0
  146. package/dist/init/install.d.ts +24 -9
  147. package/dist/init/install.d.ts.map +1 -1
  148. package/dist/init/install.js +66 -26
  149. package/dist/init/install.js.map +1 -1
  150. package/dist/init/package-manager.d.ts +6 -0
  151. package/dist/init/package-manager.d.ts.map +1 -1
  152. package/dist/init/package-manager.js +4 -0
  153. package/dist/init/package-manager.js.map +1 -1
  154. package/dist/init/run-init.d.ts +17 -4
  155. package/dist/init/run-init.d.ts.map +1 -1
  156. package/dist/init/run-init.js +31 -11
  157. package/dist/init/run-init.js.map +1 -1
  158. package/dist/init/workspace.d.ts +2 -0
  159. package/dist/init/workspace.d.ts.map +1 -1
  160. package/dist/init/workspace.js +2 -0
  161. package/dist/init/workspace.js.map +1 -1
  162. package/dist/page-errors/judge-page-errors.d.ts +50 -0
  163. package/dist/page-errors/judge-page-errors.d.ts.map +1 -0
  164. package/dist/page-errors/judge-page-errors.js +39 -0
  165. package/dist/page-errors/judge-page-errors.js.map +1 -0
  166. package/dist/page-errors/page-error-policy.d.ts +36 -0
  167. package/dist/page-errors/page-error-policy.d.ts.map +1 -0
  168. package/dist/page-errors/page-error-policy.js +15 -0
  169. package/dist/page-errors/page-error-policy.js.map +1 -0
  170. package/dist/real-network-requests/judge-real-requests.d.ts +26 -0
  171. package/dist/real-network-requests/judge-real-requests.d.ts.map +1 -0
  172. package/dist/real-network-requests/judge-real-requests.js +17 -0
  173. package/dist/real-network-requests/judge-real-requests.js.map +1 -0
  174. package/dist/real-network-requests/real-request-policy.d.ts +29 -0
  175. package/dist/real-network-requests/real-request-policy.d.ts.map +1 -0
  176. package/dist/real-network-requests/real-request-policy.js +10 -0
  177. package/dist/real-network-requests/real-request-policy.js.map +1 -0
  178. package/dist/real-network-requests/silenced-hosts.d.ts +9 -0
  179. package/dist/real-network-requests/silenced-hosts.d.ts.map +1 -0
  180. package/dist/real-network-requests/silenced-hosts.js +28 -0
  181. package/dist/real-network-requests/silenced-hosts.js.map +1 -0
  182. package/dist/report/report-document.d.ts +154 -9
  183. package/dist/report/report-document.d.ts.map +1 -1
  184. package/dist/report/report-document.js +1 -1
  185. package/dist/report/report-document.js.map +1 -1
  186. package/dist/report/report-folder.d.ts +7 -3
  187. package/dist/report/report-folder.d.ts.map +1 -1
  188. package/dist/report/report-folder.js +5 -5
  189. package/dist/report/report-folder.js.map +1 -1
  190. package/dist/reporter/end-block.d.ts +32 -3
  191. package/dist/reporter/end-block.d.ts.map +1 -1
  192. package/dist/reporter/end-block.js +55 -3
  193. package/dist/reporter/end-block.js.map +1 -1
  194. package/dist/reporter/page-errors-block.d.ts +52 -0
  195. package/dist/reporter/page-errors-block.d.ts.map +1 -0
  196. package/dist/reporter/page-errors-block.js +98 -0
  197. package/dist/reporter/page-errors-block.js.map +1 -0
  198. package/dist/reporter/real-requests-block.d.ts +33 -0
  199. package/dist/reporter/real-requests-block.d.ts.map +1 -0
  200. package/dist/reporter/real-requests-block.js +53 -0
  201. package/dist/reporter/real-requests-block.js.map +1 -0
  202. package/dist/step-summary/step-summary.d.ts +27 -7
  203. package/dist/step-summary/step-summary.d.ts.map +1 -1
  204. package/dist/step-summary/step-summary.js +107 -15
  205. package/dist/step-summary/step-summary.js.map +1 -1
  206. package/dist/storybook/options-encoding.d.ts +18 -5
  207. package/dist/storybook/options-encoding.d.ts.map +1 -1
  208. package/dist/storybook/options-encoding.js +12 -4
  209. package/dist/storybook/options-encoding.js.map +1 -1
  210. package/dist/storybook/options-read.d.ts +3 -2
  211. package/dist/storybook/options-read.d.ts.map +1 -1
  212. package/dist/storybook/options-read.js +17 -0
  213. package/dist/storybook/options-read.js.map +1 -1
  214. package/dist/storybook/read-stories.d.ts +15 -0
  215. package/dist/storybook/read-stories.d.ts.map +1 -1
  216. package/dist/storybook/read-stories.js +60 -14
  217. package/dist/storybook/read-stories.js.map +1 -1
  218. package/package.json +2 -1
  219. 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, pageInitScript, prepareCaptureExpression, readAssetsReadiness, } from './page-script.js';
6
+ import { assetsReadyExpression, endStateExpression, framesAfterGrowthExpression, 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,13 @@ 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
+ 'frames-after-regrow': 'the viewport set again after its wait hook',
25
+ };
19
26
  /**
20
27
  * What each step does, as a phrase that follows "while".
21
28
  */
@@ -25,9 +32,13 @@ const stepNames = {
25
32
  story: 'waiting for the story to finish',
26
33
  assets: 'waiting for images and fonts',
27
34
  'grow-viewport': 'growing the viewport to the page',
35
+ 'frames-after-grow': 'letting the page react to the grown viewport',
28
36
  'assets-after-grow': 'waiting for images and fonts after growing the viewport',
29
37
  wait: "running the story's wait hook",
30
38
  'assets-after-wait': 'waiting for images and fonts after its wait hook',
39
+ 'regrow-viewport': 'growing the viewport to the page again after its wait hook',
40
+ 'frames-after-regrow': 'letting the page react to the viewport set again after its wait hook',
41
+ 'assets-after-regrow': 'waiting for images and fonts once the viewport was set again after its wait hook',
31
42
  'end-state': 'bringing the story to its end state',
32
43
  'assets-after-end-state': 'waiting for images and fonts after its end state',
33
44
  masks: 'painting its masks and hiding the caret',
@@ -41,9 +52,12 @@ const stepTimeouts = {
41
52
  load: 'its page was still loading',
42
53
  story: 'its page stopped answering while visual-check waited for the story to finish',
43
54
  assets: 'its page stopped answering while visual-check waited for its images and fonts',
55
+ 'frames-after-grow': 'its page stopped answering while visual-check let it react to the grown viewport',
44
56
  'assets-after-grow': 'its page stopped answering while visual-check waited for its images and fonts after growing the viewport',
45
57
  wait: 'its page stopped answering while its wait hook ran',
46
58
  'assets-after-wait': 'its page stopped answering while visual-check waited for its images and fonts after its wait hook',
59
+ 'frames-after-regrow': 'its page stopped answering while visual-check let it react to the viewport set again after its wait hook',
60
+ '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',
47
61
  'end-state': 'its page stopped answering while visual-check brought it to its end state',
48
62
  'assets-after-end-state': 'its page stopped answering while visual-check waited for its images and fonts after its end state',
49
63
  masks: 'its page stopped answering while visual-check painted its masks and hid the caret',
@@ -55,6 +69,7 @@ const assetsCheckSuffixes = {
55
69
  assets: '',
56
70
  'assets-after-grow': ' after growing the viewport',
57
71
  'assets-after-wait': ' after its wait hook',
72
+ 'assets-after-regrow': ' once the viewport was set again after its wait hook',
58
73
  'assets-after-end-state': ' after its end state',
59
74
  };
60
75
  /**
@@ -65,13 +80,52 @@ const endStateTimeouts = {
65
80
  media: 'visual-check was still putting its media on their first frame',
66
81
  };
67
82
  /**
68
- * Gives a story that wasn't ready within readyTimeout, saying what it was doing.
83
+ * Gives the broken story with the loads of Storybook's own files that failed at the network level on its page, and a
84
+ * sentence at the end of its message naming the first, its path shown against the story's URL, and how many there were
85
+ * when more than one. A `play-threw` story whose error Storybook described as nothing keeps the message without that
86
+ * sentence as its error text, for the report's play details. Gives it as it is when none failed.
87
+ */
88
+ function withFailedLoads(broken, failedLoads, storyUrl) {
89
+ const [first] = failedLoads;
90
+ if (first === undefined) {
91
+ return broken;
92
+ }
93
+ const path = displayUrlOf(first.url, storyUrl);
94
+ const files = failedLoads.length === 1
95
+ ? `${path} from Storybook`
96
+ : `${failedLoads.length} files from Storybook, the first ${path}`;
97
+ return {
98
+ ...broken,
99
+ ...(broken.reason === 'play-threw' && broken.errorText === '' ? { errorText: broken.message } : {}),
100
+ message: `${broken.message} Its page couldn't load ${files}: ${first.error}.`,
101
+ failedLoads,
102
+ };
103
+ }
104
+ /**
105
+ * Gives the readyTimeout a story's capture runs under: the story's own when it sets one, else the settings'.
69
106
  */
70
- function notReady(readyTimeoutMs, doing) {
107
+ function readyTimeoutOf(story, settings) {
108
+ if (story.readyTimeoutMs === undefined) {
109
+ return { ms: settings.readyTimeoutMs, setIn: 'config' };
110
+ }
111
+ return { ms: story.readyTimeoutMs, setIn: 'story' };
112
+ }
113
+ /**
114
+ * Names a readyTimeout in a message: how long it is and where it was set.
115
+ */
116
+ function readyTimeoutText({ ms, setIn }) {
117
+ const where = setIn === 'story' ? "the story's parameters.visualCheck" : 'the config';
118
+ return `readyTimeout (${ms} ms, from ${where})`;
119
+ }
120
+ /**
121
+ * Gives a story that wasn't ready within its readyTimeout, saying what it was doing.
122
+ */
123
+ function notReady(readyTimeout, doing) {
71
124
  return {
72
125
  reason: 'timeout',
73
- message: `The story wasn't ready within readyTimeout (${readyTimeoutMs} ms): ${doing}.`,
74
- readyTimeoutMs,
126
+ message: `The story wasn't ready within ${readyTimeoutText(readyTimeout)}: ${doing}.`,
127
+ readyTimeoutMs: readyTimeout.ms,
128
+ readyTimeoutSetIn: readyTimeout.setIn,
75
129
  };
76
130
  }
77
131
  /**
@@ -116,14 +170,14 @@ function stillWaitingFor(wait) {
116
170
  /**
117
171
  * Says why a story isn't ready to capture, from what the story wait found.
118
172
  */
119
- function describeStoryWait(wait, readyTimeoutMs) {
173
+ function describeStoryWait(wait, readyTimeout) {
120
174
  switch (wait.outcome) {
121
175
  case 'play-threw':
122
176
  return { reason: 'play-threw', message: wait.message, errorText: wait.errorText, stack: wait.stack };
123
177
  case 'errored':
124
178
  return { reason: 'error', message: wait.message };
125
179
  case 'timed-out':
126
- return notReady(readyTimeoutMs, stillWaitingFor(wait));
180
+ return notReady(readyTimeout, stillWaitingFor(wait));
127
181
  case 'script-missing':
128
182
  return {
129
183
  reason: 'error',
@@ -144,7 +198,7 @@ function imagesStillLoading(pending) {
144
198
  * Says why a story isn't ready to capture, from what a check of its images and fonts found. `suffix` follows what the
145
199
  * message says the story was doing, so it names the check.
146
200
  */
147
- function describeAssetsWait(assets, readyTimeoutMs, suffix) {
201
+ function describeAssetsWait(assets, readyTimeout, suffix) {
148
202
  if (assets.outcome === 'script-missing') {
149
203
  return {
150
204
  reason: 'error',
@@ -152,35 +206,49 @@ function describeAssetsWait(assets, readyTimeoutMs, suffix) {
152
206
  };
153
207
  }
154
208
  if (assets.step === 'images') {
155
- return notReady(readyTimeoutMs, `${imagesStillLoading(assets.pending)}${suffix}`);
209
+ return notReady(readyTimeout, `${imagesStillLoading(assets.pending)}${suffix}`);
156
210
  }
157
211
  const faces = assets.pendingFaces;
158
212
  if (faces.length === 0) {
159
- return notReady(readyTimeoutMs, `document.fonts.ready hadn't resolved${suffix}`);
213
+ return notReady(readyTimeout, `document.fonts.ready hadn't resolved${suffix}`);
160
214
  }
161
215
  return {
162
216
  reason: 'fonts-not-loaded',
163
- message: `The story's fonts hadn't loaded within readyTimeout (${readyTimeoutMs} ms)${suffix}. Still loading: ${faces.join(', ')}.`,
217
+ message: `The story's fonts hadn't loaded within ${readyTimeoutText(readyTimeout)}${suffix}. Still loading: ${faces.join(', ')}.`,
164
218
  faces,
165
- readyTimeoutMs,
219
+ readyTimeoutMs: readyTimeout.ms,
220
+ readyTimeoutSetIn: readyTimeout.setIn,
166
221
  };
167
222
  }
223
+ /**
224
+ * Says why a story isn't ready to capture, from what letting frames pass found in the wait `framesStep` names: once the
225
+ * viewport grew, or once it was set again after the wait hook.
226
+ */
227
+ function describeFrames(frames, readyTimeout, framesStep) {
228
+ if (frames.outcome === 'script-missing') {
229
+ return {
230
+ reason: 'error',
231
+ 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]}.`,
232
+ };
233
+ }
234
+ return notReady(readyTimeout, `visual-check was still letting the page react to ${framesTargets[framesStep]}`);
235
+ }
168
236
  /**
169
237
  * Says why a story isn't ready to capture, from what bringing it to its end state found.
170
238
  */
171
- function describeEndState(endState, readyTimeoutMs) {
239
+ function describeEndState(endState, readyTimeout) {
172
240
  if (endState.outcome === 'script-missing') {
173
241
  return {
174
242
  reason: 'error',
175
243
  message: "visual-check's page script didn't run in the story's page, so it couldn't bring it to its end state.",
176
244
  };
177
245
  }
178
- return notReady(readyTimeoutMs, endStateTimeouts[endState.step]);
246
+ return notReady(readyTimeout, endStateTimeouts[endState.step]);
179
247
  }
180
248
  /**
181
249
  * Says why a story can't be captured, from what preparing its capture found. `element` is the story's element selector.
182
250
  */
183
- function describeCapturePrep(prep, element, readyTimeoutMs) {
251
+ function describeCapturePrep(prep, element, readyTimeout) {
184
252
  switch (prep.outcome) {
185
253
  case 'element-missing':
186
254
  return {
@@ -197,7 +265,7 @@ function describeCapturePrep(prep, element, readyTimeoutMs) {
197
265
  : `The selector of mask ${JSON.stringify(prep.name)} isn't valid CSS: ${failureReasonOf(prep.message)}`,
198
266
  };
199
267
  case 'timed-out':
200
- return notReady(readyTimeoutMs, 'visual-check was still looking for remote content to mask');
268
+ return notReady(readyTimeout, 'visual-check was still looking for remote content to mask');
201
269
  case 'script-missing':
202
270
  return {
203
271
  reason: 'error',
@@ -213,14 +281,14 @@ function describeCapturePrep(prep, element, readyTimeoutMs) {
213
281
  /**
214
282
  * Says why a story isn't ready to capture, from what running its wait hook found.
215
283
  */
216
- function describeWaitHookRun(run, readyTimeoutMs) {
284
+ function describeWaitHookRun(run, readyTimeout) {
217
285
  switch (run.outcome) {
218
286
  case 'threw':
219
287
  return { reason: 'wait-threw', message: run.message };
220
288
  case 'context-failed':
221
289
  return { reason: 'error', message: run.message };
222
290
  case 'timed-out':
223
- return notReady(readyTimeoutMs, "its wait hook hadn't finished");
291
+ return notReady(readyTimeout, "its wait hook hadn't finished");
224
292
  case 'no-render':
225
293
  return {
226
294
  reason: 'error',
@@ -239,7 +307,7 @@ function describeWaitHookRun(run, readyTimeoutMs) {
239
307
  * capture: the hint says to set `element` for the full page, or to capture a smaller element. `story` shows a URL on
240
308
  * the story's own origin as a path.
241
309
  */
242
- function describeFailure(error, step, story, readyTimeoutMs) {
310
+ function describeFailure(error, step, story, readyTimeout) {
243
311
  if (error instanceof PageCrashedError) {
244
312
  return {
245
313
  reason: 'crashed',
@@ -263,7 +331,7 @@ function describeFailure(error, step, story, readyTimeoutMs) {
263
331
  }
264
332
  const doing = stepTimeouts[step];
265
333
  if (error instanceof PageTimeoutError && doing !== undefined) {
266
- return notReady(readyTimeoutMs, doing);
334
+ return notReady(readyTimeout, doing);
267
335
  }
268
336
  const name = stepNames[step];
269
337
  return {
@@ -342,6 +410,63 @@ export function gridProblemOf(grid, viewport) {
342
410
  size: { width: deviceWidth, height: deviceHeight },
343
411
  };
344
412
  }
413
+ /**
414
+ * Says how far content reaches past each edge that counts, such as `12 px past the page's top edge`, from pairs of a
415
+ * distance in CSS pixels and an edge. An edge whose distance is 0 doesn't count.
416
+ */
417
+ function edgePhrasesOf(edges) {
418
+ return edges.filter(([distance]) => distance > 0).map(([distance, edge]) => `${distance} px past ${edge}`);
419
+ }
420
+ /**
421
+ * Says how far an element's capture would cut content, as a sentence of at most two clauses: first the element past
422
+ * the page's top and left edges, then its content past its right and bottom edges, each clause naming only the sides
423
+ * that count. The content's clause names the element when it comes first. Two clauses are joined with `, and` when
424
+ * either names two sides, and with `and` otherwise.
425
+ */
426
+ function elementOverflowSentenceOf({ top, right, bottom, left }) {
427
+ const pageEdges = edgePhrasesOf([
428
+ [top, "the page's top edge"],
429
+ [left, top > 0 ? 'its left edge' : "the page's left edge"],
430
+ ]);
431
+ const contentEdges = edgePhrasesOf([
432
+ [right, 'its right edge'],
433
+ [bottom, 'its bottom edge'],
434
+ ]);
435
+ const contentSubject = pageEdges.length > 0 ? 'its content' : "the element's content";
436
+ const clauses = [
437
+ { subject: 'the element', edges: pageEdges },
438
+ { subject: contentSubject, edges: contentEdges },
439
+ ]
440
+ .filter(({ edges }) => edges.length > 0)
441
+ .map(({ subject, edges }) => `${subject} reaches ${edges.join(' and ')}`);
442
+ const sentence = clauses.join(pageEdges.length > 1 || contentEdges.length > 1 ? ', and ' : ' and ');
443
+ return `${sentence.charAt(0).toUpperCase()}${sentence.slice(1)}`;
444
+ }
445
+ /**
446
+ * Says why a story whose capture would cut content its page shows can't be captured, or gives nothing when it would cut
447
+ * nothing or the story sets `allowOverflow: true`. For the full page, it names how far content reaches past the
448
+ * viewport's right edge; for an element's box, each side that counts. `area` is what the capture takes, and the
449
+ * story's viewport is the snapshot's: its mode's when it has one.
450
+ */
451
+ export function overflowProblemOf(overflow, area, story) {
452
+ if (overflow === undefined || story.allowOverflow === true) {
453
+ return undefined;
454
+ }
455
+ const viewportWidth = story.viewport.width;
456
+ const { top, right, bottom, left } = overflow;
457
+ if (area === 'full-page') {
458
+ return {
459
+ reason: 'overflows',
460
+ 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.`,
461
+ overflow: { area: 'full-page', top, right, bottom, left, viewportWidth },
462
+ };
463
+ }
464
+ return {
465
+ reason: 'overflows',
466
+ 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.`,
467
+ overflow: { area: 'element', top, right, bottom, left, viewportWidth },
468
+ };
469
+ }
345
470
  /**
346
471
  * What a snapshot comes with besides its bytes, read right after the capture: the remote content it shows, in pixels
347
472
  * of its image, when the story asked for it with `findRemoteContent` and the page gave it, and the hosts the story
@@ -359,33 +484,50 @@ function capturedExtrasOf(page, story, settings, prepared) {
359
484
  ...(hosts === undefined ? {} : { hosts }),
360
485
  };
361
486
  }
487
+ /**
488
+ * What an attempt reads of its page's loads once it's done: the page errors, and the hosts of the real network requests
489
+ * when the story asks for them with `watchRequests`.
490
+ */
491
+ function loadsReadOf(page, story) {
492
+ return {
493
+ pageErrors: page.pageErrors(),
494
+ ...(story.watchRequests === true ? { requestHosts: page.requestHosts() } : {}),
495
+ };
496
+ }
362
497
  /**
363
498
  * Captures a story on an open page: sets the story's viewport, loads the story, waits until Storybook reports it
364
499
  * finished with nothing gone wrong, waits for its images and fonts, grows the viewport to the page for a full-page
365
- * capture, runs its wait hook, brings it to its end state, measures its element, paints its masks, hides the caret and
366
- * captures the element's box, or the full page when the story has no element. When the viewport grew, its images and
367
- * fonts are checked again, when the story has a wait hook, they're checked again after it, and when the end state
368
- * changed anything, they're checked again before the masks. Loading, the waits, the hook, the end state,
369
- * those checks and the masks share readyTimeout, each getting only what's left of it. When the story asks for it with
370
- * `findRemoteContent`, the snapshot comes with the remote content it shows, unless the search didn't answer in time.
500
+ * capture, runs its wait hook, measures the page again for a full-page capture once its wait hook ran, brings it to its
501
+ * end state, measures its element, paints its masks, hides the caret and captures the element's box, or the full page
502
+ * when the story has no element. When the viewport grew, two frames pass so the page reacts to the new size, then its
503
+ * images and fonts are checked again. When the story's wait hook ran, they're checked again after it, then, for a
504
+ * full-page capture, the story's viewport is set again and grows to the page, two frames pass whether it grew or not,
505
+ * and they're checked again. When the end state changed anything, they're checked again before the masks.
506
+ * Loading, the waits, the frames, the hook, the end state, those checks and the masks share readyTimeout, the story's
507
+ * 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.
371
508
  * When the settings ask to list hosts, it also gives the hosts the page sent requests to, read once the capture is
372
509
  * done, and the hosts of the remote content the story shows, from the same search as the host masks. A story whose page
373
510
  * shows a grid wider than the viewport, or too tall to capture, is broken before anything is captured, as
374
- * `gridProblemOf` says. Gives the area the snapshot was captured from beside it, and leaves the story's
375
- * `captureAgainIf` to the caller. A story that can't be captured comes back as a broken story. Either way it comes with
511
+ * `gridProblemOf` says. Then one whose capture would cut content its page shows is broken, as `overflowProblemOf` says,
512
+ * unless it sets `allowOverflow: true`; a capture too tall is only found as it's taken, after that. Gives the area the
513
+ * 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
376
514
  * the console messages and errors the page sent, read once the capture is done or the story broke, while the page is
377
- * still open. Rejects only with a `BrowserExitedError`.
515
+ * still open, and a broken story with the loads of Storybook's files that failed on the page and its page errors. A
516
+ * snapshot's page errors are left to the caller, read once `captureAgainIf` ran. Rejects only with a
517
+ * `BrowserExitedError`.
378
518
  */
379
519
  async function captureOnPage(page, story, settings) {
380
- const deadline = performance.now() + settings.readyTimeoutMs;
520
+ const readyTimeout = readyTimeoutOf(story, settings);
521
+ const deadline = performance.now() + readyTimeout.ms;
381
522
  const timeLeft = () => Math.max(0, Math.ceil(deadline - performance.now()));
382
523
  let step = 'viewport';
383
524
  /**
384
- * Gives the broken story with the messages the page sent.
525
+ * Gives the broken story with the messages the page sent and the loads of Storybook's files that failed on it.
385
526
  */
386
527
  const brokenBy = (broken) => ({
387
- broken,
528
+ broken: withFailedLoads(broken, page.failedLoads(), story.url),
388
529
  console: page.consoleMessages(),
530
+ ...loadsReadOf(page, story),
389
531
  });
390
532
  /**
391
533
  * Evaluates a wait in the page, built by `expressionFor` for what's left of readyTimeout, and gives the page's
@@ -405,22 +547,58 @@ async function captureOnPage(page, story, settings) {
405
547
  if (assets.outcome === 'ready') {
406
548
  return undefined;
407
549
  }
408
- return describeAssetsWait(assets, settings.readyTimeoutMs, assetsCheckSuffixes[assetsStep]);
550
+ return describeAssetsWait(assets, readyTimeout, assetsCheckSuffixes[assetsStep]);
409
551
  };
410
552
  /**
411
- * Grows the viewport's height to the page's for a full-page capture, unless the story turns that off, and checks its
412
- * images and fonts again when it grew. Gives why the story isn't ready, or nothing when it is.
553
+ * Whether the capture is of the full page with the viewport's growth on: the viewport grows to the page before the
554
+ * wait hook and is measured again after a hook that ran.
555
+ */
556
+ const growsViewport = story.element === undefined && story.growViewport !== false;
557
+ /**
558
+ * Lets two frames pass once the viewport grew or was set again, as `framesStep` names, so the page reacts to its
559
+ * size: its observers and `resize` listeners call back and the render they cause is done. Gives why the story isn't
560
+ * ready, or nothing when it is.
561
+ */
562
+ const letPageReact = async (framesStep) => {
563
+ step = framesStep;
564
+ const frames = readFramesPassed(await waitInPage(framesAfterGrowthExpression));
565
+ return frames.outcome === 'passed' ? undefined : describeFrames(frames, readyTimeout, framesStep);
566
+ };
567
+ /**
568
+ * Grows the viewport's height to the page's for a full-page capture, unless the story turns that off. When it grew,
569
+ * lets the page react to the new size, then checks its images and fonts again. Gives why the story isn't ready, or
570
+ * nothing when it is.
413
571
  */
414
572
  const growViewport = async () => {
415
- if (story.element !== undefined || story.growViewport === false) {
573
+ if (!growsViewport) {
416
574
  return undefined;
417
575
  }
418
576
  step = 'grow-viewport';
419
- return (await page.growViewportToContent()) ? await checkAssets('assets-after-grow') : undefined;
577
+ if (!(await page.growViewportToContent())) {
578
+ return undefined;
579
+ }
580
+ return (await letPageReact('frames-after-grow')) ?? (await checkAssets('assets-after-grow'));
581
+ };
582
+ /**
583
+ * Measures the page again once the story's wait hook ran, for a full-page capture with the growth on: sets the
584
+ * story's own viewport again, so a `min-height: 100vh` page doesn't keep its last growth, and grows it to the
585
+ * page's height when the page is taller. A page the hook made shorter shrinks back, and one too tall to capture
586
+ * stays at the story's viewport. Then lets two frames pass, whether it grew or not, since setting the viewport
587
+ * fires `resize` too, and checks the images and fonts again. Gives why the story isn't ready, or nothing when it
588
+ * is.
589
+ */
590
+ const regrowViewport = async () => {
591
+ if (!growsViewport) {
592
+ return undefined;
593
+ }
594
+ step = 'regrow-viewport';
595
+ await page.setViewport(story.viewport);
596
+ await page.growViewportToContent();
597
+ return (await letPageReact('frames-after-regrow')) ?? (await checkAssets('assets-after-regrow'));
420
598
  };
421
599
  /**
422
- * Runs the story's wait hook, if it has one, and checks its images and fonts again once it ran. Gives why the story
423
- * isn't ready, or nothing when it is.
600
+ * Runs the story's wait hook, if it has one. Once it ran, checks its images and fonts again, then measures the page
601
+ * again for a full-page capture. Gives why the story isn't ready, or nothing when it is.
424
602
  */
425
603
  const runWaitHook = async () => {
426
604
  step = 'wait';
@@ -428,9 +606,10 @@ async function captureOnPage(page, story, settings) {
428
606
  if (run.outcome === 'none') {
429
607
  return undefined;
430
608
  }
431
- return run.outcome === 'done'
432
- ? await checkAssets('assets-after-wait')
433
- : describeWaitHookRun(run, settings.readyTimeoutMs);
609
+ if (run.outcome !== 'done') {
610
+ return describeWaitHookRun(run, readyTimeout);
611
+ }
612
+ return (await checkAssets('assets-after-wait')) ?? (await regrowViewport());
434
613
  };
435
614
  /**
436
615
  * Brings the story to its end state, and checks its images and fonts again when that changed anything. Gives why the
@@ -440,14 +619,14 @@ async function captureOnPage(page, story, settings) {
440
619
  step = 'end-state';
441
620
  const endState = readEndState(await waitInPage(endStateExpression));
442
621
  if (endState.outcome !== 'settled') {
443
- return describeEndState(endState, settings.readyTimeoutMs);
622
+ return describeEndState(endState, readyTimeout);
444
623
  }
445
624
  return endState.changed ? await checkAssets('assets-after-end-state') : undefined;
446
625
  };
447
626
  /**
448
627
  * Gets the finished story ready to capture: waits for its images and fonts, grows the viewport, runs its wait hook
449
- * and brings it to its end state, stopping at the first that leaves it not ready. Gives why the story isn't ready,
450
- * or nothing when it is.
628
+ * and measures the page again after it, and brings it to its end state, stopping at the first that leaves it not
629
+ * ready. Gives why the story isn't ready, or nothing when it is.
451
630
  */
452
631
  const getReady = async () => (await checkAssets('assets')) ?? (await growViewport()) ?? (await runWaitHook()) ?? (await bringToEndState());
453
632
  /**
@@ -466,9 +645,14 @@ async function captureOnPage(page, story, settings) {
466
645
  };
467
646
  const prep = readCapturePrep(await waitInPage((limit) => prepareCaptureExpression(request, limit)));
468
647
  if (prep.outcome !== 'ready') {
469
- return { broken: describeCapturePrep(prep, element, settings.readyTimeoutMs) };
648
+ return { broken: describeCapturePrep(prep, element, readyTimeout) };
470
649
  }
471
- return { area: prep.box ?? 'full-page', remote: request.findRemote ? prep.remote : undefined, grid: prep.grid };
650
+ return {
651
+ area: prep.box ?? 'full-page',
652
+ remote: request.findRemote ? prep.remote : undefined,
653
+ grid: prep.grid,
654
+ overflow: prep.overflow,
655
+ };
472
656
  };
473
657
  try {
474
658
  await page.setViewport(story.viewport);
@@ -477,7 +661,7 @@ async function captureOnPage(page, story, settings) {
477
661
  step = 'story';
478
662
  const wait = readStoryWait(await waitInPage((limit) => storyWaitExpression(story.id, limit)));
479
663
  if (wait.outcome !== 'finished') {
480
- return brokenBy(describeStoryWait(wait, settings.readyTimeoutMs));
664
+ return brokenBy(describeStoryWait(wait, readyTimeout));
481
665
  }
482
666
  const broken = await getReady();
483
667
  if (broken !== undefined) {
@@ -491,6 +675,10 @@ async function captureOnPage(page, story, settings) {
491
675
  if (gridBroken !== undefined) {
492
676
  return brokenBy(gridBroken);
493
677
  }
678
+ const overflowBroken = overflowProblemOf(prepared.overflow, prepared.area, story);
679
+ if (overflowBroken !== undefined) {
680
+ return brokenBy(overflowBroken);
681
+ }
494
682
  step = 'capture';
495
683
  const snapshot = await page.capture(prepared.area);
496
684
  return {
@@ -507,7 +695,7 @@ async function captureOnPage(page, story, settings) {
507
695
  if (error instanceof BrowserExitedError) {
508
696
  throw error;
509
697
  }
510
- return brokenBy(describeFailure(error, step, story, settings.readyTimeoutMs));
698
+ return brokenBy(describeFailure(error, step, story, readyTimeout));
511
699
  }
512
700
  }
513
701
  /**
@@ -523,6 +711,7 @@ const imagedReasons = [
523
711
  'wait-threw',
524
712
  'element-missing',
525
713
  'grid-too-wide',
714
+ 'overflows',
526
715
  ];
527
716
  /**
528
717
  * Captures the full page of a story that just broke, as it is. Gives nothing when the capture fails or doesn't finish
@@ -561,26 +750,29 @@ async function withBrokenImage(page, story, settings, capture) {
561
750
  * Calls the story's `captureAgainIf` with a snapshot just captured on the page, leaving the page as it is. When it
562
751
  * resolves true, captures the area the snapshot was captured from again at once, doing nothing to the page in between,
563
752
  * bound by the driver's own capture limit, and gives the snapshot with the second capture as `capturedAgain`. Gives the
564
- * snapshot as it is when the story has no `captureAgainIf` or it resolves false. A second capture that fails comes back
565
- * as a broken story, with the messages the page sent, read again. Rejects with a `BrowserExitedError` when the browser
566
- * exits during the second capture, and with whatever `captureAgainIf` rejects with: it runs outside the handling that
567
- * turns the page's failures into a broken story.
753
+ * snapshot as it is when the story has no `captureAgainIf` or it resolves false. Either way the page errors are read
754
+ * again, so one the page raised during `captureAgainIf` counts. A second capture that fails comes back as a broken
755
+ * story, with the messages and page errors the page sent, read again, and the loads that failed on it. Rejects with a
756
+ * `BrowserExitedError` when the browser exits during the second capture, and with whatever `captureAgainIf` rejects
757
+ * with: it runs outside the handling that turns the page's failures into a broken story.
568
758
  */
569
759
  async function captureAgainIfAsked(page, story, settings, captured) {
570
760
  const again = await story.captureAgainIf?.(captured.result.snapshot);
571
761
  if (again !== true) {
572
- return captured.result;
762
+ return { ...captured.result, ...loadsReadOf(page, story) };
573
763
  }
574
764
  try {
575
- return { ...captured.result, capturedAgain: await page.capture(captured.area) };
765
+ const capturedAgain = await page.capture(captured.area);
766
+ return { ...captured.result, ...loadsReadOf(page, story), capturedAgain };
576
767
  }
577
768
  catch (error) {
578
769
  if (error instanceof BrowserExitedError) {
579
770
  throw error;
580
771
  }
581
772
  return {
582
- broken: describeFailure(error, 'capture-again', story, settings.readyTimeoutMs),
773
+ broken: withFailedLoads(describeFailure(error, 'capture-again', story, readyTimeoutOf(story, settings)), page.failedLoads(), story.url),
583
774
  console: page.consoleMessages(),
775
+ ...loadsReadOf(page, story),
584
776
  };
585
777
  }
586
778
  }
@@ -615,6 +807,11 @@ export function pageSetupOf(settings) {
615
807
  * capture, set up with the settings, a user agent ending in `StorybookTestRunner` and the page script. After a broken
616
808
  * story, it closes the page and opens a fresh one, in a fresh browser context, for the next story.
617
809
  *
810
+ * A page watches its real network requests when the settings list hosts, or when the story it opens for asks with
811
+ * `watchRequests`. A story that asks, on a page that doesn't watch, gets a fresh page that does, the old one closed
812
+ * first. A page that watches is kept for the stories after it, since watching costs less than a fresh page, but only
813
+ * a story that asks gets the hosts of its real network requests, from every attempt, each once.
814
+ *
618
815
  * Before each later capture on that page, it clears the cookies, `localStorage`, `sessionStorage` and IndexedDB the
619
816
  * previous story left, keeping Cache Storage and service workers. The previous story's document stays loaded until the
620
817
  * next story's commits, so a timer or handler of it can still write storage after the clearing. When the clearing
@@ -624,15 +821,21 @@ export function pageSetupOf(settings) {
624
821
  * A story that navigates away is captured again at once, up to 2 more times, each on a fresh page in a fresh browser
625
822
  * context. When the third attempt navigates away too, the story is broken, with that attempt's message and URL. Any
626
823
  * other outcome of a retry, a snapshot or another broken reason, is the story's outcome, and no other reason is
627
- * retried.
824
+ * retried. The capture keeps the page errors of every attempt, each once, in the order first seen, though only the
825
+ * last attempt's outcome counts.
628
826
  *
629
827
  * A story whose page shows a grid wider than the viewport, or too tall to capture, is broken with `grid-too-wide` or
630
- * `too-tall` before anything is captured.
828
+ * `too-tall` before anything is captured. Then a story whose capture would cut content its page shows is broken with
829
+ * `overflows`, unless it sets `allowOverflow: true`.
830
+ *
831
+ * A broken story whose page couldn't load some of Storybook's own files at the network level, such as a connection the
832
+ * server dropped, keeps them as `failedLoads`, and its message gains a sentence naming the first and the browser's
833
+ * error, with how many there were when more than one. Its reason stays as it was, and nothing more is retried.
631
834
  *
632
835
  * A story that asks for it with `imageWhenBroken` and breaks while its page still shows something, for the reasons
633
- * `error`, `play-threw`, `timeout`, `fonts-not-loaded`, `wait-threw`, `element-missing` and `grid-too-wide`, comes
634
- * with an image of the full page, captured before the page is closed, unless that capture fails or takes longer than
635
- * the settings' `brokenImageTimeLimitMs`. A browser exit during it rejects the capture with a `BrowserExitedError`.
836
+ * `error`, `play-threw`, `timeout`, `fonts-not-loaded`, `wait-threw`, `element-missing`, `grid-too-wide` and
837
+ * `overflows`, comes with an image of the full page, captured before the page is closed, unless that capture fails or
838
+ * takes longer than the settings' `brokenImageTimeLimitMs`. A browser exit during it rejects the capture with a `BrowserExitedError`.
636
839
  *
637
840
  * When a story has `captureAgainIf`, each attempt that captured a snapshot calls it with the snapshot, the page left as
638
841
  * it is, and captures the same area again at once when it resolves true. A second capture that fails makes the story
@@ -644,6 +847,7 @@ export function pageSetupOf(settings) {
644
847
  export function openCaptureSession(driver, settings) {
645
848
  const setup = pageSetupOf(settings);
646
849
  let page;
850
+ let pageWatchesRequests = false;
647
851
  const closePage = async () => {
648
852
  const closing = page;
649
853
  page = undefined;
@@ -675,7 +879,11 @@ export function openCaptureSession(driver, settings) {
675
879
  */
676
880
  const captureOnOpenPage = async (story) => {
677
881
  try {
678
- page ??= await driver.newPage(setup);
882
+ if (page === undefined) {
883
+ const watchRequests = setup.watchRequests || story.watchRequests === true;
884
+ page = await driver.newPage({ ...setup, watchRequests });
885
+ pageWatchesRequests = watchRequests;
886
+ }
679
887
  }
680
888
  catch (error) {
681
889
  if (error instanceof BrowserExitedError) {
@@ -686,6 +894,7 @@ export function openCaptureSession(driver, settings) {
686
894
  reason: 'error',
687
895
  message: `visual-check couldn't open a page for the story: ${failureReasonOf(error)}`,
688
896
  },
897
+ pageErrors: [],
689
898
  };
690
899
  }
691
900
  try {
@@ -710,12 +919,23 @@ export function openCaptureSession(driver, settings) {
710
919
  };
711
920
  return {
712
921
  capture: async (story) => {
922
+ if (story.watchRequests === true && !pageWatchesRequests) {
923
+ await closePage();
924
+ }
713
925
  await clearOpenPage();
714
926
  let capture = await captureOnOpenPage(story);
927
+ const attempts = [capture];
715
928
  for (let retry = 0; retry < navigatedAwayRetries && navigatedAway(capture); retry += 1) {
716
929
  capture = await captureOnOpenPage(story);
930
+ attempts.push(capture);
717
931
  }
718
- return capture;
932
+ return {
933
+ ...capture,
934
+ pageErrors: eachPageErrorOnce(...attempts.map(({ pageErrors }) => pageErrors)),
935
+ ...(story.watchRequests === true
936
+ ? { requestHosts: [...new Set(attempts.flatMap(({ requestHosts }) => requestHosts ?? []))] }
937
+ : {}),
938
+ };
719
939
  },
720
940
  close: closePage,
721
941
  };