-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(integration): Improve Playwright logging (#2243)
* chore(repo): Use other playwright reporters * chore(repo): Use colored text & not bg * chore(repo): Remove white from choices * chore(repo): Add bright colors
- Loading branch information
Showing
3 changed files
with
20 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,36 @@ | ||
/* eslint-disable turbo/no-undeclared-env-vars */ | ||
import { default as chalk } from 'chalk'; | ||
|
||
const getRandomChalkBgColor = () => { | ||
const colors = ['bgRed', 'bgGreen', 'bgYellow', 'bgBlue', 'bgMagenta', 'bgCyan', 'bgWhite']; | ||
const getRandomChalkColor = () => { | ||
const colors = [ | ||
'red', | ||
'green', | ||
'yellow', | ||
'blue', | ||
'magenta', | ||
'cyan', | ||
'redBright', | ||
'greenBright', | ||
'yellowBright', | ||
'blueBright', | ||
'magentaBright', | ||
'cyanBright', | ||
]; | ||
return colors[Math.floor(Math.random() * colors.length)]; | ||
}; | ||
|
||
type CreateLoggerOptions = { prefix: string; color?: string }; | ||
export const createLogger = (opts: CreateLoggerOptions) => { | ||
const { color, prefix } = opts; | ||
const prefixBgColor = color || getRandomChalkBgColor(); | ||
const prefixColor = color || getRandomChalkColor(); | ||
return { | ||
info: (msg: string) => { | ||
if (process.env.DEBUG) { | ||
console.info(`${chalk[prefixBgColor](`[${prefix}]`)} ${msg}`); | ||
console.info(`${chalk[prefixColor](`[${prefix}]`)} ${msg}`); | ||
} | ||
}, | ||
child: (childOpts: CreateLoggerOptions) => { | ||
return createLogger({ prefix: `${prefix} :: ${childOpts.prefix}`, color: prefixBgColor }); | ||
return createLogger({ prefix: `${prefix} :: ${childOpts.prefix}`, color: prefixColor }); | ||
}, | ||
}; | ||
}; |