mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
add tests
This commit is contained in:
parent
a43ea7ae19
commit
0c0a3e6505
2 changed files with 67 additions and 0 deletions
|
@ -89,6 +89,7 @@ util::unit_test_factory!(
|
||||||
querystring_test,
|
querystring_test,
|
||||||
readline_test,
|
readline_test,
|
||||||
repl_test,
|
repl_test,
|
||||||
|
sqlite_test,
|
||||||
stream_test,
|
stream_test,
|
||||||
string_decoder_test,
|
string_decoder_test,
|
||||||
timers_test,
|
timers_test,
|
||||||
|
|
66
tests/unit_node/sqlite_test.ts
Normal file
66
tests/unit_node/sqlite_test.ts
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
import { DatabaseSync } from "node:sqlite";
|
||||||
|
import { assertEquals, assertThrows } from "@std/assert";
|
||||||
|
|
||||||
|
Deno.test("[node/sqlite] in-memory databases", () => {
|
||||||
|
const db1 = new DatabaseSync(":memory:");
|
||||||
|
const db2 = new DatabaseSync(":memory:");
|
||||||
|
db1.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
||||||
|
db1.exec("INSERT INTO data (key) VALUES (1);");
|
||||||
|
|
||||||
|
db2.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
||||||
|
db2.exec("INSERT INTO data (key) VALUES (1);");
|
||||||
|
|
||||||
|
assertEquals(db1.prepare("SELECT * FROM data").all(), [{
|
||||||
|
key: 1,
|
||||||
|
__proto__: null,
|
||||||
|
}]);
|
||||||
|
assertEquals(db2.prepare("SELECT * FROM data").all(), [{
|
||||||
|
key: 1,
|
||||||
|
__proto__: null,
|
||||||
|
}]);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test("[node/sqlite] Errors originating from SQLite should be thrown", () => {
|
||||||
|
const db = new DatabaseSync(":memory:");
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE test(
|
||||||
|
key INTEGER PRIMARY KEY
|
||||||
|
) STRICT;
|
||||||
|
`);
|
||||||
|
const stmt = db.prepare("INSERT INTO test(key) VALUES(?)");
|
||||||
|
assertEquals(stmt.run(1), { lastInsertRowid: 1, changes: 1 });
|
||||||
|
|
||||||
|
assertThrows(() => stmt.run(1), Error);
|
||||||
|
});
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
{
|
||||||
|
permissions: { read: true, write: true },
|
||||||
|
name: "[node/sqlite] PRAGMAs are supported",
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
const tempDir = Deno.makeTempDirSync();
|
||||||
|
const db = new DatabaseSync(`${tempDir}/test.db`);
|
||||||
|
|
||||||
|
assertEquals(db.prepare("PRAGMA journal_mode = WAL").get(), {
|
||||||
|
journal_mode: "wal",
|
||||||
|
__proto__: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
db.close();
|
||||||
|
Deno.removeSync(tempDir, { recursive: true });
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Deno.test("[node/sqlite] StatementSync read bigints are supported", () => {
|
||||||
|
const db = new DatabaseSync(":memory:");
|
||||||
|
db.exec("CREATE TABLE data(key INTEGER PRIMARY KEY);");
|
||||||
|
db.exec("INSERT INTO data (key) VALUES (1);");
|
||||||
|
|
||||||
|
const stmt = db.prepare("SELECT * FROM data");
|
||||||
|
assertEquals(stmt.get(), { key: 1, __proto__: null });
|
||||||
|
|
||||||
|
stmt.setReadBigInts(true);
|
||||||
|
assertEquals(stmt.get(), { key: 1n, __proto__: null });
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue