-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv-config.ts
More file actions
37 lines (30 loc) · 898 Bytes
/
Copy pathenv-config.ts
File metadata and controls
37 lines (30 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import fs from "node:fs";
import dotenv from "dotenv";
import { CONTEXT_GUEST, CONTEXT_TESTUSER } from "./globals";
dotenv.config();
console.info("[Info] Test environment: local");
const config = {
baseUrl: getEnvVar("BASE_URL"),
apiUrl: getEnvVar("BASE_API_URL"),
userName: getEnvVar("USERNAME"),
userEmail: getEnvVar("EMAIL"),
userPassword: getEnvVar("PASSWORD"),
testUserContext: CONTEXT_TESTUSER,
guestContext: CONTEXT_GUEST,
};
function getEnvVar(key: string): string {
const value = process.env[key];
if (isNonEmptyStr(value)) {
return value;
}
throw new Error(
`[Error] Environment variable "${key}" is missing or empty. Received: ${value}`,
);
}
function isNonEmptyStr(val: unknown): val is string {
return typeof val === "string" && val.trim().length > 0;
}
export function authStateExists(): boolean {
return fs.existsSync(CONTEXT_TESTUSER);
}
export { config };