mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
testing/javascript: Clean up after test runs
This commit is contained in:
@@ -4,7 +4,7 @@ import fs from 'fs';
|
||||
|
||||
|
||||
test.beforeEach(async (t) => {
|
||||
const [db, errorType] = await connect();
|
||||
const [db, path,errorType] = await connect();
|
||||
await db.exec(`
|
||||
DROP TABLE IF EXISTS users;
|
||||
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT)
|
||||
@@ -17,14 +17,30 @@ test.beforeEach(async (t) => {
|
||||
);
|
||||
t.context = {
|
||||
db,
|
||||
path,
|
||||
errorType
|
||||
};
|
||||
});
|
||||
|
||||
test.after.always(async (t) => {
|
||||
test.afterEach.always(async (t) => {
|
||||
// Close the database connection
|
||||
if (t.context.db != undefined) {
|
||||
t.context.db.close();
|
||||
}
|
||||
// Remove the database file if it exists
|
||||
if (t.context.path) {
|
||||
const walPath = t.context.path + "-wal";
|
||||
const shmPath = t.context.path + "-shm";
|
||||
if (fs.existsSync(t.context.path)) {
|
||||
fs.unlinkSync(t.context.path);
|
||||
}
|
||||
if (fs.existsSync(walPath)) {
|
||||
fs.unlinkSync(walPath);
|
||||
}
|
||||
if (fs.existsSync(shmPath)) {
|
||||
fs.unlinkSync(shmPath);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test.serial("Open in-memory database", async (t) => {
|
||||
@@ -408,12 +424,12 @@ const connect = async (path, options = {}) => {
|
||||
if (provider === "turso") {
|
||||
const x = await import("@tursodatabase/turso");
|
||||
const db = new x.default(path, options);
|
||||
return [db, x.SqliteError];
|
||||
return [db, path, x.SqliteError];
|
||||
}
|
||||
if (provider === "libsql") {
|
||||
const x = await import("libsql/promise");
|
||||
const db = new x.default(path, options);
|
||||
return [db, x.SqliteError, path];
|
||||
return [db, path, x.SqliteError, path];
|
||||
}
|
||||
if (provider === "serverless") {
|
||||
const x = await import("@tursodatabase/serverless");
|
||||
@@ -426,7 +442,7 @@ const connect = async (path, options = {}) => {
|
||||
url,
|
||||
authToken,
|
||||
});
|
||||
return [db, x.SqliteError];
|
||||
return [db, null, x.SqliteError];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user