add test via multiple locations

This commit is contained in:
Matt Walsh
2023-01-17 16:10:06 -06:00
parent 888b35ea73
commit 249cbb93e6
9 changed files with 1601 additions and 9 deletions

28
tests/messageformatter.js Normal file
View File

@@ -0,0 +1,28 @@
const chalk = require('chalk');
const describe = (jsHandle) => jsHandle.executionContext().evaluate(
// serialize |obj| however you want
(obj) => `OBJ: ${typeof obj}, ${obj}`,
jsHandle,
);
const colors = {
LOG: chalk.grey,
ERR: chalk.red,
WAR: chalk.yellow,
INF: chalk.cyan,
};
const formatter = async (message) => {
const args = await Promise.all(message.args().map((arg) => describe(arg)));
// make ability to paint different console[types]
const type = message.type().substr(0, 3).toUpperCase();
const color = colors[type] || chalk.blue;
let text = '';
for (let i = 0; i < args.length; i += 1) {
text += `[${i}] ${args[i]} `;
}
console.log(color(`CONSOLE.${type}: ${message.text()}\n${text} `));
};
module.exports = formatter;