diff --git a/test/js/bun/sql/sql-logging.test.ts b/test/js/bun/sql/sql-logging.test.ts new file mode 100644 index 0000000000..a8131e7d77 --- /dev/null +++ b/test/js/bun/sql/sql-logging.test.ts @@ -0,0 +1,42 @@ +import { test, expect } from "bun:test"; +import { tempDirWithFiles } from "harness"; + +test("SQL logging option can be set and passed to adapters", async () => { + // Test SQLite logging option + try { + const sql = new Bun.SQL(":memory:", { log: true }); + expect(sql).toBeDefined(); + + // Verify we can create tables and run queries + await sql`CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)`; + await sql`INSERT INTO users (name) VALUES ('Alice')`; + const users = await sql`SELECT * FROM users`; + expect(users).toHaveLength(1); + expect(users[0].name).toBe("Alice"); + } catch (error) { + console.error("SQLite logging test failed:", error); + throw error; + } + + // Test that log: false works (default case) + try { + const sqlNoLog = new Bun.SQL(":memory:", { log: false }); + expect(sqlNoLog).toBeDefined(); + await sqlNoLog`CREATE TABLE test (id INTEGER)`; + } catch (error) { + console.error("SQLite no-logging test failed:", error); + throw error; + } +}); + +test("SQL logging option accepts boolean values", () => { + // Test that log option can be true + expect(() => new Bun.SQL(":memory:", { log: true })).not.toThrow(); + + // Test that log option can be false + expect(() => new Bun.SQL(":memory:", { log: false })).not.toThrow(); + + // Test that log option can be undefined (defaults to false) + expect(() => new Bun.SQL(":memory:", {})).not.toThrow(); + expect(() => new Bun.SQL(":memory:")).not.toThrow(); +}); \ No newline at end of file