Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(integration): Improve Playwright logging #2243

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration/models/applicationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const applicationConfig = () => {
const files = new Map<string, string>();
const scripts: Scripts = { dev: 'npm run dev', serve: 'npm run serve', build: 'npm run build', setup: 'npm i' };
const envFormatters = { public: (key: string) => key, private: (key: string) => key };
const logger = createLogger({ prefix: 'appConfig', color: 'bgYellow' });
const logger = createLogger({ prefix: 'appConfig', color: 'yellow' });
const dependencies = new Map<string, string>();

const self = {
Expand Down
2 changes: 1 addition & 1 deletion integration/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const common: PlaywrightTestConfig = {
timeout: process.env.CI ? 90000 : 30000,
maxFailures: process.env.CI ? 1 : undefined,
workers: process.env.CI ? numAvailableWorkers : '70%',
reporter: [[process.env.CI ? 'html' : 'line', { open: 'never' }]] as any,
reporter: process.env.CI ? 'line' : 'list',
use: {
trace: 'on-first-retry',
bypassCSP: true, // We probably need to limit this to specific tests
Expand Down
23 changes: 18 additions & 5 deletions integration/scripts/logger.ts
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 });
},
};
};
Loading