1
0
Fork 0
mirror of synced 2024-07-04 05:50:57 +12:00
budibase/globalSetup.ts

48 lines
1.3 KiB
TypeScript
Raw Normal View History

import { GenericContainer, Wait } from "testcontainers"
2024-04-04 00:11:28 +13:00
import path from "path"
import lockfile from "proper-lockfile"
export default async function setup() {
2024-04-04 00:11:28 +13: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-04 00:11:28 +13:00
lockfile.lockSync(lockPath)
}
try {
let couchdb = new GenericContainer("budibase/couchdb:v3.2.1-sqs")
2024-04-10 02:31:32 +12:00
.withExposedPorts(5984, 4984)
.withEnvironment({
COUCHDB_PASSWORD: "budibase",
COUCHDB_USER: "budibase",
})
.withCopyContentToContainer([
{
content: `
2024-03-26 22:58:40 +13: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-04 00:11:28 +13:00
lockfile.unlockSync(lockPath)
}
}
}