test: add deterministic task behaviour tests
This commit is contained in:
16
lib/db.ts
16
lib/db.ts
@@ -21,6 +21,12 @@ export function getDatabase() {
|
||||
return globalDatabase.plannerDatabase;
|
||||
}
|
||||
|
||||
if (globalDatabase.plannerDatabase) {
|
||||
globalDatabase.plannerDatabase.close();
|
||||
delete globalDatabase.plannerDatabase;
|
||||
delete globalDatabase.plannerDatabasePath;
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(databasePath), { recursive: true });
|
||||
|
||||
const database = new DatabaseSync(databasePath);
|
||||
@@ -34,3 +40,13 @@ export function getDatabase() {
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
export function closeDatabaseForTests() {
|
||||
const globalDatabase = globalThis as DatabaseGlobal;
|
||||
|
||||
if (globalDatabase.plannerDatabase) {
|
||||
globalDatabase.plannerDatabase.close();
|
||||
delete globalDatabase.plannerDatabase;
|
||||
delete globalDatabase.plannerDatabasePath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user