(
options: CreateTestSetupOptions = {},
)
| 134 | * ``` |
| 135 | */ |
| 136 | export function createTestSetup( |
| 137 | options: CreateTestSetupOptions = {}, |
| 138 | ): TestSetupResult { |
| 139 | const { |
| 140 | analytics = true, |
| 141 | crypto = true, |
| 142 | database = false, |
| 143 | dbModule, |
| 144 | analyticsModule, |
| 145 | cryptoPrefix = 'test', |
| 146 | } = options |
| 147 | |
| 148 | const logger = createMockLogger() |
| 149 | let analyticsSpy: AnalyticsSpies | undefined |
| 150 | let cryptoSpy: CryptoMockSpies | undefined |
| 151 | let dbSpy: DbSpies | undefined |
| 152 | |
| 153 | const beforeEach = (): void => { |
| 154 | // Reset tool call ID counter for deterministic tests |
| 155 | resetToolCallIdCounter() |
| 156 | |
| 157 | // Set up analytics mocks |
| 158 | if (analytics && analyticsModule) { |
| 159 | analyticsSpy = setupAnalyticsMocks(analyticsModule) |
| 160 | } |
| 161 | |
| 162 | // Set up crypto mocks |
| 163 | if (crypto) { |
| 164 | cryptoSpy = setupCryptoMocks({ prefix: cryptoPrefix, sequential: true }) |
| 165 | } |
| 166 | |
| 167 | // Set up database mocks |
| 168 | if (database && dbModule) { |
| 169 | dbSpy = setupDbSpies(dbModule) |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | const afterEach = (): void => { |
| 174 | // Restore all mocks |
| 175 | analyticsSpy?.restore() |
| 176 | cryptoSpy?.restore() |
| 177 | dbSpy?.restore() |
| 178 | |
| 179 | // Reset the spies |
| 180 | analyticsSpy = undefined |
| 181 | cryptoSpy = undefined |
| 182 | dbSpy = undefined |
| 183 | } |
| 184 | |
| 185 | const restore = afterEach |
| 186 | |
| 187 | return { |
| 188 | logger, |
| 189 | get analyticsSpy() { |
| 190 | return analyticsSpy |
| 191 | }, |
| 192 | get cryptoSpy() { |
| 193 | return cryptoSpy |
nothing calls this directly
no test coverage detected