Description
Describe the bug
@keyv/sqlite
does not properly close the client when disconnect
is called, it just fetches the function:
keyv/packages/sqlite/src/index.ts
Line 72 in 10f2081
To fix, simply add parentheses: database => database.close()
.
There is a test for this, but it does not catch the issue because it is implemented incorrectly:
keyv/packages/sqlite/test/test.ts
Lines 112 to 124 in 10f2081
The await keyv.get('foo');
does not throw, then the t.expect.fail();
does throw, then the catch
catches the error and ignores it - so the try catch will just always pass.
One possible solution is replace the try-catch block with:
await t.expect(() => keyv.get('foo')).rejects.toThrow();
How To Reproduce (best to provide workable code or tests!)
The following should throw, it does not:
import Keyv from 'keyv';
import { KeyvSqlite } from '@keyv/sqlite';
const sqliteTest = new Keyv(new KeyvSqlite());
console.log(await sqliteTest.has('key'));
await sqliteTest.disconnect();
console.log(await sqliteTest.has('key'));
If you add the parentheses to close the connection properly, it will then throw.