mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Add tests for SQL logging functionality
- Test that log option can be set on SQL connections - Verify SQLite operations work with logging enabled/disabled - Test boolean values for log option are accepted 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
42
test/js/bun/sql/sql-logging.test.ts
Normal file
42
test/js/bun/sql/sql-logging.test.ts
Normal file
@@ -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();
|
||||
});
|
||||
Reference in New Issue
Block a user