MongoHelper.mjs 791 B

12345678910111213141516171819202122232425262728293031
  1. import { exec } from 'node:child_process'
  2. import {
  3. connectionPromise,
  4. cleanupTestDatabase,
  5. dropTestDatabase,
  6. } from '../../../../app/src/infrastructure/mongodb.js'
  7. import Settings from '@overleaf/settings'
  8. import { promisify } from 'node:util'
  9. const DEFAULT_ENV = 'saas'
  10. export default {
  11. initialize() {
  12. before('wait for db', async function () {
  13. await connectionPromise
  14. })
  15. if (process.env.CLEANUP_MONGO === 'true') {
  16. before('drop test database', dropTestDatabase)
  17. }
  18. before('run migrations', async function () {
  19. this.timeout(60_000)
  20. await promisify(exec)(
  21. `cd ../../tools/migrations && npm run migrations -- migrate -t ${Settings.env || DEFAULT_ENV}`
  22. )
  23. })
  24. afterEach('purge mongo data', cleanupTestDatabase)
  25. },
  26. }