2022-08-16 10:51:18 -04:00
|
|
|
import { read as configRead } from "../../src/config";
|
2021-09-23 11:12:08 -04:00
|
|
|
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() {
|
2022-02-24 07:43:31 -05:00
|
|
|
console.error("---- entering test", JSON.stringify(this.currentTest.title)); // Makes MatrixClient error logs a bit easier to parse.
|
2021-10-19 11:34:30 -04:00
|
|
|
console.log("mochaHooks.beforeEach");
|
2022-01-25 12:55:02 -05:00
|
|
|
// Sometimes it takes a little longer to register users.
|
2022-10-18 09:48:39 -04:00
|
|
|
this.timeout(30000);
|
2022-08-16 10:51:18 -04:00
|
|
|
const config = this.config = configRead();
|
2021-10-19 11:34:30 -04:00
|
|
|
this.managementRoomAlias = config.managementRoom;
|
2022-08-09 06:29:27 -04:00
|
|
|
this.mjolnir = await makeMjolnir(config);
|
2021-10-19 11:34:30 -04:00
|
|
|
config.RUNTIME.client = this.mjolnir.client;
|
2022-02-15 08:51:20 -05:00
|
|
|
await Promise.all([
|
|
|
|
this.mjolnir.client.setAccountData('org.matrix.mjolnir.protected_rooms', { rooms: [] }),
|
|
|
|
this.mjolnir.client.setAccountData('org.matrix.mjolnir.watched_lists', { references: [] }),
|
|
|
|
]);
|
2022-01-24 09:53:39 -05:00
|
|
|
await this.mjolnir.start();
|
2021-10-19 11:34:30 -04:00
|
|
|
console.log("mochaHooks.beforeEach DONE");
|
|
|
|
}
|
2021-09-23 11:12:08 -04:00
|
|
|
],
|
|
|
|
afterEach: [
|
|
|
|
async function() {
|
2022-02-15 08:51:20 -05:00
|
|
|
this.timeout(10000)
|
2021-09-23 11:12:08 -04:00
|
|
|
await this.mjolnir.stop();
|
2022-02-15 08:51:20 -05:00
|
|
|
await Promise.all([
|
|
|
|
this.mjolnir.client.setAccountData('org.matrix.mjolnir.protected_rooms', { rooms: [] }),
|
|
|
|
this.mjolnir.client.setAccountData('org.matrix.mjolnir.watched_lists', { references: [] }),
|
|
|
|
]);
|
2021-09-23 11:12:08 -04:00
|
|
|
// remove alias from management room and leave it.
|
2022-08-16 10:51:18 -04:00
|
|
|
await teardownManagementRoom(this.mjolnir.client, this.mjolnir.managementRoomId, this.managementRoomAlias);
|
2022-02-24 07:43:31 -05:00
|
|
|
console.error("---- completed test", JSON.stringify(this.currentTest.title), "\n\n"); // Makes MatrixClient error logs a bit easier to parse.
|
2021-09-23 11:12:08 -04:00
|
|
|
}
|
|
|
|
]
|
2021-10-19 11:34:30 -04:00
|
|
|
};
|