Remove jest-testcontainers.

This commit is contained in:
Sam Rose 2024-03-22 17:04:45 +00:00
parent 6bd6ee779b
commit 66cfb8eedd
No known key found for this signature in database
10 changed files with 67 additions and 11 deletions

View File

@ -10,7 +10,7 @@ module.exports = () => {
wait: { wait: {
type: "ports", type: "ports",
timeout: 20000, timeout: 20000,
} },
} },
} }
} }

View File

@ -27,7 +27,7 @@ class Replication {
return resolve(info) return resolve(info)
}) })
.on("error", function (err) { .on("error", function (err) {
throw new Error(`Replication Error: ${err}`) throw err
}) })
}) })
} }

View File

@ -1,8 +0,0 @@
const { join } = require("path")
require("dotenv").config({
path: join(__dirname, "..", "..", "hosting", ".env"),
})
const jestTestcontainersConfigGenerator = require("../../jestTestcontainersConfigGenerator")
module.exports = jestTestcontainersConfigGenerator()

View File

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

View File

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

View File

@ -0,0 +1,27 @@
import { GenericContainer, Wait } from "testcontainers"
export default async function setup() {
const container = await new GenericContainer("budibase/couchdb")
.withName("couchdb-service")
.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

@ -0,0 +1,12 @@
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

@ -11,3 +11,6 @@ process.env.PLATFORM_URL = "http://localhost:10000"
process.env.REDIS_PASSWORD = "budibase" process.env.REDIS_PASSWORD = "budibase"
process.env.BUDIBASE_VERSION = "0.0.0+jest" process.env.BUDIBASE_VERSION = "0.0.0+jest"
process.env.WORKER_URL = "http://localhost:10000" process.env.WORKER_URL = "http://localhost:10000"
process.env.COUCH_DB_PASSWORD = "budibase"
process.env.COUCH_DB_USER = "budibase"
process.env.JWT_SECRET = "jwtsecret"

View File

@ -0,0 +1,2 @@
[log]
level = warn

View File

@ -187,6 +187,22 @@ export abstract class TestAPI {
expect(response.body).toMatchObject(expectations.body) expect(response.body).toMatchObject(expectations.body)
} }
if (response.text && response.text.length > 0) {
// @ts-expect-error - we know this exists, it's just not in the types
const request = response.request as Test
const contentLength = response.headers["content-length"]
if (!contentLength) {
throw new Error(
`Failed request "${request.method} ${request.url}": Content-Length header not present, but response has a body (body length ${response.text.length})`
)
}
if (parseInt(contentLength) !== response.text.length) {
throw new Error(
`Failed request "${request.method} ${request.url}": Content-Length header does not match response body length (header: ${contentLength}, body: ${response.text.length})`
)
}
}
return response return response
} }