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

test-cleanup.ts

23 lines766 Bytes

1/** Release every test resource while retaining each cleanup failure. */
2export async function cleanupTestActions(
3 actions: Array<() => void | Promise<unknown>>,
4 hasPrimaryFailure: boolean,
5 label: string,
6 runAction: (
7 action: () => void | Promise<unknown>,
8 index: number,
9 ) => Promise<unknown> = async (action) => action(),
10): Promise<void> {
11 const failures: Array<unknown> = []
12 for (const [index, action] of actions.entries()) {
13 try {
14 await runAction(action, index)
15 } catch (error) {
16 failures.push(error)
17 }
18 }
19 if (!failures.length) return
20 if (hasPrimaryFailure)
21 console.warn(`${label} cleanup failed after the primary failure:`, failures)
22 else throw new AggregateError(failures, `${label} cleanup failed`)