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

Function loadSnapshotSerializers

packages/vitest/src/runtime/setup-common.ts:71–102  ·  view source on GitHub ↗
(
  config: SerializedConfig,
  moduleRunner: PublicModuleRunner,
)

Source from the content-addressed store, hash-verified

69}
70
71export async function loadSnapshotSerializers(
72 config: SerializedConfig,
73 moduleRunner: PublicModuleRunner,
74): Promise<void> {
75 const files = config.snapshotSerializers
76
77 const snapshotSerializers = await Promise.all(
78 files.map(async (file) => {
79 const mo = await moduleRunner.import(file)
80 if (!mo || typeof mo.default !== 'object' || mo.default === null) {
81 throw new Error(
82 `invalid snapshot serializer file ${file}. Must export a default object`,
83 )
84 }
85
86 const config = mo.default
87 if (
88 typeof config.test !== 'function'
89 || (typeof config.serialize !== 'function'
90 && typeof config.print !== 'function')
91 ) {
92 throw new TypeError(
93 `invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`,
94 )
95 }
96
97 return config as SnapshotSerializer
98 }),
99 )
100
101 snapshotSerializers.forEach(serializer => addSerializer(serializer))
102}

Callers 2

resolveTestRunnerFunction · 0.90
initiateRunnerFunction · 0.85

Calls 3

addSerializerFunction · 0.90
allMethod · 0.80
importMethod · 0.45

Tested by

no test coverage detected