test: Avoid creation of new server/app instance for each route test

This commit is contained in:
Tom Moor
2022-08-08 12:06:54 +02:00
parent b45e6c504f
commit 71c9fcf59b
22 changed files with 59 additions and 129 deletions

View File

@@ -1,6 +1,8 @@
import TestServer from "fetch-test-server";
import { v4 as uuidv4 } from "uuid";
import { sequelize } from "@server/database/sequelize";
import { User, Document, Collection, Team } from "@server/models";
import webService from "@server/services/web";
const sql = sequelize.getQueryInterface();
const tables = Object.keys(sequelize.models).map((model) => {
@@ -109,3 +111,15 @@ export const seed = async () => {
};
});
};
let testServer: typeof TestServer | undefined;
export function getTestServer() {
if (testServer) {
return testServer;
}
const app = webService();
testServer = new TestServer(app.callback());
return testServer;
}