mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Give mjolnir a clean history in each test
This commit is contained in:
parent
68aa717826
commit
ff216f4918
@ -1,19 +1,27 @@
|
||||
import config from "../../src/config";
|
||||
import { Mjolnir } from "../../src/Mjolnir";
|
||||
import { makeMjolnir } from "./mjolnirSetupUtils";
|
||||
import { makeMjolnir, teardownManagementRoom } from "./mjolnirSetupUtils";
|
||||
|
||||
export async function mochaGlobalSetup() {
|
||||
console.log("Starting mjolnir.");
|
||||
try {
|
||||
this.bot = await makeMjolnir()
|
||||
// do not block on this!
|
||||
this.bot.start();
|
||||
} catch (e) {
|
||||
console.trace(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function mochaGlobalTeardown() {
|
||||
this.bot.stop();
|
||||
console.log('stopping mjolnir');
|
||||
}
|
||||
// when mjolnir starts it clobbers the config, which is cached between runs,
|
||||
// by resolving the alias and setting it to a roomid.
|
||||
export const mochaHooks = {
|
||||
beforeEach: [
|
||||
async function() {
|
||||
this.managementRoomAlias = config.managementRoom
|
||||
this.mjolnir = await makeMjolnir()
|
||||
this.mjolnir.start()
|
||||
}
|
||||
],
|
||||
afterEach: [
|
||||
async function() {
|
||||
console.log("stopping mjolnir");
|
||||
await this.mjolnir.stop();
|
||||
// unclobber mjolnir's dirty work, i thought the config was being cached
|
||||
// and was global, but that might have just been supersitiion, needs confirming.
|
||||
let managementRoomId = config.managementRoom;
|
||||
config.managementRoom = this.managementRoomAlias;
|
||||
// remove alias from management room and leave it.
|
||||
await teardownManagementRoom(this.mjolnir.client, managementRoomId, this.managementRoomAlias);
|
||||
}
|
||||
]
|
||||
};
|
@ -12,6 +12,7 @@ describe("help command", () => {
|
||||
})
|
||||
it('Mjolnir responded to !mjolnir help', async function() {
|
||||
this.timeout(30000);
|
||||
console.log(`management room ${config.managementRoom}`);
|
||||
// send a messgage
|
||||
await client.joinRoom(config.managementRoom);
|
||||
// listener for getting the event reply
|
||||
@ -23,6 +24,7 @@ describe("help command", () => {
|
||||
}
|
||||
}))});
|
||||
// check we get one back
|
||||
console.log(config);
|
||||
await client.sendMessage(config.managementRoom, {msgtype: "m.text", body: "!mjolnir help"})
|
||||
await reply
|
||||
})
|
||||
|
@ -75,4 +75,9 @@ export async function makeMjolnir() {
|
||||
const client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password);
|
||||
await ensureManagementRoomExists(client);
|
||||
return await setupMjolnir(client, config);
|
||||
}
|
||||
|
||||
export async function teardownManagementRoom(client: MatrixClient, roomId: string, alias: string) {
|
||||
await client.deleteRoomAlias(alias);
|
||||
await client.leaveRoom(roomId);
|
||||
}
|
Loading…
Reference in New Issue
Block a user