HealthCheck.test.ts 884 B

12345678910111213141516171819202122232425262728293031
  1. import { beforeAll, describe, it, expect } from 'vitest'
  2. import { fetchStringWithResponse } from '@overleaf/fetch-utils'
  3. import app from '../../../app.js'
  4. import logger from '@overleaf/logger'
  5. let runAppPromise: Promise<void> | null = null
  6. async function ensureRunning(hostname: string, port: number) {
  7. if (!runAppPromise) {
  8. runAppPromise = new Promise(resolve => {
  9. app.listen(port, hostname, () => {
  10. logger.info({ port, hostname }, 'notifications running in dev mode')
  11. resolve()
  12. })
  13. })
  14. }
  15. await runAppPromise
  16. }
  17. describe('HealthCheck endpoint', () => {
  18. beforeAll(async () => {
  19. await ensureRunning('127.0.0.1', 3042)
  20. })
  21. it('should return 200 for GET /health_check', async () => {
  22. const { response } = await fetchStringWithResponse(
  23. 'http://localhost:3042/health_check'
  24. )
  25. expect(response.status).toBe(200)
  26. })
  27. })