import { describe, expect, it } from 'vitest' import { spawnSync } from 'node:child_process' import path from 'node:path' function runHelper(script: string) { return spawnSync('bash', ['-c', 'set -euo pipefail; source "$DEPLOY_HELPER"; ' + script], { encoding: 'utf8', env: { ...process.env, DEPLOY_HELPER: path.resolve('scripts/deploy-runtime.sh'), DEPLOY_CONFIG: path.resolve('harheimertc.test.config.cjs') } }) } describe('Deployment runtime', () => { it('reloads the selected app configuration with an absolute Node runtime', () => { const result = runHelper(` pm2() { if [ "$1" = describe ]; then return 0; fi printf 'runtime=%s\\n' "\${DEPLOY_NODE_BINARY:-}" printf '%s\\n' "$@" } deploy_restart_pm2 harheimertc.test "$DEPLOY_CONFIG" `) expect(result.status).toBe(0) expect(result.stdout).toContain('runtime=/') expect(result.stdout).toContain('delete\nharheimertc.test') expect(result.stdout).toContain('start\n' + path.resolve('harheimertc.test.config.cjs')) expect(result.stdout).toContain('--only\nharheimertc.test\n--update-env') }) it('waits for HTTP readiness after initial connection failures', () => { const result = runHelper(` attempts=0 curl() { attempts=$((attempts + 1)); [ "$attempts" -ge 3 ]; } sleep() { :; } pm2() { echo 'Unexpected diagnostics'; return 1; } deploy_wait_for_http harheimertc.test http://127.0.0.1:3102/ [ "$attempts" -eq 3 ] `) expect(result.status).toBe(0) expect(result.stdout).toContain('HTTP-Healthcheck erfolgreich') expect(result.stdout).not.toContain('Unexpected diagnostics') }) it('fails with PM2 diagnostics when the server never becomes ready', () => { const result = runHelper(` curl() { return 1; } sleep() { :; } pm2() { printf '%s\\n' "$*"; } deploy_wait_for_http harheimertc.test http://127.0.0.1:3102/ `) expect(result.status).toBe(1) expect(result.stdout).toContain('describe harheimertc.test') expect(result.stdout).toContain('logs harheimertc.test --nostream --lines 30') }) })