From 492d8106b2a7ee6f06406b5c5c929dff9d2f5d55 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 8 Apr 2019 17:00:19 +0200 Subject: [PATCH] support writing logs to file --- start.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/start.js b/start.js index 8c8b640595..ab710664ec 100644 --- a/start.js +++ b/start.js @@ -18,6 +18,7 @@ const assert = require('assert'); const RiotSession = require('./src/session'); const scenario = require('./src/scenario'); const RestSessionCreator = require('./src/rest/creator'); +const fs = require("fs"); const program = require('commander'); program @@ -27,6 +28,7 @@ program .option('--slow-mo', "run tests slower to follow whats going on", false) .option('--dev-tools', "open chrome devtools in browser window", false) .option('--no-sandbox', "same as puppeteer arg", false) + .option('--error-log ', 'stdout, or a file to dump html and network logs in when the tests fail') .parse(process.argv); const hsUrl = 'http://localhost:5005'; @@ -67,18 +69,13 @@ async function runTests() { } catch(err) { failure = true; console.log('failure: ', err); - if (program.logs) { - for(let i = 0; i < sessions.length; ++i) { - const session = sessions[i]; - documentHtml = await session.page.content(); - console.log(`---------------- START OF ${session.username} LOGS ----------------`); - console.log('---------------- console.log output:'); - console.log(session.consoleLogs()); - console.log('---------------- network requests:'); - console.log(session.networkLogs()); - console.log('---------------- document html:'); - console.log(documentHtml); - console.log(`---------------- END OF ${session.username} LOGS ----------------`); + if (program.errorLog) { + const logs = await createLogs(sessions); + if (program.errorLog === "stdout") { + process.stdout.write(logs); + } else { + console.log(`wrote logs to "${program.errorLog}"`); + fs.writeFileSync(program.errorLog, 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) { console.log(err); process.exit(-1);