update test to mjs
This commit is contained in:
parent
cde7ceda6e
commit
99308155d6
8 changed files with 784 additions and 1106 deletions
28
tests/messageformatter.mjs
Normal file
28
tests/messageformatter.mjs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import chalk from 'chalk';
|
||||
|
||||
const describe = (jsHandle) => jsHandle.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} `));
|
||||
};
|
||||
|
||||
export default formatter;
|
||||
Loading…
Add table
Add a link
Reference in a new issue