From 3e8265a5396a4a8250a2ae3fbb5c0df636099f4d Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Tue, 7 Jan 2025 20:05:48 -0800 Subject: [PATCH] test: skip sql tests when psql binary is not installed --- test/js/sql/sql.test.ts | 3 ++- test/js/sql/tls-sql.test.ts | 33 ++++++++++++++++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/test/js/sql/sql.test.ts b/test/js/sql/sql.test.ts index 4f16d46073f14e..ce681484fe6004 100644 --- a/test/js/sql/sql.test.ts +++ b/test/js/sql/sql.test.ts @@ -4,7 +4,8 @@ import { $ } from "bun"; import { bunExe, isCI, withoutAggressiveGC } from "harness"; import path from "path"; -if (!isCI) { +const hasPsql = Bun.which("psql"); +if (!isCI && hasPsql) { require("./bootstrap.js"); // macOS location: /opt/homebrew/var/postgresql@14/pg_hba.conf diff --git a/test/js/sql/tls-sql.test.ts b/test/js/sql/tls-sql.test.ts index 2bc99bd3ad2d40..a9d2254c88afbd 100644 --- a/test/js/sql/tls-sql.test.ts +++ b/test/js/sql/tls-sql.test.ts @@ -3,21 +3,24 @@ import { getSecret } from "harness"; import { sql as SQL } from "bun"; const TLS_POSTGRES_DATABASE_URL = getSecret("TLS_POSTGRES_DATABASE_URL"); +const hasPsql = Bun.which("psql"); -test("tls (explicit)", async () => { - const sql = new SQL({ - url: TLS_POSTGRES_DATABASE_URL!, - tls: true, - adapter: "postgresql", - }); +if (hasPsql) { + test("tls (explicit)", async () => { + const sql = new SQL({ + url: TLS_POSTGRES_DATABASE_URL!, + tls: true, + adapter: "postgresql", + }); - const [{ one, two }] = await sql`SELECT 1 as one, '2' as two`; - expect(one).toBe(1); - expect(two).toBe("2"); -}); + const [{ one, two }] = await sql`SELECT 1 as one, '2' as two`; + expect(one).toBe(1); + expect(two).toBe("2"); + }); -test("tls (implicit)", async () => { - const [{ one, two }] = await SQL`SELECT 1 as one, '2' as two`; - expect(one).toBe(1); - expect(two).toBe("2"); -}); + test("tls (implicit)", async () => { + const [{ one, two }] = await SQL`SELECT 1 as one, '2' as two`; + expect(one).toBe(1); + expect(two).toBe("2"); + }); +}