mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-16 13:14:58 +08:00
support writing logs to file
This commit is contained in:
parent
7e2d35fdfe
commit
492d8106b2
38
start.js
38
start.js
@ -18,6 +18,7 @@ const assert = require('assert');
|
|||||||
const RiotSession = require('./src/session');
|
const RiotSession = require('./src/session');
|
||||||
const scenario = require('./src/scenario');
|
const scenario = require('./src/scenario');
|
||||||
const RestSessionCreator = require('./src/rest/creator');
|
const RestSessionCreator = require('./src/rest/creator');
|
||||||
|
const fs = require("fs");
|
||||||
|
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
program
|
program
|
||||||
@ -27,6 +28,7 @@ program
|
|||||||
.option('--slow-mo', "run tests slower to follow whats going on", false)
|
.option('--slow-mo', "run tests slower to follow whats going on", false)
|
||||||
.option('--dev-tools', "open chrome devtools in browser window", false)
|
.option('--dev-tools', "open chrome devtools in browser window", false)
|
||||||
.option('--no-sandbox', "same as puppeteer arg", false)
|
.option('--no-sandbox', "same as puppeteer arg", false)
|
||||||
|
.option('--error-log <n>', 'stdout, or a file to dump html and network logs in when the tests fail')
|
||||||
.parse(process.argv);
|
.parse(process.argv);
|
||||||
|
|
||||||
const hsUrl = 'http://localhost:5005';
|
const hsUrl = 'http://localhost:5005';
|
||||||
@ -67,18 +69,13 @@ async function runTests() {
|
|||||||
} catch(err) {
|
} catch(err) {
|
||||||
failure = true;
|
failure = true;
|
||||||
console.log('failure: ', err);
|
console.log('failure: ', err);
|
||||||
if (program.logs) {
|
if (program.errorLog) {
|
||||||
for(let i = 0; i < sessions.length; ++i) {
|
const logs = await createLogs(sessions);
|
||||||
const session = sessions[i];
|
if (program.errorLog === "stdout") {
|
||||||
documentHtml = await session.page.content();
|
process.stdout.write(logs);
|
||||||
console.log(`---------------- START OF ${session.username} LOGS ----------------`);
|
} else {
|
||||||
console.log('---------------- console.log output:');
|
console.log(`wrote logs to "${program.errorLog}"`);
|
||||||
console.log(session.consoleLogs());
|
fs.writeFileSync(program.errorLog, logs);
|
||||||
console.log('---------------- network requests:');
|
|
||||||
console.log(session.networkLogs());
|
|
||||||
console.log('---------------- document html:');
|
|
||||||
console.log(documentHtml);
|
|
||||||
console.log(`---------------- END OF ${session.username} LOGS ----------------`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,6 +95,23 @@ async function runTests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function createLogs(sessions) {
|
||||||
|
let logs = "";
|
||||||
|
for(let i = 0; i < sessions.length; ++i) {
|
||||||
|
const session = sessions[i];
|
||||||
|
documentHtml = await session.page.content();
|
||||||
|
logs = logs + `---------------- START OF ${session.username} LOGS ----------------\n`;
|
||||||
|
logs = logs + '\n---------------- console.log output:\n';
|
||||||
|
logs = logs + session.consoleLogs();
|
||||||
|
logs = logs + '\n---------------- network requests:\n';
|
||||||
|
logs = logs + session.networkLogs();
|
||||||
|
logs = logs + '\n---------------- document html:\n';
|
||||||
|
logs = logs + documentHtml;
|
||||||
|
logs = logs + `\n---------------- END OF ${session.username} LOGS ----------------\n`;
|
||||||
|
}
|
||||||
|
return logs;
|
||||||
|
}
|
||||||
|
|
||||||
runTests().catch(function(err) {
|
runTests().catch(function(err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user