- Updated `ensure_node_version` function in `deploy-production.sh` and `deploy-test.sh` to use a common script for Node.js version validation. - Simplified PM2 instance restart logic by introducing `deploy_restart_pm2` function in a new `deploy-runtime.sh` script. - Replaced direct PM2 commands with the new function to handle instance restarts and HTTP readiness checks. - Modified PM2 configuration files to set the script directly instead of using `node` as the interpreter, allowing for better compatibility with older Node.js versions. - Added tests for the new deployment runtime functions in `deploy-runtime.spec.ts` to ensure correct behavior during deployment. - Updated `package-lock.json` to include new dependencies and ensure compatibility with the latest changes.
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
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')
|
|
})
|
|
})
|