]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/utils/mock-smtp.ts
Fix E2E with firefox
[github/Chocobozzz/PeerTube.git] / client / e2e / src / utils / mock-smtp.ts
1 import MailDev from '@peertube/maildev'
2
3 class MockSMTPServer {
4
5 private static instance: MockSMTPServer
6 private started = false
7 private maildev: any
8 private emails: object[]
9
10 collectEmails (port: number, emailsCollection: object[]) {
11 return new Promise<number>((res, rej) => {
12 this.emails = emailsCollection
13
14 if (this.started) {
15 return res(undefined)
16 }
17
18 this.maildev = new MailDev({
19 ip: '127.0.0.1',
20 smtp: port,
21 disableWeb: true,
22 silent: true
23 })
24
25 this.maildev.on('new', email => {
26 this.emails.push(email)
27
28 console.log('pushed email', email)
29 })
30
31 this.maildev.listen(err => {
32 if (err) return rej(err)
33
34 this.started = true
35
36 return res(port)
37 })
38 })
39 }
40
41 kill () {
42 if (!this.maildev) return
43
44 this.maildev.close()
45
46 this.maildev = null
47 MockSMTPServer.instance = null
48 }
49
50 static get Instance () {
51 return this.instance || (this.instance = new this())
52 }
53 }
54
55 // ---------------------------------------------------------------------------
56
57 export {
58 MockSMTPServer
59 }