MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / createTestSetup

Function createTestSetup

common/src/testing/setup.ts:136–202  ·  view source on GitHub ↗
(
  options: CreateTestSetupOptions = {},
)

Source from the content-addressed store, hash-verified

134 * ```
135 */
136export 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

Callers

nothing calls this directly

Calls 1

createMockLoggerFunction · 0.90

Tested by

no test coverage detected