Skip to content

Commit

Permalink
Fix on console event logging
Browse files Browse the repository at this point in the history
  • Loading branch information
astefanutti committed Mar 2, 2024
1 parent 9d2a4ae commit 54aa7b8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions decktape.js
Expand Up @@ -227,7 +227,7 @@ if (os.name === 'windows') parser.nocolors();
const color = type => {
switch (type) {
case 'error': return chalk.red;
case 'warning': return chalk.yellow;
case 'warn': return chalk.yellow;
default: return chalk.gray;
}
};
Expand Down Expand Up @@ -273,11 +273,12 @@ process.on('unhandledRejection', error => {

page
.on('console', async msg => {
const args = msg.type() !== 'log'
? await Promise.all(msg.args().map(arg => arg.executionContext().evaluate(obj => obj, arg)))
: [msg.text()];
if (args.length > 0)
if (msg.type() === 'log') {
const args = await Promise.all(msg.args().map(arg => arg.evaluate(obj => obj, arg)));
console.log(...args.map(arg => color(msg.type())(util.format(arg))));
} else {
console.log(color(msg.type())(util.format(msg.text())));
}
})
.on('requestfailed', request => {
// do not output warning for cancelled requests
Expand Down

0 comments on commit 54aa7b8

Please sign in to comment.