more functional design principles for tests
Some checks failed
ci/woodpecker/pr/pr Pipeline failed

This commit is contained in:
Madison Grubb
2026-02-17 11:21:02 -05:00
parent c8d37c98f4
commit 82bd51c3a4
3 changed files with 42 additions and 34 deletions

View File

@@ -59,7 +59,9 @@ async function waitForHealth(timeoutMs = 90000) {
}
describe('Server and CoT integration', () => {
let serverProcess = null
const testState = {
serverProcess: null,
}
beforeAll(async () => {
ensureDevCerts()
@@ -74,33 +76,35 @@ describe('Server and CoT integration', () => {
BOOTSTRAP_EMAIL: COT_AUTH_USER,
BOOTSTRAP_PASSWORD: COT_AUTH_PASS,
}
serverProcess = spawn('node', ['.output/server/index.mjs'], {
testState.serverProcess = spawn('node', ['.output/server/index.mjs'], {
cwd: projectRoot,
env,
stdio: ['ignore', 'pipe', 'pipe'],
})
serverProcess.stdout?.on('data', d => process.stdout.write(d))
serverProcess.stderr?.on('data', d => process.stderr.write(d))
testState.serverProcess.stdout?.on('data', d => process.stdout.write(d))
testState.serverProcess.stderr?.on('data', d => process.stderr.write(d))
await waitForHealth(90000)
}, 120000)
afterAll(() => {
if (serverProcess?.pid) {
serverProcess.kill('SIGTERM')
if (testState.serverProcess?.pid) {
testState.serverProcess.kill('SIGTERM')
}
})
it('serves health on port 3000', async () => {
let res
for (const protocol of ['https', 'http']) {
const tryProtocols = async (protocols) => {
if (protocols.length === 0) throw new Error('No protocol succeeded')
try {
res = await fetch(`${protocol}://localhost:${API_PORT}/health`, { method: 'GET', headers: { Accept: 'application/json' } })
if (res?.ok) break
const res = await fetch(`${protocols[0]}://localhost:${API_PORT}/health`, { method: 'GET', headers: { Accept: 'application/json' } })
if (res?.ok) return res
return tryProtocols(protocols.slice(1))
}
catch {
// try next
return tryProtocols(protocols.slice(1))
}
}
const res = await tryProtocols(['https', 'http'])
expect(res?.ok).toBe(true)
const body = await res.json()
expect(body).toHaveProperty('status', 'ok')