mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-09-29 20:56:23 +00: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 { Mjolnir } from "../../src/Mjolnir";
|
||||||
import { makeMjolnir } from "./mjolnirSetupUtils";
|
import { makeMjolnir, teardownManagementRoom } from "./mjolnirSetupUtils";
|
||||||
|
|
||||||
export async function mochaGlobalSetup() {
|
// when mjolnir starts it clobbers the config, which is cached between runs,
|
||||||
console.log("Starting mjolnir.");
|
// by resolving the alias and setting it to a roomid.
|
||||||
try {
|
export const mochaHooks = {
|
||||||
this.bot = await makeMjolnir()
|
beforeEach: [
|
||||||
// do not block on this!
|
async function() {
|
||||||
this.bot.start();
|
this.managementRoomAlias = config.managementRoom
|
||||||
} catch (e) {
|
this.mjolnir = await makeMjolnir()
|
||||||
console.trace(e);
|
this.mjolnir.start()
|
||||||
throw e;
|
}
|
||||||
}
|
],
|
||||||
}
|
afterEach: [
|
||||||
|
async function() {
|
||||||
export async function mochaGlobalTeardown() {
|
console.log("stopping mjolnir");
|
||||||
this.bot.stop();
|
await this.mjolnir.stop();
|
||||||
console.log('stopping mjolnir');
|
// 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() {
|
it('Mjolnir responded to !mjolnir help', async function() {
|
||||||
this.timeout(30000);
|
this.timeout(30000);
|
||||||
|
console.log(`management room ${config.managementRoom}`);
|
||||||
// send a messgage
|
// send a messgage
|
||||||
await client.joinRoom(config.managementRoom);
|
await client.joinRoom(config.managementRoom);
|
||||||
// listener for getting the event reply
|
// listener for getting the event reply
|
||||||
@ -23,6 +24,7 @@ describe("help command", () => {
|
|||||||
}
|
}
|
||||||
}))});
|
}))});
|
||||||
// check we get one back
|
// check we get one back
|
||||||
|
console.log(config);
|
||||||
await client.sendMessage(config.managementRoom, {msgtype: "m.text", body: "!mjolnir help"})
|
await client.sendMessage(config.managementRoom, {msgtype: "m.text", body: "!mjolnir help"})
|
||||||
await reply
|
await reply
|
||||||
})
|
})
|
||||||
|
@ -75,4 +75,9 @@ export async function makeMjolnir() {
|
|||||||
const client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password);
|
const client = await pantalaimon.createClientWithCredentials(config.pantalaimon.username, config.pantalaimon.password);
|
||||||
await ensureManagementRoomExists(client);
|
await ensureManagementRoomExists(client);
|
||||||
return await setupMjolnir(client, config);
|
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