(page: Page, asset: string)
| 227 | const docShots = getDocShotMap(); |
| 228 | |
| 229 | const expectDocShot = async (page: Page, asset: string): Promise<void> => { |
| 230 | const shot = docShots.get(asset); |
| 231 | if (shot == null) { |
| 232 | throw new Error(`No doc shot metadata found for ${asset}`); |
| 233 | } |
| 234 | expect(normalizePath(new URL(page.url()).pathname)).toEqual( |
| 235 | normalizePath(shot.page), |
| 236 | ); |
| 237 | |
| 238 | const frameLocator = shot.framed ? page.locator('iframe').first() : undefined; |
| 239 | |
| 240 | if (shot.framed) { |
| 241 | await prepareFirstFrame(page); |
| 242 | } |
| 243 | |
| 244 | await applyDocShotStyle(page, shot); |
| 245 | await waitForDocShotReady(page, shot); |
| 246 | await waitForDocShotImages(page, shot); |
| 247 | await performDocShotClicks(page, shot); |
| 248 | await stabilizeDocShot(page, shot); |
| 249 | |
| 250 | const locator = shot.framed |
| 251 | ? await expectedFramedElement(page, shot.selector) |
| 252 | : await expectedElement(page, shot.selector); |
| 253 | const clip = await getClip(page, locator, shot.marginRem, frameLocator); |
| 254 | |
| 255 | if (shot.framed) { |
| 256 | // Keep the framed capture path aligned with the known-good one-off flow: |
| 257 | // a full-page render here stabilizes the later clipped screenshot. |
| 258 | await page.screenshot({ |
| 259 | fullPage: true, |
| 260 | animations: 'disabled', |
| 261 | caret: 'hide', |
| 262 | omitBackground: shot.omitBackground, |
| 263 | scale: 'device', |
| 264 | style: shot.style, |
| 265 | }); |
| 266 | } |
| 267 | |
| 268 | const normalizedScreenshot = await page.screenshot({ |
| 269 | animations: 'disabled', |
| 270 | caret: 'hide', |
| 271 | clip, |
| 272 | omitBackground: shot.omitBackground, |
| 273 | scale: 'device', |
| 274 | style: shot.style, |
| 275 | }); |
| 276 | const snapshotPath = test.info().snapshotPath(...shot.asset.split('/')); |
| 277 | |
| 278 | if (process.env.UPDATE_DOC_SHOTS == '1') { |
| 279 | mkdirSync(dirname(snapshotPath), {recursive: true}); |
| 280 | writeFileSync(snapshotPath, normalizedScreenshot); |
| 281 | } |
| 282 | |
| 283 | expect(normalizedScreenshot).toMatchSnapshot(shot.asset.split('/')); |
| 284 | }; |
| 285 | |
| 286 | const {afterAll, beforeAll, describe} = test; |
no test coverage detected
searching dependent graphs…