MongoHelper.mjs 871 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { execFile } 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. const DEFAULT_ENV = 'saas'
  9. export default {
  10. initialize() {
  11. before('wait for db', async function () {
  12. await connectionPromise
  13. })
  14. if (process.env.CLEANUP_MONGO === 'true') {
  15. before('drop test database', dropTestDatabase)
  16. }
  17. before('run migrations', function (done) {
  18. const args = [
  19. 'run',
  20. 'migrations',
  21. '--',
  22. 'migrate',
  23. '-t',
  24. Settings.env || DEFAULT_ENV,
  25. ]
  26. execFile('npm', args, (error, stdout, stderr) => {
  27. if (error) {
  28. throw error
  29. }
  30. done()
  31. })
  32. })
  33. afterEach('purge mongo data', cleanupTestDatabase)
  34. },
  35. }