2020-11-11 18:59:38 +01:00
|
|
|
import {setupMailServer, teardownMailServer} from "./_mail_server";
|
|
|
|
import TestApp from "../src/TestApp";
|
2020-11-16 12:08:39 +01:00
|
|
|
import MysqlConnectionManager from "../src/db/MysqlConnectionManager";
|
|
|
|
import config from "config";
|
2020-11-11 18:59:38 +01:00
|
|
|
|
2020-07-08 10:49:29 +02:00
|
|
|
|
2021-04-22 15:38:24 +02:00
|
|
|
export default function useApp<T extends TestApp>(appSupplier: AppSupplier<T>): () => T {
|
|
|
|
let app: T;
|
2020-07-08 10:49:29 +02:00
|
|
|
|
|
|
|
beforeAll(async (done) => {
|
2020-11-16 12:08:39 +01:00
|
|
|
await MysqlConnectionManager.prepare();
|
|
|
|
await MysqlConnectionManager.query('DROP DATABASE IF EXISTS ' + config.get<string>('mysql.database'));
|
|
|
|
await MysqlConnectionManager.endPool();
|
|
|
|
|
2020-07-08 10:49:29 +02:00
|
|
|
await setupMailServer();
|
2021-04-22 15:38:24 +02:00
|
|
|
app = await appSupplier('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();
|
|
|
|
});
|
2021-04-22 15:38:24 +02:00
|
|
|
|
|
|
|
return () => app;
|
2020-07-08 10:49:29 +02:00
|
|
|
}
|
2021-03-26 10:38:58 +01:00
|
|
|
|
2021-04-22 15:38:24 +02:00
|
|
|
export type AppSupplier<T extends TestApp> = (addr: string, port: number) => Promise<T>;
|