budibase/globalSetup.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

import { GenericContainer, Wait } from "testcontainers"
2024-04-03 13:11:28 +02:00
import path from "path"
import lockfile from "proper-lockfile"
export default async function setup() {
2024-04-03 13:11:28 +02:00
const lockPath = path.resolve(__dirname, "globalSetup.ts")
if (process.env.REUSE_CONTAINERS) {
// If you run multiple tests at the same time, it's possible for the CouchDB
// shared container to get started multiple times despite having an
// identical reuse hash. To avoid that, we do a filesystem-based lock so
// that only one globalSetup.ts is running at a time.
2024-04-03 13:11:28 +02:00
lockfile.lockSync(lockPath)
}
try {
let couchdb = new GenericContainer("budibase/couchdb:v3.2.1-sqs")
2024-04-09 16:31:32 +02:00
.withExposedPorts(5984, 4984)
.withEnvironment({
COUCHDB_PASSWORD: "budibase",
COUCHDB_USER: "budibase",
})
.withCopyContentToContainer([
{
content: `
2024-03-26 10:58:40 +01:00
[log]
level = warn
`,
target: "/opt/couchdb/etc/local.d/test-couchdb.ini",
},
])
.withWaitStrategy(
Wait.forSuccessfulCommand(
"curl http://budibase:budibase@localhost:5984/_up"
).withStartupTimeout(20000)
)
if (process.env.REUSE_CONTAINERS) {
couchdb = couchdb.withReuse()
}
await couchdb.start()
} finally {
if (process.env.REUSE_CONTAINERS) {
2024-04-03 13:11:28 +02:00
lockfile.unlockSync(lockPath)
}
}
}