]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/e2e/src/utils/mock-smtp.ts
Bumped to version v5.2.1
[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
29 this.maildev.listen(err => {
30 if (err) return rej(err)
31
32 this.started = true
33
34 return res(port)
35 })
36 })
37 }
38
39 kill () {
40 if (!this.maildev) return
41
42 this.maildev.close()
43
44 this.maildev = null
45 MockSMTPServer.instance = null
46 }
47
48 static get Instance () {
49 return this.instance || (this.instance = new this())
50 }
51 }
52
53 // ---------------------------------------------------------------------------
54
55 export {
56 MockSMTPServer
57 }