diff options
author | Chocobozzz <me@florianbigard.com> | 2021-06-14 16:52:22 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2021-06-15 08:21:12 +0200 |
commit | 3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4 (patch) | |
tree | 7305399caecbf7380319bd08e21c933de88096dc /shared/extra-utils/miscs/email.ts | |
parent | 79db409a41bd28fd2773626c9a93b5d326a38bc0 (diff) | |
download | PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.tar.gz PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.tar.zst PeerTube-3d470a530c4a48b2e4f4a9e7d4f223e14f32cea4.zip |
Faster ci using compiled ts files
Diffstat (limited to 'shared/extra-utils/miscs/email.ts')
-rw-r--r-- | shared/extra-utils/miscs/email.ts | 39 |
1 files changed, 17 insertions, 22 deletions
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 @@ | |||
1 | import { ChildProcess, fork } from 'child_process' | 1 | import { ChildProcess } from 'child_process' |
2 | import { join } from 'path' | ||
3 | import { randomInt } from '../../core-utils/miscs/miscs' | 2 | import { randomInt } from '../../core-utils/miscs/miscs' |
4 | import { parallelTests } from '../server/servers' | 3 | import { parallelTests } from '../server/servers' |
5 | 4 | ||
5 | const MailDev = require('maildev') | ||
6 | |||
6 | class MockSmtpServer { | 7 | class 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 | }) |