| 264 | * while preserving fixtures that were created for aroundEach itself. |
| 265 | */ |
| 266 | export async function callFixtureCleanupFrom(context: object, fromIndex: number): Promise<void> { |
| 267 | const cleanupFnArray = cleanupFnArrayMap.get(context) |
| 268 | if (!cleanupFnArray || cleanupFnArray.length <= fromIndex) { |
| 269 | return |
| 270 | } |
| 271 | // Get items added after the checkpoint |
| 272 | const toCleanup = cleanupFnArray.slice(fromIndex) |
| 273 | // Clean up in reverse order |
| 274 | for (const cleanup of toCleanup.reverse()) { |
| 275 | await cleanup() |
| 276 | } |
| 277 | // Remove cleaned up items from the array, keeping items before checkpoint |
| 278 | cleanupFnArray.length = fromIndex |
| 279 | } |
| 280 | |
| 281 | type SuiteHook = 'beforeAll' | 'afterAll' | 'aroundAll' |
| 282 | |