aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/miscs
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-14 16:52:22 +0200
committerChocobozzz <chocobozzz@cpy.re>2021-06-15 08:21:12 +0200
commit3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4 (patch)
tree7305399caecbf7380319bd08e21c933de88096dc /shared/extra-utils/miscs
parent79db409a41bd28fd2773626c9a93b5d326a38bc0 (diff)
downloadPeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.tar.gz
PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.tar.zst
PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.zip
Faster ci using compiled ts files
Diffstat (limited to 'shared/extra-utils/miscs')
-rw-r--r--shared/extra-utils/miscs/email-child-process.js27
-rw-r--r--shared/extra-utils/miscs/email.ts39
2 files changed, 17 insertions, 49 deletions
diff --git a/shared/extra-utils/miscs/email-child-process.js b/shared/extra-utils/miscs/email-child-process.js
deleted file mode 100644
index 088a5a08c..000000000
--- a/shared/extra-utils/miscs/email-child-process.js
+++ /dev/null
@@ -1,27 +0,0 @@
1const MailDev = require('maildev')
2
3// must run maildev as forked ChildProcess
4// failed instantiation stops main process with exit code 0
5process.on('message', (msg) => {
6 if (msg.start) {
7 const maildev = new MailDev({
8 ip: '127.0.0.1',
9 smtp: msg.port,
10 disableWeb: true,
11 silent: true
12 })
13
14 maildev.on('new', email => {
15 process.send({ email })
16 })
17
18 maildev.listen(err => {
19 if (err) {
20 // cannot send as Error object
21 return process.send({ err: err.message })
22 }
23
24 return process.send({ err: null })
25 })
26 }
27})
diff --git a/shared/extra-utils/miscs/email.ts b/shared/extra-utils/miscs/email.ts
index 758b15b58..9fc9a5ad0 100644
--- a/shared/extra-utils/miscs/email.ts
+++ b/shared/extra-utils/miscs/email.ts
@@ -1,8 +1,9 @@
1import { ChildProcess, fork } from 'child_process' 1import { ChildProcess } from 'child_process'
2import { join } from 'path'
3import { randomInt } from '../../core-utils/miscs/miscs' 2import { randomInt } from '../../core-utils/miscs/miscs'
4import { parallelTests } from '../server/servers' 3import { parallelTests } from '../server/servers'
5 4
5const MailDev = require('maildev')
6
6class MockSmtpServer { 7class MockSmtpServer {
7 8
8 private static instance: MockSmtpServer 9 private static instance: MockSmtpServer
@@ -10,38 +11,32 @@ class MockSmtpServer {
10 private emailChildProcess: ChildProcess 11 private emailChildProcess: ChildProcess
11 private emails: object[] 12 private emails: object[]
12 13
13 private constructor () { 14 private constructor () { }
14 this.emailChildProcess = fork(join(__dirname, 'email-child-process'), [])
15
16 this.emailChildProcess.on('message', (msg: any) => {
17 if (msg.email) {
18 return this.emails.push(msg.email)
19 }
20 })
21
22 process.on('exit', () => this.kill())
23 }
24 15
25 collectEmails (emailsCollection: object[]) { 16 collectEmails (emailsCollection: object[]) {
26 return new Promise<number>((res, rej) => { 17 return new Promise<number>((res, rej) => {
27 const port = parallelTests() ? randomInt(1000, 2000) : 1025 18 const port = parallelTests() ? randomInt(1000, 2000) : 1025
19 this.emails = emailsCollection
28 20
29 if (this.started) { 21 if (this.started) {
30 this.emails = emailsCollection
31 return res(undefined) 22 return res(undefined)
32 } 23 }
33 24
34 // ensure maildev isn't started until 25 const maildev = new MailDev({
35 // unexpected exit can be reported to test runner 26 ip: '127.0.0.1',
36 this.emailChildProcess.send({ start: true, port }) 27 smtp: port,
37 this.emailChildProcess.on('exit', () => { 28 disableWeb: true,
38 return rej(new Error('maildev exited unexpectedly, confirm port not in use')) 29 silent: true
30 })
31
32 maildev.on('new', email => {
33 this.emails.push(email)
39 }) 34 })
40 this.emailChildProcess.on('message', (msg: any) => { 35
41 if (msg.err) return rej(new Error(msg.err)) 36 maildev.listen(err => {
37 if (err) return rej(err)
42 38
43 this.started = true 39 this.started = true
44 this.emails = emailsCollection
45 40
46 return res(port) 41 return res(port)
47 }) 42 })