Skip to content

Commit

Permalink
support more logging methods
Browse files Browse the repository at this point in the history
  • Loading branch information
yannbf committed Aug 5, 2022
1 parent 045ea48 commit 66af119
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/setup-page.ts
Expand Up @@ -166,7 +166,8 @@ export const setupPage = async (page) => {
// collect logs to show upon test error
let logs = [];
const spyOnConsole = (originalFn, name) => {
const spyOnConsole = (method, name) => {
const originalFn = console[method];
return function () {
const message = [...arguments].map(composeMessage).join(', ');
const prefix = \`\${bold(name)}: \`;
Expand All @@ -175,10 +176,19 @@ export const setupPage = async (page) => {
};
};
console.log = spyOnConsole(console.log, blue('log'));
console.warn = spyOnConsole(console.warn, yellow('warn'));
console.error = spyOnConsole(console.error, red('error'));
console.trace = spyOnConsole(console.trace, magenta('trace'));
// console methods + color function for their prefix
const spiedMethods = {
log: blue,
warn: yellow,
error: red,
trace: magenta,
group: magenta,
groupCollapsed: magenta,
}
Object.entries(spiedMethods).forEach(([method, color]) => {
console[method] = spyOnConsole(method, color(method))
})
return new Promise((resolve, reject) => {
channel.on('${renderedEvent}', () => resolve(document.getElementById('root')));
Expand Down

0 comments on commit 66af119

Please sign in to comment.