Bug 1499533 - Fix console log stringifying bug in webcompat reporter; r=miketaylr

Fix console log stringifying bug in webcompat reporter

Differential Revision: https://phabricator.services.mozilla.com/D8984

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Wisniewski 2018-10-18 02:51:30 +00:00
parent 116bfa4345
commit 832717d698
3 changed files with 13 additions and 2 deletions

View File

@ -47,8 +47,8 @@ function getInfoFrameScript(messageName) {
return messages.map(evt => {
const {columnNumber, filename, level, lineNumber, timeStamp} = evt;
const args = evt.arguments.map(arg => {
return arg.toString();
});
return "" + arg;
}).join(", ");
const message = `[console.${level}(${args}) ${filename}:${lineNumber}:${columnNumber}]`;
return {timeStamp, message};
});

View File

@ -61,6 +61,9 @@ add_task(async function test_opened_page() {
const details = JSON.parse(detailsParam);
ok(typeof details == "object", "Details param is a stringified JSON object.");
ok(Array.isArray(details.consoleLog), "Details has a consoleLog array.");
ok(details.consoleLog[0].match(/console\.log\(null\)[\s\S]*test.html:\d+:\d+/m), "Can handle degenerate console logs");
ok(details.consoleLog[1].match(/console\.error\(colored message\)[\s\S]*test.html:\d+:\d+/m), "Can handle fancy console logs");
ok(details.consoleLog[2].match(/document\.access is undefined[\s\S]*test.html:\d+:\d+/m), "Script errors are logged");
ok(typeof details.buildID == "string", "Details has a buildID string.");
ok(typeof details.channel == "string", "Details has a channel string.");
ok(typeof details.hasTouchScreen == "boolean", "Details has a hasTouchScreen flag.");

View File

@ -1,5 +1,13 @@
<!DOCTYPE html>
<meta charset="utf-8">
<script>
/* eslint-disable no-console */
/* eslint-disable no-unused-expressions */
"use strict";
console.log(null);
console.error("%ccolored message", "background:green; color:white");
document.access.non.existent.property.to.trigger.error;
</script>
<style>
body {background: rgb(0, 128, 0);}
</style>