34 lines
843 B
TypeScript
34 lines
843 B
TypeScript
|
import getPort from "get-port";
|
||
|
import { MemoryStorage } from "./basic";
|
||
|
import { basicCheck } from "./basic.test";
|
||
|
import { RestRemoteStorage } from "./remote";
|
||
|
import { startRestServer } from "./server";
|
||
|
|
||
|
export function startTestServer(): { port: () => number } {
|
||
|
let app: { close: Function } | undefined;
|
||
|
let port: number;
|
||
|
|
||
|
beforeEach(async () => {
|
||
|
port = await getPort();
|
||
|
app = await startRestServer(port, new MemoryStorage());
|
||
|
});
|
||
|
|
||
|
afterEach(async () => {
|
||
|
if (app) {
|
||
|
await app.close();
|
||
|
app = undefined;
|
||
|
}
|
||
|
});
|
||
|
|
||
|
return { port: () => port };
|
||
|
}
|
||
|
|
||
|
describe(RestRemoteStorage, () => {
|
||
|
const server = startTestServer();
|
||
|
|
||
|
it("communicates with the server", async () => {
|
||
|
const storage = new RestRemoteStorage("test", `http://localhost:${server.port()}`);
|
||
|
await basicCheck(storage);
|
||
|
});
|
||
|
});
|