Add acceptance test to notifications

GitOrigin-RevId: de2d0ed8cab15c4347ddecf227073a6d4e06120f
This commit is contained in:
Andrew Rumble
2025-09-11 13:58:58 +01:00
committed by Copybot
parent 92792828bf
commit aef9639405
7 changed files with 52 additions and 7 deletions

View File

@@ -69,6 +69,9 @@ try {
process.exit(1)
}
app.listen(port, host, () =>
logger.debug({}, `notifications starting up, listening on ${host}:${port}`)
)
if (import.meta.url === `file://${process.argv[1]}`) {
app.listen(port, host, () =>
logger.debug({}, `notifications starting up, listening on ${host}:${port}`)
)
}
export default app

View File

@@ -6,5 +6,6 @@ notifications
--esmock-loader=False
--node-version=22.18.0
--public-repo=True
--test-acceptance-vitest=True
--test-unit-vitest=True
--tsconfig-extra-includes=vitest.config.unit.cjs,vitest.config.acceptance.cjs

View File

@@ -33,6 +33,7 @@ services:
NODE_OPTIONS: "--unhandled-rejections=strict"
volumes:
- ../../bin/shared/wait_for_it:/overleaf/bin/shared/wait_for_it
- ../../tsconfig.backend.json:/overleaf/tsconfig.backend.json
depends_on:
mongo:
condition: service_started

View File

@@ -32,6 +32,7 @@ services:
- ../../node_modules:/overleaf/node_modules
- ../../libraries:/overleaf/libraries
- ../../bin/shared/wait_for_it:/overleaf/bin/shared/wait_for_it
- ../../tsconfig.backend.json:/overleaf/tsconfig.backend.json
working_dir: /overleaf/services/notifications
environment:
ELASTIC_SEARCH_DSN: es:9200

View File

@@ -6,13 +6,13 @@
"type": "module",
"scripts": {
"start": "node app.js",
"test:acceptance:_run": "mocha --recursive --reporter spec --timeout 15000 --exit $@ test/acceptance/js",
"test:acceptance": "npm run test:acceptance:_run -- --grep=$MOCHA_GREP",
"test:acceptance:_run": "vitest --config ./vitest.config.acceptance.cjs",
"test:acceptance": "npm run test:acceptance:_run",
"test:unit:_run": "vitest --config ./vitest.config.unit.cjs",
"test:unit": "npm run test:unit:_run",
"lint": "eslint --max-warnings 0 --format unix .",
"format": "prettier --list-different $PWD/'**/{*.*js,Jenkinsfile}'",
"format:fix": "prettier --write $PWD/'**/{*.*js,Jenkinsfile}'",
"format": "prettier --list-different $PWD/'**/{*.*js, *.*ts,Jenkinsfile}'",
"format:fix": "prettier --write $PWD/'**/{*.*js,*.*ts,Jenkinsfile}'",
"lint:fix": "eslint --fix .",
"types:check": "tsc --noEmit",
"nodemon": "node --watch app.js"

View File

@@ -0,0 +1,31 @@
import { beforeAll, describe, it, expect } from 'vitest'
import { fetchStringWithResponse } from '@overleaf/fetch-utils'
import app from '../../../app.js'
import logger from '@overleaf/logger'
let runAppPromise: Promise<void> | null = null
async function ensureRunning(hostname: string, port: number) {
if (!runAppPromise) {
runAppPromise = new Promise(resolve => {
app.listen(port, hostname, () => {
logger.info({ port, hostname }, 'notifications running in dev mode')
resolve()
})
})
}
await runAppPromise
}
describe('HealthCheck endpoint', () => {
beforeAll(async () => {
await ensureRunning('127.0.0.1', 3042)
})
it('should return 200 for GET /health_check', async () => {
const { response } = await fetchStringWithResponse(
'http://localhost:3042/health_check'
)
expect(response.status).toBe(200)
})
})

View File

@@ -0,0 +1,8 @@
const { defineConfig } = require('vitest/config')
module.exports = defineConfig({
test: {
include: ['test/acceptance/js/**/*.test.{js,ts}'],
isolate: false,
},
})