overleaf/services/chat/test/acceptance/js/helpers/ChatApp.js

32 lines
699 B
JavaScript
Raw Normal View History

const { waitForDb } = require('../../../../app/js/mongodb')
const app = require('../../../../app')
module.exports = {
running: false,
initing: false,
callbacks: [],
ensureRunning(callback) {
if (!callback) {
callback = function () {}
}
if (this.running) {
return callback()
} else if (this.initing) {
return this.callbacks.push(callback)
}
this.initing = true
this.callbacks.push(callback)
waitForDb().then(() => {
app.listen(3010, 'localhost', error => {
if (error) {
throw error
}
this.running = true
for (callback of this.callbacks) {
callback()
}
})
})
2021-07-13 07:04:48 -04:00
},
}