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) => {
@@ -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);
});

View File

@@ -82,8 +82,8 @@ test.serial("Database.exec() after close()", async (t) => {
t.throws(() => {
db.exec("SELECT 1");
}, {
instanceOf: TypeError,
message: "The database connection is not open"
instanceOf: Error,
message: "database must be connected"
});
});
@@ -108,8 +108,8 @@ test.serial("Database.prepare() after close()", async (t) => {
t.throws(() => {
db.prepare("SELECT 1");
}, {
instanceOf: TypeError,
message: "The database connection is not open"
instanceOf: Error,
message: "database must be connected"
});
});
@@ -129,8 +129,8 @@ test.serial("Database.pragma() after close()", async (t) => {
t.throws(() => {
db.pragma("cache_size = 2000");
}, {
instanceOf: TypeError,
message: "The database connection is not open"
instanceOf: Error,
message: "database must be connected"
});
});
@@ -207,7 +207,7 @@ test.serial("Statement.run() [named]", async (t) => {
const db = t.context.db;
const stmt = db.prepare("INSERT INTO users(name, email) VALUES (@name, @email);");
const info = stmt.run({"name": "Carol", "email": "carol@example.net"});
const info = stmt.run({ "name": "Carol", "email": "carol@example.net" });
t.is(info.changes, 1);
t.is(info.lastInsertRowid, 3);
});
@@ -262,11 +262,11 @@ test.skip("Statement.run() for vector feature with Float32Array bind parameter",
`);
const insertStmt = db.prepare("INSERT INTO t VALUES (?)");
insertStmt.run([new Float32Array([1,1,1,1,1,1,1,1])]);
insertStmt.run([new Float32Array([-1,-1,-1,-1,-1,-1,-1,-1])]);
insertStmt.run([new Float32Array([1, 1, 1, 1, 1, 1, 1, 1])]);
insertStmt.run([new Float32Array([-1, -1, -1, -1, -1, -1, -1, -1])]);
const selectStmt = db.prepare("SELECT embedding FROM vector_top_k('t_idx', vector('[2,2,2,2,2,2,2,2]'), 1) n JOIN t ON n.rowid = t.rowid");
t.deepEqual(selectStmt.raw().get()[0], Buffer.from(new Float32Array([1,1,1,1,1,1,1,1]).buffer));
t.deepEqual(selectStmt.raw().get()[0], Buffer.from(new Float32Array([1, 1, 1, 1, 1, 1, 1, 1]).buffer));
// we need to explicitly delete this table because later when sqlite-based (not LibSQL) tests will delete table 't' they will leave 't_idx_shadow' table untouched
db.exec(`DROP TABLE t`);
@@ -298,9 +298,9 @@ test.serial("Statement.get() [positional]", async (t) => {
t.is(stmt.get(2).name, "Bob");
stmt = db.prepare("SELECT * FROM users WHERE id = ?1");
t.is(stmt.get({1: 0}), undefined);
t.is(stmt.get({1: 1}).name, "Alice");
t.is(stmt.get({1: 2}).name, "Bob");
t.is(stmt.get({ 1: 0 }), undefined);
t.is(stmt.get({ 1: 1 }).name, "Alice");
t.is(stmt.get({ 1: 2 }).name, "Bob");
});
test.serial("Statement.get() [named]", async (t) => {
@@ -510,7 +510,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);
});
@@ -521,7 +521,7 @@ const connect = async (path, options = {}) => {
}
const provider = process.env.PROVIDER;
if (provider === "turso") {
const { Database, SqliteError }= await import("@tursodatabase/database/compat");
const { Database, SqliteError } = await import("@tursodatabase/database/compat");
const db = new Database(path, options);
return [db, path, provider, SqliteError];
}

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,7 @@
},
"dependencies": {
"@tursodatabase/serverless": "../../packages/turso-serverless",
"@tursodatabase/database": "../../bindings/javascript",
"@tursodatabase/database": "../../bindings/javascript/packages/native",
"better-sqlite3": "^11.9.1",
"libsql": "^0.6.0-pre.16"
}