2021-09-23 11:12:08 -04:00
|
|
|
import config from "../../src/config";
|
|
|
|
import { makeMjolnir, teardownManagementRoom } from "./mjolnirSetupUtils";
|
2021-09-22 12:59:11 -04:00
|
|
|
|
2021-09-24 05:12:18 -04:00
|
|
|
// When Mjolnir starts (src/index.ts) it clobbers the config by resolving the management room
|
|
|
|
// alias specified in the config (config.managementRoom) and overwriting that with the room ID.
|
|
|
|
// Unfortunately every piece of code importing that config imports the same instance, including
|
|
|
|
// testing code, which is problematic when we want to create a fresh management room for each test.
|
|
|
|
// So there is some code in here to "undo" the mutation after we stop Mjolnir syncing.
|
2021-09-23 11:12:08 -04:00
|
|
|
export const mochaHooks = {
|
|
|
|
beforeEach: [
|
2021-10-19 11:34:30 -04:00
|
|
|
async function() {
|
|
|
|
console.log("mochaHooks.beforeEach");
|
|
|
|
this.managementRoomAlias = config.managementRoom;
|
|
|
|
this.mjolnir = await makeMjolnir();
|
|
|
|
config.RUNTIME.client = this.mjolnir.client;
|
|
|
|
this.mjolnir.start();
|
|
|
|
console.log("mochaHooks.beforeEach DONE");
|
|
|
|
}
|
2021-09-23 11:12:08 -04:00
|
|
|
],
|
|
|
|
afterEach: [
|
|
|
|
async function() {
|
|
|
|
await this.mjolnir.stop();
|
|
|
|
// remove alias from management room and leave it.
|
2022-01-17 11:24:12 -05:00
|
|
|
await teardownManagementRoom(this.mjolnir.client, this.mjolnir.managementRoomId, config.managementRoom);
|
2021-09-23 11:12:08 -04:00
|
|
|
}
|
|
|
|
]
|
2021-10-19 11:34:30 -04:00
|
|
|
};
|