(
collection: any,
testFn: (tracker: { stats: IndexUsageStats }) => void | Promise<void>,
)
| 168 | |
| 169 | // Helper to run a test with index usage tracking (automatically handles setup/cleanup) |
| 170 | function withIndexTracking( |
| 171 | collection: any, |
| 172 | testFn: (tracker: { stats: IndexUsageStats }) => void | Promise<void>, |
| 173 | ): void | Promise<void> { |
| 174 | const tracker = createIndexUsageTracker(collection) |
| 175 | |
| 176 | try { |
| 177 | const result = testFn(tracker) |
| 178 | if (result instanceof Promise) { |
| 179 | return result.finally(() => tracker.restore()) |
| 180 | } |
| 181 | tracker.restore() |
| 182 | } catch (error) { |
| 183 | tracker.restore() |
| 184 | throw error |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | const testData: Array<TestItem> = [ |
| 189 | { |
no test coverage detected