fix: evitar contaminación entre pruebas quitando fallback a currentDb

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
main
brobert 1 month ago
parent fc6f6d8128
commit 84a5b80cae

@ -36,8 +36,7 @@ export function getDb(): Database {
if (!testScope) testScope = new AsyncLocalStorage<Database>();
const scoped = testScope.getStore();
if (scoped) return scoped;
// En tests, permitir fallback a currentDb si está configurada explícitamente en el hook
if (currentDb) return currentDb;
// En tests, no hacemos fallback a currentDb para evitar contaminación entre suites
throw new DbNotConfiguredError('Database has not been configured. Call setDb(db) before using getDb().');
}
if (currentDb) return currentDb;
@ -49,10 +48,7 @@ export function getDb(): Database {
*/
export function resetDb(): void {
currentDb = null;
if (process.env.NODE_ENV === 'test') {
// Re-inicializar el almacenamiento para limpiar el store del contexto actual
testScope = new AsyncLocalStorage<Database>();
}
// En tests no tocamos testScope para no invalidar contextos de otras suites en paralelo
}
/**
@ -60,10 +56,7 @@ export function resetDb(): void {
*/
export function clearDb(): void {
currentDb = null;
if (process.env.NODE_ENV === 'test') {
// Re-inicializar el almacenamiento para limpiar el store del contexto actual
testScope = new AsyncLocalStorage<Database>();
}
// En tests no tocamos testScope para no invalidar contextos de otras suites en paralelo
}
/**

Loading…
Cancel
Save