| 886 | |
| 887 | // Wrap builder pattern function (returns value) to use() pattern |
| 888 | const fixture = async (ctx: any, use: (value: any) => Promise<void>) => { |
| 889 | let cleanup: (() => any) | undefined |
| 890 | const onCleanup = (fn: () => any) => { |
| 891 | if (cleanup !== undefined) { |
| 892 | throw new Error( |
| 893 | `onCleanup can only be called once per fixture. ` |
| 894 | + `Define separate fixtures if you need multiple cleanup functions.`, |
| 895 | ) |
| 896 | } |
| 897 | cleanup = fn |
| 898 | } |
| 899 | const value = await builderFn(ctx, { onCleanup }) |
| 900 | await use(value) |
| 901 | if (cleanup) { |
| 902 | await cleanup() |
| 903 | } |
| 904 | } |
| 905 | configureProps(fixture, { original: builderFn }) |
| 906 | |
| 907 | if (fixtureOptions) { |