1 import { ChildProcess } from 'child_process'
2 import MailDev from '@peertube/maildev'
6 private static instance: MockSMTPServer
7 private started = false
8 private emailChildProcess: ChildProcess
9 private emails: object[]
11 collectEmails (port: number, emailsCollection: object[]) {
12 return new Promise<number>((res, rej) => {
13 this.emails = emailsCollection
19 const maildev = new MailDev({
26 maildev.on('new', email => {
27 this.emails.push(email)
30 maildev.listen(err => {
31 if (err) return rej(err)
41 if (!this.emailChildProcess) return
43 process.kill(this.emailChildProcess.pid)
45 this.emailChildProcess = null
46 MockSMTPServer.instance = null
49 static get Instance () {
50 return this.instance || (this.instance = new this())
54 // ---------------------------------------------------------------------------