diff --git a/README.md b/README.md index c43ff60..c6b5fde 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ Including: This project demonstrates the stack in action via a [RealWorld](https://github.com/gothinkster/realworld) example. +## Environment Configuration + +Production and shared environment variables are defined in `src/core/env.ts`. + +Test-specific environment variables are now defined in `src/core/test-env.ts` and are only used by test scripts and test runners. This keeps test configuration isolated from production config. + ## Development 1. Install dependencies diff --git a/scripts/test/api.ts b/scripts/test/api.ts index e01f600..93dd407 100644 --- a/scripts/test/api.ts +++ b/scripts/test/api.ts @@ -5,13 +5,13 @@ import { $ } from "bun"; import chalk from "chalk"; import newman from "newman"; import { debounce } from "radashi"; -import { env } from "@/core/env"; +import { testEnv } from "@/core/test-env"; -const APIURL = env.APIURL; -const USERNAME = env.USERNAME; -const EMAIL = env.EMAIL; -const PASSWORD = env.PASSWORD; -const POSTMAN_COLLECTION = env.POSTMAN_COLLECTION; +const APIURL = testEnv.APIURL; +const USERNAME = testEnv.USERNAME; +const EMAIL = testEnv.EMAIL; +const PASSWORD = testEnv.PASSWORD; +const POSTMAN_COLLECTION = testEnv.POSTMAN_COLLECTION; // Parse command line arguments const { values } = parseArgs({ @@ -29,11 +29,12 @@ const { values } = parseArgs({ }); // check --skip-db-reset param -const shouldSkipDbReset = values["skip-db-reset"] || env.SKIP_DB_RESET; +const shouldSkipDbReset = + values["skip-db-reset"] ?? testEnv.SKIP_DB_RESET; const isWatchMode = values.watch || false; // Performance options -const DELAY_REQUEST = env.DELAY_REQUEST; +const DELAY_REQUEST = testEnv.DELAY_REQUEST; // Note: Newman doesn't support parallel execution, but we can reduce delays console.info(chalk.gray("Checking Bedstack health")); diff --git a/src/core/env.ts b/src/core/env.ts index fdc7948..391dd51 100644 --- a/src/core/env.ts +++ b/src/core/env.ts @@ -18,16 +18,6 @@ export const envPlugin = elysiaEnv({ LOG_LEVEL: t.Union([t.Literal("debug"), t.Literal("info")], { default: "info", }), - APIURL: t.String({ default: "http://localhost:3000/api" }), - USERNAME: t.String({ default: "jake" }), - EMAIL: t.String({ default: "jake@jake.jake" }), - PASSWORD: t.String({ default: "hunter2A" }), - POSTMAN_COLLECTION: t.String({ - default: - "https://raw.githubusercontent.com/gothinkster/realworld/refs/heads/main/api/Conduit.postman_collection.json", - }), - SKIP_DB_RESET: t.Boolean({ default: false }), - DELAY_REQUEST: t.Number({ default: 50 }), }); export const { env } = envPlugin.decorator; diff --git a/src/core/test-env.ts b/src/core/test-env.ts new file mode 100644 index 0000000..8405b8e --- /dev/null +++ b/src/core/test-env.ts @@ -0,0 +1,17 @@ +import { env as elysiaEnv } from "@yolk-oss/elysia-env"; +import { t } from "elysia"; + +export const testEnvPlugin = elysiaEnv({ + APIURL: t.String({ default: "http://localhost:3000/api" }), + USERNAME: t.String({ default: "jake" }), + EMAIL: t.String({ default: "jake@jake.jake" }), + PASSWORD: t.String({ default: "hunter2A" }), + POSTMAN_COLLECTION: t.String({ + default: + "https://raw.githubusercontent.com/gothinkster/realworld/refs/heads/main/api/Conduit.postman_collection.json", + }), + SKIP_DB_RESET: t.Boolean({ default: false }), + DELAY_REQUEST: t.Number({ default: 50 }), +}); + +export const { env: testEnv } = testEnvPlugin.decorator;