Skip to content

Commit

Permalink
Merge pull request #2959 from preactjs/duplicate-console
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Jan 26, 2021
2 parents d34b413 + e0b0b72 commit a288d0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const fs = require('fs').promises;
const orgStdoutWrite = process.stdout.write;
process.stdout.write = msg => {
let out = '';
const match = msg.match(/(^|.*\s)(LOG|WARN|ERROR):\s'([\s\S]*)'/);
const match = msg.match(
/(^|.*\s)(LOG|WARN|ERROR):\s'__LOG_CUSTOM:([\S\s]*)'/
);
if (match && match.length >= 4) {
// Sometimes the UA of the browser will be included in the message
if (match[1].length) {
Expand All @@ -29,6 +31,8 @@ process.stdout.write = msg => {
out += match[3];
}
out += '\n';
} else if (/(^|.*\s)(LOG|WARN|ERROR):\s([\S\s]*)/.test(msg)) {
// Nothing
} else {
out = msg;
}
Expand Down
7 changes: 6 additions & 1 deletion test/polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function patchConsole(method) {
window.console[method] = (...args) => {
// @ts-ignore
// eslint-disable-next-line no-undef
__karma__.log(method, serializeConsoleArgs(args));
__karma__.log(method, ['__LOG_CUSTOM:' + serializeConsoleArgs(args)]);
original.apply(window.console, args);
};
}
Expand Down Expand Up @@ -197,6 +197,10 @@ function serialize(value, mode, indent, seen) {
return kl.cyan(`[Function: ${value.name || 'anonymous'}]`);
}

if (value instanceof Element) {
return value.outerHTML;
}

seen.add(value);

const props = Object.keys(value).map(key => {
Expand Down Expand Up @@ -253,3 +257,4 @@ function serialize(value, mode, indent, seen) {
// new Set([1, 2]),
// new Map([[1, 2]])
// );
// console.log(document.createElement('div'));

0 comments on commit a288d0f

Please sign in to comment.