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

Method matchDomain

packages/snapshot/src/client.ts:214–263  ·  view source on GitHub ↗
(options: AssertDomainOptions)

Source from the content-addressed store, hash-verified

212 }
213
214 matchDomain(options: AssertDomainOptions): MatchResult {
215 const {
216 received,
217 filepath,
218 name,
219 testId = name,
220 message,
221 adapter,
222 isInline = false,
223 inlineSnapshot,
224 error,
225 } = options
226
227 if (!filepath) {
228 throw new Error('Snapshot cannot be used outside of test')
229 }
230
231 const captured = adapter.capture(received)
232 const rendered = adapter.render(captured)
233
234 const snapshotState = this.getSnapshotState(filepath)
235 const testName = [name, ...(message ? [message] : [])].join(' > ')
236
237 const expectedSnapshot = snapshotState.probeExpectedSnapshot({
238 testName,
239 testId,
240 isInline,
241 inlineSnapshot,
242 })
243 expectedSnapshot.markAsChecked()
244 const matchResult = expectedSnapshot.data
245 ? adapter.match(captured, adapter.parseExpected(expectedSnapshot.data))
246 : undefined
247 const { actual, expected, key, pass } = snapshotState.processDomainSnapshot({
248 testId,
249 received: rendered,
250 expectedSnapshot,
251 matchResult,
252 isInline,
253 error,
254 assertionName: options.assertionName,
255 })
256
257 return {
258 pass,
259 message: () => `Snapshot \`${key}\` mismatched`,
260 actual: actual?.trim(),
261 expected: expected?.trim(),
262 }
263 }
264
265 async pollMatchDomain(options: AssertDomainPollOptions): Promise<MatchResult> {
266 const {

Callers 1

Calls 6

getSnapshotStateMethod · 0.95
captureMethod · 0.80
probeExpectedSnapshotMethod · 0.80
processDomainSnapshotMethod · 0.80
renderMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected