| 300 | } |
| 301 | |
| 302 | export async function assertSnapshot( |
| 303 | snapshotsOrPage: eventWithTime[] | puppeteer.Page, |
| 304 | ) { |
| 305 | let snapshots: eventWithTime[]; |
| 306 | if (!Array.isArray(snapshotsOrPage)) { |
| 307 | // make sure page has finished executing js |
| 308 | await waitForRAF(snapshotsOrPage); |
| 309 | await snapshotsOrPage.waitForFunction( |
| 310 | 'window.snapshots && window.snapshots.length > 0', |
| 311 | ); |
| 312 | |
| 313 | snapshots = (await snapshotsOrPage.evaluate( |
| 314 | 'window.snapshots', |
| 315 | )) as eventWithTime[]; |
| 316 | } else { |
| 317 | snapshots = snapshotsOrPage; |
| 318 | } |
| 319 | |
| 320 | expect(snapshots).toBeDefined(); |
| 321 | expect(stringifySnapshots(snapshots)).toMatchSnapshot(); |
| 322 | } |
| 323 | |
| 324 | export function replaceLast(str: string, find: string, replace: string) { |
| 325 | const index = str.lastIndexOf(find); |