From f8ef226c70c676b28d2df10d3d761085019c26e3 Mon Sep 17 00:00:00 2001 From: alexeh Date: Thu, 10 Oct 2024 09:31:59 +0200 Subject: [PATCH] load env for jest context --- api/test/jest-config.json | 1 + api/test/set-up-jest-env.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 api/test/set-up-jest-env.ts diff --git a/api/test/jest-config.json b/api/test/jest-config.json index a3717c69..581efaca 100644 --- a/api/test/jest-config.json +++ b/api/test/jest-config.json @@ -3,6 +3,7 @@ "rootDir": "../", "roots": ["/src/", "/test/"], "testEnvironment": "node", + "setupFiles": ["/test/set-up-jest-env.ts"], "testRegex": "(.steps.ts|.spec.ts)$", "transform": { "^.+\\.(t|j)s$": "ts-jest" diff --git a/api/test/set-up-jest-env.ts b/api/test/set-up-jest-env.ts new file mode 100644 index 00000000..890fdf5b --- /dev/null +++ b/api/test/set-up-jest-env.ts @@ -0,0 +1,11 @@ +import { config } from 'dotenv'; +import { resolve } from 'path'; + +/** + * @description: Since Jest is executed in a different context, we need to load the environment variables manually for this specific context + * for e2e tests, the default route + env suffix is used + */ + +const envPath = resolve(__dirname, '../../shared/config/.env.test'); + +config({ path: envPath });