chore: fix integration tests

This commit is contained in:
Charlie Lamb
2026-04-21 11:41:29 +01:00
parent 36049cae23
commit d9b71b0f97
3 changed files with 27 additions and 9 deletions

View File

@@ -24,6 +24,19 @@ const normalizeExecuteRows = <TRow>(result: unknown): TRow[] => {
return result as TRow[];
};
const normalizeDbExecute = <
TDb extends { execute: (query: string | SQLWrapper) => Promise<unknown> },
>(
db: TDb,
) => {
const execute = db.execute.bind(db);
return Object.assign(db, {
execute: async <TRow = Record<string, unknown>>(
query: string | SQLWrapper,
) => normalizeExecuteRows<TRow>(await execute(query)),
});
};
/** Creates a Drizzle pool with the given configuration. */
export const initDrizzle = ({
maxConnections = 10,
@@ -50,12 +63,17 @@ export const initDrizzle = ({
});
const drizzleDb = drizzle(client, { schema });
const execute = drizzleDb.execute.bind(drizzleDb);
const db = Object.assign(drizzleDb, {
execute: async <TRow = Record<string, unknown>>(
query: string | SQLWrapper,
) => normalizeExecuteRows<TRow>(await execute(query)),
}) as unknown as AutumnDb;
const transaction = drizzleDb.transaction.bind(drizzleDb);
const db = normalizeDbExecute(drizzleDb) as unknown as AutumnDb;
const normalizedTransaction: typeof drizzleDb.transaction = ((
fn,
config,
) =>
transaction(
(tx) => fn(normalizeDbExecute(tx) as typeof tx),
config,
)) as typeof drizzleDb.transaction;
db.transaction = normalizedTransaction as typeof db.transaction;
if (otelConfig.drizzle) {
instrumentDrizzleClient(db);

View File

@@ -4,8 +4,8 @@ import { config } from "dotenv";
let hasLoadedLocalEnv = false;
const shouldLogLocalEnvLoading = false;
export const loadLocalEnv = () => {
if (hasLoadedLocalEnv) return;
export const loadLocalEnv = ({ force = false }: { force?: boolean } = {}) => {
if (hasLoadedLocalEnv && !force) return;
hasLoadedLocalEnv = true;
const processDir = process.cwd();

View File

@@ -32,6 +32,6 @@ if (isUnitTest()) {
} else {
console.log("--- Setup integration tests ---");
await loadInfisicalSecrets();
loadLocalEnv();
loadLocalEnv({ force: true });
console.log("--- Setup integration tests complete ---");
}