Share a single globalSetup/globalTeardown.

This commit is contained in:
Sam Rose 2024-03-26 09:49:33 +00:00
parent afacee978d
commit f3e9e3d35e
No known key found for this signature in database
9 changed files with 5 additions and 80 deletions

View File

@ -9,7 +9,7 @@ export default async function setup() {
})
.withCopyFilesToContainer([
{
source: "./src/tests/test-couchdb.ini",
source: "./test-couchdb.ini",
target: "/opt/couchdb/etc/local.d/test-couchdb.ini",
},
])
@ -20,7 +20,6 @@ export default async function setup() {
)
.start()
// @ts-expect-error
// eslint-disable-next-line no-undef
globalThis.__COUCHDB_CONTAINER_ID__ = container.getId()
}

View File

@ -17,8 +17,8 @@ const baseConfig: Config.InitialProjectOptions = {
"svelte",
],
setupFilesAfterEnv: ["./src/tests/jestSetup.ts"],
globalSetup: "./src/tests/globalSetup.ts",
globalTeardown: "./src/tests/globalTeardown.ts",
globalSetup: "./../../globalSetup.ts",
globalTeardown: "./../../globalTeardown.ts",
transform: {
"^.+\\.ts?$": "@swc/jest",
"^.+\\.js?$": "@swc/jest",

View File

@ -1,6 +1,8 @@
#!/bin/bash
set -e
export DEBUG=testcontainers*
if [[ -n $CI ]]
then
export NODE_OPTIONS="--max-old-space-size=4096 --no-node-snapshot $NODE_OPTIONS"

View File

@ -1,26 +0,0 @@
import { GenericContainer, Wait } from "testcontainers"
export default async function setup() {
const container = await new GenericContainer("budibase/couchdb")
.withExposedPorts(5984)
.withEnvironment({
COUCHDB_PASSWORD: "budibase",
COUCHDB_USER: "budibase",
})
.withCopyFilesToContainer([
{
source: "./src/tests/test-couchdb.ini",
target: "/opt/couchdb/etc/local.d/test-couchdb.ini",
},
])
.withWaitStrategy(
Wait.forSuccessfulCommand(
"curl http://budibase:budibase@localhost:5984/_up"
).withStartupTimeout(20000)
)
.start()
// @ts-expect-error
// eslint-disable-next-line no-undef
globalThis.__COUCHDB_CONTAINER_ID__ = container.getId()
}

View File

@ -1,12 +0,0 @@
import { getContainerRuntimeClient } from "testcontainers"
export default async function teardown() {
const client = await getContainerRuntimeClient()
// @ts-expect-error
// eslint-disable-next-line no-undef
const containerId = globalThis.__COUCHDB_CONTAINER_ID__
const container = client.container.getById(containerId)
await client.container.stop(container)
await client.container.remove(container)
}

View File

@ -1,26 +0,0 @@
import { GenericContainer, Wait } from "testcontainers"
export default async function setup() {
const container = await new GenericContainer("budibase/couchdb")
.withExposedPorts(5984)
.withEnvironment({
COUCHDB_PASSWORD: "budibase",
COUCHDB_USER: "budibase",
})
.withCopyFilesToContainer([
{
source: "./src/tests/test-couchdb.ini",
target: "/opt/couchdb/etc/local.d/test-couchdb.ini",
},
])
.withWaitStrategy(
Wait.forSuccessfulCommand(
"curl http://budibase:budibase@localhost:5984/_up"
).withStartupTimeout(20000)
)
.start()
// @ts-expect-error
// eslint-disable-next-line no-undef
globalThis.__COUCHDB_CONTAINER_ID__ = container.getId()
}

View File

@ -1,12 +0,0 @@
import { getContainerRuntimeClient } from "testcontainers"
export default async function teardown() {
const client = await getContainerRuntimeClient()
// @ts-expect-error
// eslint-disable-next-line no-undef
const containerId = globalThis.__COUCHDB_CONTAINER_ID__
const container = client.container.getById(containerId)
await client.container.stop(container)
await client.container.remove(container)
}