MCPcopy
hub / github.com/vitest-dev/vitest / pollMatchDomain

Method pollMatchDomain

packages/snapshot/src/client.ts:265–346  ·  view source on GitHub ↗
(options: AssertDomainPollOptions)

Source from the content-addressed store, hash-verified

263 }
264
265 async pollMatchDomain(options: AssertDomainPollOptions): Promise<MatchResult> {
266 const {
267 poll,
268 filepath,
269 name,
270 testId = name,
271 message,
272 adapter,
273 isInline = false,
274 inlineSnapshot,
275 error,
276 timeout = 1000,
277 interval = 50,
278 } = options
279
280 if (!filepath) {
281 throw new Error('Snapshot cannot be used outside of test')
282 }
283
284 const snapshotState = this.getSnapshotState(filepath)
285 const testName = [name, ...(message ? [message] : [])].join(' > ')
286
287 const expectedSnapshot = snapshotState.probeExpectedSnapshot({
288 testName,
289 testId,
290 isInline,
291 inlineSnapshot,
292 })
293
294 const reference = expectedSnapshot.data && snapshotState.snapshotUpdateState !== 'all'
295 ? adapter.parseExpected(expectedSnapshot.data)
296 : undefined
297 const timedOut = timeout > 0
298 ? new Promise<void>(r => setTimeout(r, timeout))
299 : undefined
300 const stableResult = await getStableSnapshot({
301 adapter,
302 poll,
303 interval,
304 timedOut,
305 match: reference
306 ? captured => adapter.match(captured, reference).pass
307 : undefined,
308 })
309
310 expectedSnapshot.markAsChecked()
311
312 if (!stableResult?.rendered) {
313 // the original caller `expect.poll` later manipulates error via `throwWithCause`,
314 // so here we can directly throw `lastPollError` if exists.
315 if (stableResult?.lastPollError) {
316 throw stableResult.lastPollError
317 }
318 return {
319 pass: false,
320 message: () => `poll() did not produce a stable snapshot within the timeout`,
321 }
322 }

Callers 1

Calls 5

getSnapshotStateMethod · 0.95
getStableSnapshotFunction · 0.85
probeExpectedSnapshotMethod · 0.80
processDomainSnapshotMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected