( config: SerializedConfig, moduleRunner: PublicModuleRunner, )
| 69 | } |
| 70 | |
| 71 | export 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 | } |
no test coverage detected