1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00

Remove jest-testcontainers.

This commit is contained in:
Sam Rose 2024-03-22 17:04:45 +00:00
parent 3e07483f7e
commit aac589018e
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: {
type: "ports",
timeout: 20000,
}
}
},
},
}
}

View file

@ -27,7 +27,7 @@ class Replication {
return resolve(info)
})
.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",
],
setupFilesAfterEnv: ["./src/tests/jestSetup.ts"],
globalSetup: "./src/tests/globalSetup.ts",
globalTeardown: "./src/tests/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

@ -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.BUDIBASE_VERSION = "0.0.0+jest"
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)
}
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
}