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

Loading…
Cancel
Save