Skip to content
Source
Sign inSign up
TanStack/db
Open History to see the last commit

with-test-cleanup.ts

24 lines630 Bytes

1type Action = () => unknown | Promise<unknown>
2​
3/** Test resource teardown only; this carries no adapter or oracle semantics. */
4export async function withTestCleanup(body: Action, cleanups: Array<Action>) {
5 const failures: Array<unknown> = []
6 try {
7 await body()
8 } catch (error) {
9 failures.push(error)
10 }
11 for (const cleanup of cleanups) {
12 try {
13 await cleanup()
14 } catch (error) {
15 failures.push(error)
16 }
17 }
18 if (failures.length === 1) throw failures[0]
19 if (failures.length > 1) {
20 throw new AggregateError(failures, `Test and cleanup failed`, {
21 cause: failures[0],
22 })
23 }