(
stats: IndexUsageStats,
expectations: {
shouldUseIndex: boolean
shouldUseFullScan?: boolean
indexCallCount?: number
fullScanCallCount?: number
},
)
| 156 | |
| 157 | // Helper to assert index usage |
| 158 | export function expectIndexUsage( |
| 159 | stats: IndexUsageStats, |
| 160 | expectations: { |
| 161 | shouldUseIndex: boolean |
| 162 | shouldUseFullScan?: boolean |
| 163 | indexCallCount?: number |
| 164 | fullScanCallCount?: number |
| 165 | }, |
| 166 | ) { |
| 167 | if (expectations.shouldUseIndex) { |
| 168 | expect(stats.rangeQueryCalls).toBeGreaterThan(0) |
| 169 | expect(stats.indexesUsed.length).toBeGreaterThan(0) |
| 170 | |
| 171 | if (expectations.indexCallCount !== undefined) { |
| 172 | expect(stats.rangeQueryCalls).toBe(expectations.indexCallCount) |
| 173 | } |
| 174 | } else { |
| 175 | expect(stats.rangeQueryCalls).toBe(0) |
| 176 | expect(stats.indexesUsed.length).toBe(0) |
| 177 | } |
| 178 | |
| 179 | if (expectations.shouldUseFullScan !== undefined) { |
| 180 | if (expectations.shouldUseFullScan) { |
| 181 | expect(stats.fullScanCalls).toBeGreaterThan(0) |
| 182 | |
| 183 | if (expectations.fullScanCallCount !== undefined) { |
| 184 | expect(stats.fullScanCalls).toBe(expectations.fullScanCallCount) |
| 185 | } |
| 186 | } else { |
| 187 | expect(stats.fullScanCalls).toBe(0) |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | // Helper to run a test with index usage tracking (automatically handles setup/cleanup) |
| 193 | export function withIndexTracking( |
no test coverage detected