release: WRNexusJS 0.8.0
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
closeDatabases,
|
||||
} from "../src/index.ts";
|
||||
import { sqlite } from "../src/adapters/sqlite.ts";
|
||||
import type { Db } from "../src/index.ts";
|
||||
|
||||
test("multi-database registry: default + named connections", async () => {
|
||||
await closeDatabases(); // isolate from any prior state
|
||||
@@ -78,3 +79,16 @@ test("closing the registry does not instantiate unused lazy databases", async ()
|
||||
await closeDatabases();
|
||||
expect(calls).toBe(0);
|
||||
});
|
||||
|
||||
test("registry closes every database and clears itself when one close fails", async () => {
|
||||
await closeDatabases();
|
||||
let secondClosed = false;
|
||||
const broken = { close: async () => Promise.reject(new Error("close failed")) } as Db;
|
||||
const healthy = { close: () => void (secondClosed = true) } as Db;
|
||||
setDb(broken);
|
||||
registerDb("healthy", healthy);
|
||||
|
||||
await expect(closeDatabases()).rejects.toThrow("databases failed to close");
|
||||
expect(secondClosed).toBe(true);
|
||||
expect(databaseNames()).toEqual([]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user