mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-01 21:31:36 +02:00
[web] tests: use named before-all/after-all hooks for mongo setup GitOrigin-RevId: bbdd0f27d310eac730cec3e2230f177d8112acd8
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
const { execFile } = require('child_process')
|
|
const {
|
|
waitForDb,
|
|
db,
|
|
dropTestDatabase,
|
|
} = require('../../../../app/src/infrastructure/mongodb')
|
|
const Settings = require('@overleaf/settings')
|
|
|
|
const DEFAULT_ENV = 'saas'
|
|
|
|
module.exports = {
|
|
initialize() {
|
|
before('wait for db', waitForDb)
|
|
if (process.env.CLEANUP_MONGO === 'true') {
|
|
before('drop test database', dropTestDatabase)
|
|
}
|
|
|
|
before('run migrations', function (done) {
|
|
const args = [
|
|
'run',
|
|
'migrations',
|
|
'--',
|
|
'migrate',
|
|
'-t',
|
|
Settings.env || DEFAULT_ENV,
|
|
]
|
|
execFile('npm', args, (error, stdout, stderr) => {
|
|
if (error) {
|
|
throw error
|
|
}
|
|
done()
|
|
})
|
|
})
|
|
|
|
afterEach('purge mongo data', async function () {
|
|
return Promise.all(
|
|
Object.values(db).map(async collection => {
|
|
if (collection === db.migrations) {
|
|
// Do not clear the collection for tracking migrations.
|
|
return
|
|
}
|
|
return collection.deleteMany({})
|
|
})
|
|
)
|
|
})
|
|
},
|
|
}
|