Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Oct 13, 2024
1 parent 7fcc78a commit e7fd2be
Showing 1 changed file with 40 additions and 46 deletions.
86 changes: 40 additions & 46 deletions test/drivers/db0.test.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
import { createDatabase } from "db0";
import libSql from "db0/connectors/libsql/node";
import pglite from "db0/connectors/pglite";
import { afterAll, describe, expect } from "vitest";
import { createDatabase } from "db0";
import db0Driver from "../../src/drivers/db0";
import { testDriver } from "./utils";

describe("drivers: db0 - LibSQL", () => {
const db = createDatabase(
libSql({
url: ":memory:",
})
);

afterAll(async () => {
await db.sql`DROP TABLE IF EXISTS unstorage`;
});

testDriver({
driver: db0Driver({ database: db }),
additionalTests: async (ctx) => {
await ctx.storage.setItem("meta:test", "test_data");

expect(await ctx.storage.getMeta("meta:test")).toMatchObject({
birthtime: expect.any(Date),
mtime: expect.any(Date),
});
const drivers = [
{
name: "libsql",
async getDB() {
const libSQL = await import("db0/connectors/libsql/node").then(
(m) => m.default
);
return createDatabase(libSQL({ url: ":memory:" }));
},
});
});

describe("drivers: db0 - PGlite", async () => {
const db = createDatabase(pglite());

afterAll(async () => {
await db.sql`DROP TABLE IF EXISTS custom_unstorage_table`;
});

testDriver({
driver: db0Driver({
database: db,
table: "custom_unstorage_table",
}),
additionalTests: async (ctx) => {
await ctx.storage.setItem("meta:test", "test_data");

expect(await ctx.storage.getMeta("meta:test")).toMatchObject({
birthtime: expect.any(Date),
mtime: expect.any(Date),
});
},
{
name: "pglite",
async getDB() {
const pglite = await import("db0/connectors/pglite").then(
(m) => m.default
);
return createDatabase(pglite());
},
},
];

for (const driver of drivers) {
describe(`drivers: db0 - ${driver.name}`, async () => {
const db = await driver.getDB();

afterAll(async () => {
await db.sql`DROP TABLE IF EXISTS unstorage`;
});

testDriver({
driver: db0Driver({ database: db }),
additionalTests: async (ctx) => {
await ctx.storage.setItem("meta:test", "test_data");

expect(await ctx.storage.getMeta("meta:test")).toMatchObject({
birthtime: expect.any(Date),
mtime: expect.any(Date),
});
},
});
});
});
}

0 comments on commit e7fd2be

Please sign in to comment.