Dry, moving env variables to a .env.test file

This commit is contained in:
Adria Navarro 2023-01-23 17:41:32 +00:00
parent 98aa60879f
commit d6f0e5b1ec
6 changed files with 31 additions and 18 deletions

View File

@ -1,15 +1,12 @@
module.exports = { module.exports = env => ({
devEnv: { devEnv: {
image: "budibase/dependencies", image: "budibase/dependencies",
tag: "latest", tag: "latest",
ports: [6379, 5984, 9000], ports: [6379, 5984, 9000],
env: { env,
COUCHDB_USER: "test_couchdb_user",
COUCHDB_PASSWORD: "test_couchdb_password",
},
wait: { wait: {
type: "text", type: "text",
text: "Test environment started...", text: "Test environment started...",
}, },
}, },
} })

View File

@ -87,4 +87,4 @@
"install:pro": "bash scripts/pro/install.sh", "install:pro": "bash scripts/pro/install.sh",
"dep:clean": "yarn clean && yarn bootstrap" "dep:clean": "yarn clean && yarn bootstrap"
} }
} }

View File

@ -0,0 +1,3 @@
JWT_SECRET=testsecret
COUCH_DB_PASSWORD=test_couchdb_user
COUCH_DB_USER=test_couchdb_password

View File

@ -1 +1,8 @@
module.exports = require("../../jest-testcontainers-config") const { join } = require("path")
const { parsed: env } = require("dotenv").config({
path: join(__dirname, ".env.test"),
})
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
module.exports = jestTestcontainersConfigGenerator(env)

View File

@ -21,11 +21,20 @@ function isCypress() {
} }
let LOADED = false let LOADED = false
if (!LOADED && isDev() && !isTest()) { if (!LOADED) {
require("dotenv").config({ if (isDev() && !isTest()) {
path: join(__dirname, "..", ".env"), require("dotenv").config({
}) path: join(__dirname, "..", ".env"),
LOADED = true })
LOADED = true
}
// TODO: remove when all tests (cypress, e2e, unit, etc) use docker for testing dependencies
else if (isJest()) {
require("dotenv").config({
path: join(__dirname, "..", ".env.test"),
})
LOADED = true
}
} }
function parseIntSafe(number?: string) { function parseIntSafe(number?: string) {

View File

@ -26,13 +26,10 @@ function overrideConfigValue(key: string, value: string) {
overrideConfigValue("COUCH_DB_PORT", global.__TESTCONTAINERS_DEVENV_PORT_5984__) overrideConfigValue("COUCH_DB_PORT", global.__TESTCONTAINERS_DEVENV_PORT_5984__)
overrideConfigValue( overrideConfigValue(
"COUCH_DB_URL", "COUCH_DB_URL",
`http://localhost:${global.__TESTCONTAINERS_DEVENV_PORT_5984__}` `http://${global.__TESTCONTAINERS_DEVENV_IP__}:${global.__TESTCONTAINERS_DEVENV_PORT_5984__}`
) )
overrideConfigValue( overrideConfigValue(
"MINIO_URL", "MINIO_URL",
`http://localhost:${global.__TESTCONTAINERS_DEVENV_PORT_9000__}` `http://${global.__TESTCONTAINERS_DEVENV_IP__}:${global.__TESTCONTAINERS_DEVENV_PORT_9000__}`
) )
overrideConfigValue("COUCH_DB_USERNAME", "test_couchdb_user")
overrideConfigValue("COUCH_DB_PASSWORD", "test_couchdb_password")