aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared/extra-utils/miscs
diff options
context:
space:
mode:
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
-rw-r--r--shared/extra-utils/miscs/miscs.ts11
3 files changed, 26 insertions, 51 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 })
diff --git a/shared/extra-utils/miscs/miscs.ts b/shared/extra-utils/miscs/miscs.ts
index 1cb1cf440..462b914d4 100644
--- a/shared/extra-utils/miscs/miscs.ts
+++ b/shared/extra-utils/miscs/miscs.ts
@@ -60,8 +60,14 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
60 const minLength = body.length - ((30 * body.length) / 100) 60 const minLength = body.length - ((30 * body.length) / 100)
61 const maxLength = body.length + ((30 * body.length) / 100) 61 const maxLength = body.length + ((30 * body.length) / 100)
62 62
63 expect(data.length).to.be.above(minLength, "the generated image is way smaller than the recorded fixture") 63 expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture')
64 expect(data.length).to.be.below(maxLength, "the generated image is way larger than the recorded fixture") 64 expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture')
65}
66
67async function testFileExistsOrNot (server: { internalServerNumber: number }, directory: string, filePath: string, exist: boolean) {
68 const base = buildServerDirectory(server, directory)
69
70 expect(await pathExists(join(base, filePath))).to.equal(exist)
65} 71}
66 72
67function isGithubCI () { 73function isGithubCI () {
@@ -157,6 +163,7 @@ export {
157 testImage, 163 testImage,
158 isGithubCI, 164 isGithubCI,
159 buildAbsoluteFixturePath, 165 buildAbsoluteFixturePath,
166 testFileExistsOrNot,
160 root, 167 root,
161 generateHighBitrateVideo, 168 generateHighBitrateVideo,
162 generateVideoWithFramerate 169 generateVideoWithFramerate