MCPcopy Index your code
hub / github.com/tinyplex/tinybase / expectDocShot

Function expectDocShot

test/e2e/doc-shots.test.ts:229–284  ·  view source on GitHub ↗
(page: Page, asset: string)

Source from the content-addressed store, hash-verified

227const docShots = getDocShotMap();
228
229const 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
286const {afterAll, beforeAll, describe} = test;

Callers 1

doc-shots.test.tsFile · 0.85

Calls 11

expectedFramedElementFunction · 0.90
expectedElementFunction · 0.90
normalizePathFunction · 0.85
prepareFirstFrameFunction · 0.85
applyDocShotStyleFunction · 0.85
waitForDocShotReadyFunction · 0.85
waitForDocShotImagesFunction · 0.85
performDocShotClicksFunction · 0.85
stabilizeDocShotFunction · 0.85
getClipFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…