diff options
author | 2023-01-31 17:55:16 -0800 | |
---|---|---|
committer | 2023-01-31 17:55:16 -0800 | |
commit | cc4326cd829decc95d1f1f23998f97705637e04b (patch) | |
tree | 9ccaa829b6d48af521d5e5fcdbabc0dac8d186af /test/bun.js/sqlite.test.js | |
parent | c57b37d29f9d04780c7f7917789cf8b424710d23 (diff) | |
download | bun-cc4326cd829decc95d1f1f23998f97705637e04b.tar.gz bun-cc4326cd829decc95d1f1f23998f97705637e04b.tar.zst bun-cc4326cd829decc95d1f1f23998f97705637e04b.zip |
Re-run prettier after changes
Diffstat (limited to 'test/bun.js/sqlite.test.js')
-rw-r--r-- | test/bun.js/sqlite.test.js | 120 |
1 files changed, 31 insertions, 89 deletions
diff --git a/test/bun.js/sqlite.test.js b/test/bun.js/sqlite.test.js index f78d3b481..3120283f4 100644 --- a/test/bun.js/sqlite.test.js +++ b/test/bun.js/sqlite.test.js @@ -4,15 +4,12 @@ import { existsSync, fstat, realpathSync, rmSync, writeFileSync } from "fs"; import { spawnSync } from "bun"; import { bunExe } from "bunExe"; import { tmpdir } from "os"; -var encode = (text) => new TextEncoder().encode(text); +var encode = text => new TextEncoder().encode(text); it("Database.open", () => { // in a folder which doesn't exist try { - Database.open( - "/this/database/does/not/exist.sqlite", - constants.SQLITE_OPEN_READWRITE, - ); + Database.open("/this/database/does/not/exist.sqlite", constants.SQLITE_OPEN_READWRITE); throw new Error("Expected an error to be thrown"); } catch (error) { expect(error.message).toBe("unable to open database file"); @@ -20,10 +17,7 @@ it("Database.open", () => { // in a file which doesn't exist try { - Database.open( - `/tmp/database-${Math.random()}.sqlite`, - constants.SQLITE_OPEN_READWRITE, - ); + Database.open(`/tmp/database-${Math.random()}.sqlite`, constants.SQLITE_OPEN_READWRITE); throw new Error("Expected an error to be thrown"); } catch (error) { expect(error.message).toBe("unable to open database file"); @@ -60,23 +54,17 @@ it("Database.open", () => { it("upsert cross-process, see #1366", () => { const dir = realpathSync(tmpdir()) + "/"; - const { exitCode } = spawnSync( - [bunExe(), import.meta.dir + "/sqlite-cross-process.js"], - { - env: { - SQLITE_DIR: dir, - }, - stderr: "inherit", + const { exitCode } = spawnSync([bunExe(), import.meta.dir + "/sqlite-cross-process.js"], { + env: { + SQLITE_DIR: dir, }, - ); + stderr: "inherit", + }); expect(exitCode).toBe(0); const db2 = Database.open(dir + "get-persist.sqlite"); - expect(db2.query(`SELECT id FROM examples`).all()).toEqual([ - { id: "hello" }, - { id: "world" }, - ]); + expect(db2.query(`SELECT id FROM examples`).all()).toEqual([{ id: "hello" }, { id: "world" }]); }); it("creates", () => { @@ -84,31 +72,11 @@ it("creates", () => { db.exec( "CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, created TEXT, deci FLOAT, blobby BLOB)", ); - const stmt = db.prepare( - "INSERT INTO test (name, value, deci, created, blobby) VALUES (?, ?, ?, ?, ?)", - ); + const stmt = db.prepare("INSERT INTO test (name, value, deci, created, blobby) VALUES (?, ?, ?, ?, ?)"); - stmt.run([ - "foo", - 1, - Math.fround(1.111), - new Date(1995, 12, 19).toISOString(), - encode("Hello World"), - ]); - stmt.run([ - "bar", - 2, - Math.fround(2.222), - new Date(1995, 12, 19).toISOString(), - encode("Hello World"), - ]); - stmt.run([ - "baz", - 3, - Math.fround(3.333), - new Date(1995, 12, 19).toISOString(), - encode("Hello World"), - ]); + stmt.run(["foo", 1, Math.fround(1.111), new Date(1995, 12, 19).toISOString(), encode("Hello World")]); + stmt.run(["bar", 2, Math.fround(2.222), new Date(1995, 12, 19).toISOString(), encode("Hello World")]); + stmt.run(["baz", 3, Math.fround(3.333), new Date(1995, 12, 19).toISOString(), encode("Hello World")]); stmt.finalize(); @@ -162,9 +130,7 @@ it("int52", () => { const db = Database.open(":memory:"); db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, int64 INTEGER)"); db.run("INSERT INTO test (int64) VALUES (?)", Number.MAX_SAFE_INTEGER); - expect(db.query("SELECT * FROM test").get().int64).toBe( - Number.MAX_SAFE_INTEGER, - ); + expect(db.query("SELECT * FROM test").get().int64).toBe(Number.MAX_SAFE_INTEGER); }); it("typechecks", () => { @@ -175,7 +141,7 @@ it("typechecks", () => { const q = db.prepare("SELECT * FROM test WHERE (name = ?)"); - var expectfail = (val) => { + var expectfail = val => { try { q.run([val]); throw new Error("Expected error"); @@ -238,13 +204,7 @@ it("db.query supports TypedArray", () => { }), ); - expect( - JSON.stringify( - db - .query("SELECT * FROM test WHERE (blobby = ?)") - .get([encode("Hello World")]), - ), - ).toBe( + expect(JSON.stringify(db.query("SELECT * FROM test WHERE (blobby = ?)").get([encode("Hello World")]))).toBe( JSON.stringify({ id: 1, blobby: encode("Hello World"), @@ -363,20 +323,12 @@ it("db.query()", () => { } // check that it supports multiple arguments - expect( - JSON.stringify( - db - .query("SELECT * FROM test where (name = ? OR name = ?)") - .all(["Hello", "Fooooo"]), - ), - ).toBe(JSON.stringify([{ id: 1, name: "Hello" }])); - expect( - JSON.stringify( - db - .query("SELECT * FROM test where (name = ? OR name = ?)") - .all("Hello", "Fooooo"), - ), - ).toBe(JSON.stringify([{ id: 1, name: "Hello" }])); + expect(JSON.stringify(db.query("SELECT * FROM test where (name = ? OR name = ?)").all(["Hello", "Fooooo"]))).toBe( + JSON.stringify([{ id: 1, name: "Hello" }]), + ); + expect(JSON.stringify(db.query("SELECT * FROM test where (name = ? OR name = ?)").all("Hello", "Fooooo"))).toBe( + JSON.stringify([{ id: 1, name: "Hello" }]), + ); // throws if insufficeint arguments try { @@ -388,12 +340,10 @@ it("db.query()", () => { // named parameters expect( JSON.stringify( - db - .query("SELECT * FROM test where (name = $hello OR name = $goodbye)") - .all({ - $hello: "Hello", - $goodbye: "Fooooo", - }), + db.query("SELECT * FROM test where (name = $hello OR name = $goodbye)").all({ + $hello: "Hello", + $goodbye: "Fooooo", + }), ), ).toBe(JSON.stringify([{ id: 1, name: "Hello" }])); @@ -418,16 +368,12 @@ it("db.query()", () => { it("db.transaction()", () => { const db = Database.open(":memory:"); - db.exec( - "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)", - ); + db.exec("CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"); - const insert = db.prepare( - "INSERT INTO cats (name, age) VALUES (@name, @age)", - ); + const insert = db.prepare("INSERT INTO cats (name, age) VALUES (@name, @age)"); expect(db.inTransaction).toBe(false); - const insertMany = db.transaction((cats) => { + const insertMany = db.transaction(cats => { expect(db.inTransaction).toBe(true); try { for (const cat of cats) insert.run(cat); @@ -466,9 +412,7 @@ it("db.transaction()", () => { it("inlineCapacity #987", async () => { const path = "/tmp/bun-987.db"; if (!existsSync(path)) { - const arrayBuffer = await ( - await fetch("https://github.com/oven-sh/bun/files/9265429/logs.log") - ).arrayBuffer(); + const arrayBuffer = await (await fetch("https://github.com/oven-sh/bun/files/9265429/logs.log")).arrayBuffer(); writeFileSync(path, arrayBuffer); } @@ -522,9 +466,7 @@ it("inlineCapacity #987", async () => { // https://github.com/oven-sh/bun/issues/1553 it("latin1 supplement chars", () => { const db = new Database(); - db.run( - "CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, greeting TEXT)", - ); + db.run("CREATE TABLE IF NOT EXISTS foo (id INTEGER PRIMARY KEY AUTOINCREMENT, greeting TEXT)"); db.run("INSERT INTO foo (greeting) VALUES (?)", "Welcome to bun!"); db.run("INSERT INTO foo (greeting) VALUES (?)", "Español"); db.run("INSERT INTO foo (greeting) VALUES (?)", "¿Qué sucedió?"); |