All files / reporter/console console.ts

53.85% Statements 7/13
40% Branches 4/10
66.67% Functions 2/3
50% Lines 6/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                  4x   4x 4x 4x     2x                                               2x                
import { ExperimentsObserver } from '../../src/feature/feature.typings';
import { XGroup } from '../../src/typing';
 
export type ConsoleReporterInit = {
	log?: Console['log'];
	badgeStyle?: string;
	pathStyle?: string;
};
 
export function createConsoleReporter(Einit: ConsoleReporterInit = {}): ExperimentsObserver {
	const {
		log = console.log,
		badgeStyle = getDefaultDadgeStyle(),
		pathStyle = 'color: #005ff9',
	} = init;
 
	return (feature, xevt) => {
		let descr = xevt.target.$descr(xevt.data);
		let xgropup = xevt.target.$group()
 
		while (xgropup) {
			descr = `${xgropup.$descr()} → ${descr}`;
			xgropup = xgropup.$group();
		}
 
		log(
			'%c%s%c%s: [ %c%s%c ] %o',
			badgeStyle,
			feature.id + (feature.split ? `:${feature.split}` : ``),
			'',
			descr,
			pathStyle,
			xevt.target.$path().join(' → '),
			'',
			xevt.data,
		);
	};
}
 
function getDefaultDadgeStyle() {
	return `
		background-color: #f60;
		color: #fff;
		padding: 1px 2px 1px;
		border-radius: 2px;
		margin-right: 5px;
	`;
}