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

Function serialize

packages/pretty-format/src/plugins/AsymmetricMatcher.ts:17–90  ·  view source on GitHub ↗
(
  val: any,
  config: Config,
  indentation: string,
  depth: number,
  refs: Refs,
  printer: Printer,
)

Source from the content-addressed store, hash-verified

15const SPACE = ' '
16
17export const serialize: NewPlugin['serialize'] = (
18 val: any,
19 config: Config,
20 indentation: string,
21 depth: number,
22 refs: Refs,
23 printer: Printer,
24) => {
25 const stringedValue = val.toString()
26
27 if (
28 stringedValue === 'ArrayContaining'
29 || stringedValue === 'ArrayNotContaining'
30 ) {
31 if (++depth > config.maxDepth) {
32 return `[${stringedValue}]`
33 }
34 return `${stringedValue + SPACE}[${printListItems(
35 val.sample,
36 config,
37 indentation,
38 depth,
39 refs,
40 printer,
41 )}]`
42 }
43
44 if (
45 stringedValue === 'ObjectContaining'
46 || stringedValue === 'ObjectNotContaining'
47 ) {
48 if (++depth > config.maxDepth) {
49 return `[${stringedValue}]`
50 }
51 return `${stringedValue + SPACE}{${printObjectProperties(
52 val.sample,
53 config,
54 indentation,
55 depth,
56 refs,
57 printer,
58 )}}`
59 }
60
61 if (
62 stringedValue === 'StringMatching'
63 || stringedValue === 'StringNotMatching'
64 ) {
65 return (
66 stringedValue
67 + SPACE
68 + printer(val.sample, config, indentation, depth, refs)
69 )
70 }
71
72 if (
73 stringedValue === 'StringContaining'
74 || stringedValue === 'StringNotContaining'

Callers

nothing calls this directly

Calls 5

printListItemsFunction · 0.90
printObjectPropertiesFunction · 0.90
printerFunction · 0.85
toStringMethod · 0.45
toAsymmetricMatcherMethod · 0.45

Tested by

no test coverage detected