Förberedelse fas 2: testmiljö fix + analytics tracker i mobilappen
This commit is contained in:
@@ -12,10 +12,16 @@ let sharedPool: pg.Pool | undefined;
|
||||
* (minsta möjliga privilegier, spec §52).
|
||||
*/
|
||||
export function createDatabase(connectionString?: string) {
|
||||
const url =
|
||||
connectionString ??
|
||||
process.env.DATABASE_URL ??
|
||||
"postgres://app_user:app_dev_password@localhost:5432/app";
|
||||
const url = connectionString ?? process.env.TEST_DATABASE_URL ?? process.env.DATABASE_URL;
|
||||
|
||||
if (!url) {
|
||||
if (process.env.NODE_ENV === "test" || process.env.VITEST !== undefined) {
|
||||
throw new Error(
|
||||
"Missing DATABASE_URL / TEST_DATABASE_URL. Database tests must run against an explicit database URL and are not allowed to fall back to the dev database.",
|
||||
);
|
||||
}
|
||||
throw new Error("Missing DATABASE_URL. Set it in your .env or environment before starting the app.");
|
||||
}
|
||||
|
||||
const pool = new pg.Pool({
|
||||
connectionString: url,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { config } from "dotenv";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// Load root .env so database tests receive DATABASE_URL / TEST_DATABASE_URL
|
||||
// when running `pnpm test` from the workspace root.
|
||||
config({ path: path.resolve(__dirname, "../../.env") });
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
environment: "node",
|
||||
globals: false,
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user