1
0
Fork 0
mirror of synced 2024-09-30 00:57:16 +13:00

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: {
image: "budibase/dependencies",
tag: "latest",
ports: [6379, 5984, 9000],
env: {
COUCHDB_USER: "test_couchdb_user",
COUCHDB_PASSWORD: "test_couchdb_password",
},
env,
wait: {
type: "text",
text: "Test environment started...",
},
},
}
})

View file

@ -87,4 +87,4 @@
"install:pro": "bash scripts/pro/install.sh",
"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
if (!LOADED && isDev() && !isTest()) {
require("dotenv").config({
path: join(__dirname, "..", ".env"),
})
LOADED = true
if (!LOADED) {
if (isDev() && !isTest()) {
require("dotenv").config({
path: join(__dirname, "..", ".env"),
})
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) {

View file

@ -26,13 +26,10 @@ function overrideConfigValue(key: string, value: string) {
overrideConfigValue("COUCH_DB_PORT", global.__TESTCONTAINERS_DEVENV_PORT_5984__)
overrideConfigValue(
"COUCH_DB_URL",
`http://localhost:${global.__TESTCONTAINERS_DEVENV_PORT_5984__}`
`http://${global.__TESTCONTAINERS_DEVENV_IP__}:${global.__TESTCONTAINERS_DEVENV_PORT_5984__}`
)
overrideConfigValue(
"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")