2020-07-08 10:49:29 +02:00
|
|
|
import Application from "../src/Application";
|
2020-11-11 18:59:38 +01:00
|
|
|
import {setupMailServer, teardownMailServer} from "./_mail_server";
|
|
|
|
import TestApp from "../src/TestApp";
|
|
|
|
|
2020-07-08 10:49:29 +02:00
|
|
|
|
2020-11-14 18:16:58 +01:00
|
|
|
export default function useApp(appSupplier?: (addr: string, port: number) => Promise<TestApp>): void {
|
2020-07-08 10:49:29 +02:00
|
|
|
let app: Application;
|
|
|
|
|
|
|
|
beforeAll(async (done) => {
|
|
|
|
await setupMailServer();
|
2020-11-14 18:16:58 +01:00
|
|
|
app = appSupplier ? await appSupplier('127.0.0.1', 8966) : new TestApp('127.0.0.1', 8966);
|
2020-07-08 10:49:29 +02:00
|
|
|
|
|
|
|
await app.start();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async (done) => {
|
2020-09-25 23:42:15 +02:00
|
|
|
const errors = [];
|
|
|
|
|
|
|
|
try {
|
|
|
|
await app.stop();
|
|
|
|
} catch (e) {
|
|
|
|
errors.push(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await teardownMailServer();
|
|
|
|
} catch (e) {
|
|
|
|
errors.push(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (errors.length > 0) throw errors;
|
2020-07-08 10:49:29 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
}
|