budibase/packages/worker/src/tests/jestSetup.ts

46 lines
1.2 KiB
TypeScript
Raw Normal View History

import { mocks } from "@budibase/backend-core/tests"
2023-01-27 18:59:14 +01:00
import env from "../environment"
import { env as coreEnv } from "@budibase/backend-core"
2022-11-16 14:06:30 +01:00
// must explicitly enable fetch mock
mocks.fetch.enable()
// mock all dates to 2020-01-01T00:00:00.000Z
// use tk.reset() to use real dates in individual tests
const tk = require("timekeeper")
tk.freeze(mocks.date.MOCK_DATE)
if (!process.env.DEBUG) {
global.console.log = jest.fn() // console.log are ignored in tests
}
if (!process.env.CI) {
// set a longer timeout in dev for debugging
// 100 seconds
jest.setTimeout(100000)
}
2023-01-27 18:59:14 +01:00
function overrideConfigValue(key: string, value: string) {
env._set(key, value)
coreEnv._set(key, value)
}
const globalSafe = global as any
2023-01-31 11:18:51 +01:00
console.log(global)
2023-01-27 18:59:14 +01:00
overrideConfigValue(
"COUCH_DB_PORT",
2023-01-30 19:15:29 +01:00
globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]
2023-01-27 18:59:14 +01:00
)
overrideConfigValue(
"COUCH_DB_URL",
2023-01-30 19:15:29 +01:00
`http://${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]}`
2023-01-27 18:59:14 +01:00
)
overrideConfigValue(
"MINIO_URL",
2023-01-30 19:15:29 +01:00
`http://${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_PORT_9000__"]}`
2023-01-27 18:59:14 +01:00
)