From 8ef9457fdee7812b1a8cc3b3bdeff94130819003 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:36:54 +0200 Subject: Correctly export misc files --- shared/extra-utils/index.ts | 11 +---- shared/extra-utils/miscs/email.ts | 64 -------------------------- shared/extra-utils/miscs/index.ts | 3 ++ shared/extra-utils/mock-servers/index.ts | 1 + shared/extra-utils/mock-servers/mock-email.ts | 64 ++++++++++++++++++++++++++ shared/extra-utils/users/user-notifications.ts | 2 +- 6 files changed, 70 insertions(+), 75 deletions(-) delete mode 100644 shared/extra-utils/miscs/email.ts create mode 100644 shared/extra-utils/miscs/index.ts create mode 100644 shared/extra-utils/mock-servers/mock-email.ts (limited to 'shared') diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 30f44dfc2..7d2887209 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -1,20 +1,11 @@ export * from './bulk' - export * from './cli' - export * from './custom-pages' - export * from './feeds' - export * from './logs' - +export * from './miscs' export * from './mock-servers' -export * from './miscs/email' -export * from './miscs/sql' -export * from './miscs/miscs' -export * from './miscs/stubs' - export * from './moderation/abuses' export * from './plugins/mock-blocklist' diff --git a/shared/extra-utils/miscs/email.ts b/shared/extra-utils/miscs/email.ts deleted file mode 100644 index 9fc9a5ad0..000000000 --- a/shared/extra-utils/miscs/email.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { ChildProcess } from 'child_process' -import { randomInt } from '../../core-utils/miscs/miscs' -import { parallelTests } from '../server/servers' - -const MailDev = require('maildev') - -class MockSmtpServer { - - private static instance: MockSmtpServer - private started = false - private emailChildProcess: ChildProcess - private emails: object[] - - private constructor () { } - - collectEmails (emailsCollection: object[]) { - return new Promise((res, rej) => { - const port = parallelTests() ? randomInt(1000, 2000) : 1025 - this.emails = emailsCollection - - if (this.started) { - return res(undefined) - } - - const maildev = new MailDev({ - ip: '127.0.0.1', - smtp: port, - disableWeb: true, - silent: true - }) - - maildev.on('new', email => { - this.emails.push(email) - }) - - maildev.listen(err => { - if (err) return rej(err) - - this.started = true - - return res(port) - }) - }) - } - - kill () { - if (!this.emailChildProcess) return - - process.kill(this.emailChildProcess.pid) - - this.emailChildProcess = null - MockSmtpServer.instance = null - } - - static get Instance () { - return this.instance || (this.instance = new this()) - } -} - -// --------------------------------------------------------------------------- - -export { - MockSmtpServer -} diff --git a/shared/extra-utils/miscs/index.ts b/shared/extra-utils/miscs/index.ts new file mode 100644 index 000000000..ccacd4c79 --- /dev/null +++ b/shared/extra-utils/miscs/index.ts @@ -0,0 +1,3 @@ +export * from './miscs' +export * from './sql' +export * from './stubs' diff --git a/shared/extra-utils/mock-servers/index.ts b/shared/extra-utils/mock-servers/index.ts index 47679c818..485757843 100644 --- a/shared/extra-utils/mock-servers/index.ts +++ b/shared/extra-utils/mock-servers/index.ts @@ -1,2 +1,3 @@ +export * from './mock-email' export * from './mock-instances-index' export * from './mock-joinpeertube-versions' diff --git a/shared/extra-utils/mock-servers/mock-email.ts b/shared/extra-utils/mock-servers/mock-email.ts new file mode 100644 index 000000000..9fc9a5ad0 --- /dev/null +++ b/shared/extra-utils/mock-servers/mock-email.ts @@ -0,0 +1,64 @@ +import { ChildProcess } from 'child_process' +import { randomInt } from '../../core-utils/miscs/miscs' +import { parallelTests } from '../server/servers' + +const MailDev = require('maildev') + +class MockSmtpServer { + + private static instance: MockSmtpServer + private started = false + private emailChildProcess: ChildProcess + private emails: object[] + + private constructor () { } + + collectEmails (emailsCollection: object[]) { + return new Promise((res, rej) => { + const port = parallelTests() ? randomInt(1000, 2000) : 1025 + this.emails = emailsCollection + + if (this.started) { + return res(undefined) + } + + const maildev = new MailDev({ + ip: '127.0.0.1', + smtp: port, + disableWeb: true, + silent: true + }) + + maildev.on('new', email => { + this.emails.push(email) + }) + + maildev.listen(err => { + if (err) return rej(err) + + this.started = true + + return res(port) + }) + }) + } + + kill () { + if (!this.emailChildProcess) return + + process.kill(this.emailChildProcess.pid) + + this.emailChildProcess = null + MockSmtpServer.instance = null + } + + static get Instance () { + return this.instance || (this.instance = new this()) + } +} + +// --------------------------------------------------------------------------- + +export { + MockSmtpServer +} diff --git a/shared/extra-utils/users/user-notifications.ts b/shared/extra-utils/users/user-notifications.ts index 844f4442d..e75946eec 100644 --- a/shared/extra-utils/users/user-notifications.ts +++ b/shared/extra-utils/users/user-notifications.ts @@ -5,7 +5,7 @@ import { inspect } from 'util' import { AbuseState, PluginType } from '@shared/models' import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' -import { MockSmtpServer } from '../miscs/email' +import { MockSmtpServer } from '../mock-servers/mock-email' import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' import { doubleFollow } from '../server/follows' import { flushAndRunMultipleServers, ServerInfo } from '../server/servers' -- cgit v1.2.3