fix tests in testing/javascript

This commit is contained in:
Nikita Sivukhin
2025-09-25 12:07:57 +04:00
parent a938bdcf09
commit 6015dee36e
4 changed files with 64 additions and 3506 deletions

View File

@@ -4,7 +4,7 @@ import fs from 'fs';
test.beforeEach(async (t) => {
const [db, path,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)
@@ -84,8 +84,8 @@ test.serial("Database.exec() after close()", async (t) => {
await t.throwsAsync(async () => {
await db.exec("SELECT 1");
}, {
instanceOf: TypeError,
message: "The database connection is not open"
instanceOf: Error,
message: "database must be connected"
});
});
@@ -111,8 +111,8 @@ test.serial("Database.prepare() after close()", async (t) => {
await t.throwsAsync(async () => {
await db.prepare("SELECT 1");
}, {
instanceOf: TypeError,
message: "The database connection is not open"
instanceOf: Error,
message: "database must be connected"
});
});
@@ -136,8 +136,8 @@ test.serial("Database.pragma() after close()", async (t) => {
await t.throwsAsync(async () => {
await db.pragma("cache_size = 2000");
}, {
instanceOf: TypeError,
message: "The database connection is not open"
instanceOf: Error,
message: "database must be connected"
});
});
@@ -246,9 +246,9 @@ test.serial("Statement.get() [positional]", async (t) => {
t.is((await stmt.get(2)).name, "Bob");
stmt = await db.prepare("SELECT * FROM users WHERE id = ?1");
t.is(await stmt.get({1: 0}), undefined);
t.is((await stmt.get({1: 1})).name, "Alice");
t.is((await stmt.get({1: 2})).name, "Bob");
t.is(await stmt.get({ 1: 0 }), undefined);
t.is((await stmt.get({ 1: 1 })).name, "Alice");
t.is((await stmt.get({ 1: 2 })).name, "Bob");
});
test.serial("Statement.get() [named]", async (t) => {
@@ -295,16 +295,16 @@ test.serial("Statement.get() [blob]", async (t) => {
// Create table with blob column
await db.exec("CREATE TABLE IF NOT EXISTS blobs (id INTEGER PRIMARY KEY, data BLOB)");
// Test inserting and retrieving blob data
const binaryData = Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64]); // "Hello World"
const insertStmt = await db.prepare("INSERT INTO blobs (data) VALUES (?)");
await insertStmt.run([binaryData]);
// Retrieve the blob data
const selectStmt = await db.prepare("SELECT data FROM blobs WHERE id = 1");
const result = await selectStmt.get();
t.truthy(result, "Should return a result");
t.true(Buffer.isBuffer(result.data), "Should return Buffer for blob data");
t.deepEqual(result.data, binaryData, "Blob data should match original");
@@ -425,14 +425,14 @@ test.serial("Statement.columns()", async (t) => {
stmt = await db.prepare("SELECT * FROM users WHERE id = ?");
const columns2 = stmt.columns();
t.is(columns2.length, 3);
// Check column names and types only
t.is(columns2[0].name, "id");
t.is(columns2[0].type, "INTEGER");
t.is(columns2[1].name, "name");
t.is(columns2[1].name, "name");
t.is(columns2[1].type, "TEXT");
t.is(columns2[2].name, "email");
t.is(columns2[2].type, "TEXT");
});
@@ -472,7 +472,7 @@ test.skip("Timeout option", async (t) => {
const end = Date.now();
const elapsed = end - start;
// Allow some tolerance for the timeout.
t.is(elapsed > timeout/2, true);
t.is(elapsed > timeout / 2, true);
}
fs.unlinkSync(path);
});