move outputting steps to session to scope it to username

This commit is contained in:
Bruno Windels 2018-08-07 17:16:27 +02:00
parent 6b843eacfc
commit 4c0ab117bf
2 changed files with 22 additions and 7 deletions

View file

@ -31,6 +31,20 @@ class LogBuffer {
} }
} }
class Logger {
constructor(username) {
this.username = username;
}
step(description) {
process.stdout.write(` * ${this.username} ${description} ... `);
}
done() {
process.stdout.write("done\n");
}
}
module.exports = class RiotSession { module.exports = class RiotSession {
constructor(browser, page, username, riotserver) { constructor(browser, page, username, riotserver) {
this.browser = browser; this.browser = browser;
@ -43,6 +57,7 @@ module.exports = class RiotSession {
const response = await req.response(); const response = await req.response();
return `${type} ${response.status()} ${req.method()} ${req.url()} \n`; return `${type} ${response.status()} ${req.method()} ${req.url()} \n`;
}, true); }, true);
this.log = new Logger(this.username);
} }
static async create(username, puppeteerOptions, riotserver) { static async create(username, puppeteerOptions, riotserver) {

View file

@ -39,19 +39,19 @@ async function runTests() {
const alice = await RiotSession.create("alice", options, riotserver); const alice = await RiotSession.create("alice", options, riotserver);
sessions.push(alice); sessions.push(alice);
process.stdout.write(`* signing up as ${alice.username} ... `); alice.log.step("signs up");
await signup(alice, alice.username, 'testtest'); await signup(alice, alice.username, 'testtest');
process.stdout.write('done\n'); alice.log.done();
const noticesName = "Server Notices"; const noticesName = "Server Notices";
process.stdout.write(`* accepting "${noticesName}" and accepting terms & conditions ... `); alice.log.step(`accepts "${noticesName}" invite and accepting terms & conditions`);
await acceptServerNoticesInviteAndConsent(alice, noticesName); await acceptServerNoticesInviteAndConsent(alice, noticesName);
process.stdout.write('done\n'); alice.log.done();
const room = 'test'; const room = 'test';
process.stdout.write(`* creating room ${room} ... `); alice.log.step(`creates room ${room}`);
await createRoom(alice, room); await createRoom(alice, room);
process.stdout.write('done\n'); alice.log.done();
await alice.close(); await alice.close();
} }