import MailDev, {Mail} from "maildev"; export const MAIL_SERVER = new MailDev({ ip: '127.0.0.1', }); export async function setupMailServer(): Promise { await new Promise((resolve, reject) => MAIL_SERVER.listen((err?: Error) => { if (err) reject(err); else resolve(); })); } export async function teardownMailServer(): Promise { await new Promise((resolve, reject) => MAIL_SERVER.close((err?: Error) => { if (err) reject(err); else resolve(); })); } export async function popEmail(): Promise | null> { return await new Promise | null>((resolve, reject) => { MAIL_SERVER.getAllEmail((err: Error | undefined, emails: Mail[]) => { if (err) return reject(err); if (emails.length === 0) return resolve(null); const email = emails[0]; expect(email).toBeDefined(); expect(email.id).toBeDefined(); return resolve(new Promise>((resolve, reject) => { MAIL_SERVER.deleteEmail(email.id as string, (err: Error | undefined) => { if (err) return reject(err); resolve(email as Record); }); })); }); }); }