aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/utils/miscs
diff options
context:
space:
mode:
Diffstat (limited to 'shared/utils/miscs')
-rw-r--r--shared/utils/miscs/email.ts17
1 files changed, 11 insertions, 6 deletions
diff --git a/shared/utils/miscs/email.ts b/shared/utils/miscs/email.ts
index 108f7d3d9..6fac7621f 100644
--- a/shared/utils/miscs/email.ts
+++ b/shared/utils/miscs/email.ts
@@ -1,22 +1,20 @@
1import * as child from 'child_process' 1import { fork, ChildProcess } from 'child_process'
2 2
3class MockSmtpServer { 3class MockSmtpServer {
4 4
5 private static instance: MockSmtpServer 5 private static instance: MockSmtpServer
6 private started = false 6 private started = false
7 private emailChildProcess: child.ChildProcess 7 private emailChildProcess: ChildProcess
8 private emails: object[] 8 private emails: object[]
9 9
10 private constructor () { 10 private constructor () {
11 this.emailChildProcess = child.fork(`${__dirname}/email-child-process`, [], { silent: true }) 11 this.emailChildProcess = fork(`${__dirname}/email-child-process`, [])
12
12 this.emailChildProcess.on('message', (msg) => { 13 this.emailChildProcess.on('message', (msg) => {
13 if (msg.email) { 14 if (msg.email) {
14 return this.emails.push(msg.email) 15 return this.emails.push(msg.email)
15 } 16 }
16 }) 17 })
17 process.on('exit', () => {
18 this.emailChildProcess.kill()
19 })
20 } 18 }
21 19
22 collectEmails (emailsCollection: object[]) { 20 collectEmails (emailsCollection: object[]) {
@@ -43,6 +41,13 @@ class MockSmtpServer {
43 }) 41 })
44 } 42 }
45 43
44 kill () {
45 process.kill(this.emailChildProcess.pid)
46
47 this.emailChildProcess = null
48 MockSmtpServer.instance = null
49 }
50
46 static get Instance () { 51 static get Instance () {
47 return this.instance || (this.instance = new this()) 52 return this.instance || (this.instance = new this())
48 } 53 }