Skip to content

Commit

Permalink
test: Console printing improvements
Browse files Browse the repository at this point in the history
Print numbers, "null", and "undefined" nicely with Chromium.

Let's never abort a test just because converting a console.log
argument crashes.
  • Loading branch information
mvollmer committed Nov 8, 2023
1 parent 73d5249 commit 80fca0f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions test/common/chromium-cdp-driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,26 @@ function clearExceptions() {
}

function stringifyConsoleArg(arg) {
if (arg.type === 'string')
return arg.value;
if (arg.type === 'object') {
const obj = {};
arg.preview.properties.forEach(prop => {
obj[prop.name] = prop.value.toString();
});
return JSON.stringify(obj);
try {
if (arg.type === 'string')
return arg.value;
if (arg.type === 'number')
return arg.value;
if (arg.type === 'undefined')
return "undefined";
if (arg.value === null)
return "null";
if (arg.type === 'object' && arg.preview?.properties) {
const obj = {};
arg.preview.properties.forEach(prop => {
obj[prop.name] = prop.value.toString();
});
return JSON.stringify(obj);
}
return JSON.stringify(arg);
} catch (error) {
return "[error stringifying argument: " + error.toString() + "]";
}
return JSON.stringify(arg);
}

function setupLogging(client) {
Expand Down

0 comments on commit 80fca0f

Please sign in to comment.