(
stats: IndexUsageStats,
expectations: {
shouldUseIndex: boolean
shouldUseFullScan?: boolean
indexCallCount?: number
fullScanCallCount?: number
},
)
| 133 | |
| 134 | // Helper to assert index usage |
| 135 | function expectIndexUsage( |
| 136 | stats: IndexUsageStats, |
| 137 | expectations: { |
| 138 | shouldUseIndex: boolean |
| 139 | shouldUseFullScan?: boolean |
| 140 | indexCallCount?: number |
| 141 | fullScanCallCount?: number |
| 142 | }, |
| 143 | ) { |
| 144 | if (expectations.shouldUseIndex) { |
| 145 | expect(stats.rangeQueryCalls).toBeGreaterThan(0) |
| 146 | expect(stats.indexesUsed.length).toBeGreaterThan(0) |
| 147 | |
| 148 | if (expectations.indexCallCount !== undefined) { |
| 149 | expect(stats.rangeQueryCalls).toBe(expectations.indexCallCount) |
| 150 | } |
| 151 | } else { |
| 152 | expect(stats.rangeQueryCalls).toBe(0) |
| 153 | expect(stats.indexesUsed.length).toBe(0) |
| 154 | } |
| 155 | |
| 156 | if (expectations.shouldUseFullScan !== undefined) { |
| 157 | if (expectations.shouldUseFullScan) { |
| 158 | expect(stats.fullScanCalls).toBeGreaterThan(0) |
| 159 | |
| 160 | if (expectations.fullScanCallCount !== undefined) { |
| 161 | expect(stats.fullScanCalls).toBe(expectations.fullScanCallCount) |
| 162 | } |
| 163 | } else { |
| 164 | expect(stats.fullScanCalls).toBe(0) |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | // Helper to run a test with index usage tracking (automatically handles setup/cleanup) |
| 170 | function withIndexTracking( |
no test coverage detected
searching dependent graphs…