@@ -13,32 +13,33 @@ import {
1313 reportRawOverviewTableHeaders ,
1414} from './utils' ;
1515
16- let output = '' ;
17-
18- const addLine = ( text = '' ) => ( output += text + '\n' ) ;
19- const print = ( text : string ) => console . log ( text ) ;
20-
21- export function reportToStdout ( report : ScoredReport ) : void {
22- addLine ( ) ;
23- reportToHeaderSection ( report ) ;
24- addLine ( ) ;
25- reportToDetailSection ( report ) ;
26- addLine ( ) ;
27- reportToOverviewSection ( report ) ;
28- addLine ( ) ;
29- addLine ( `${ FOOTER_PREFIX } ${ CODE_PUSHUP_DOMAIN } ` ) ;
30-
31- print ( output ) ;
16+ function addLine ( line = '' ) : string {
17+ return line + '\n' ;
3218}
3319
34- function reportToHeaderSection ( report : ScoredReport ) : void {
20+ export function reportToStdout ( report : ScoredReport ) : string {
21+ let output = '' ;
22+
23+ output += addLine ( reportToHeaderSection ( report ) ) ;
24+ output += addLine ( ) ;
25+ output += addLine ( reportToDetailSection ( report ) ) ;
26+ output += addLine ( reportToOverviewSection ( report ) ) ;
27+ output += addLine ( `${ FOOTER_PREFIX } ${ CODE_PUSHUP_DOMAIN } ` ) ;
28+
29+ return output ;
30+ }
31+
32+ function reportToHeaderSection ( report : ScoredReport ) : string {
3533 const { packageName, version } = report ;
36- addLine ( `${ chalk . bold ( reportHeadlineText ) } - ${ packageName } @${ version } ` ) ;
34+ return `${ chalk . bold ( reportHeadlineText ) } - ${ packageName } @${ version } ` ;
3735}
3836
39- function reportToOverviewSection ( { categories, plugins } : ScoredReport ) : void {
40- addLine ( chalk . magentaBright . bold ( 'Categories' ) ) ;
41- addLine ( ) ;
37+ function reportToOverviewSection ( {
38+ categories,
39+ plugins,
40+ } : ScoredReport ) : string {
41+ let output = addLine ( chalk . magentaBright . bold ( 'Categories' ) ) ;
42+ output += addLine ( ) ;
4243
4344 const table = new Table ( {
4445 head : reportRawOverviewTableHeaders ,
@@ -56,15 +57,20 @@ function reportToOverviewSection({ categories, plugins }: ScoredReport): void {
5657 ] ) ,
5758 ) ;
5859
59- addLine ( table . toString ( ) ) ;
60+ output += addLine ( table . toString ( ) ) ;
61+
62+ return output ;
6063}
6164
62- function reportToDetailSection ( report : ScoredReport ) : void {
65+ function reportToDetailSection ( report : ScoredReport ) : string {
6366 const { plugins } = report ;
6467
68+ let output = '' ;
69+
6570 plugins . forEach ( ( { title, audits } ) => {
66- addLine ( chalk . magentaBright . bold ( `${ title } audits` ) ) ;
67- addLine ( ) ;
71+ output += addLine ( ) ;
72+ output += addLine ( chalk . magentaBright . bold ( `${ title } audits` ) ) ;
73+ output += addLine ( ) ;
6874
6975 const ui = cliui ( { width : 80 } ) ;
7076
@@ -87,8 +93,11 @@ function reportToDetailSection(report: ScoredReport): void {
8793 ) ;
8894 } ) ;
8995
90- addLine ( ui . toString ( ) ) ;
96+ output += addLine ( ui . toString ( ) ) ;
97+ output += addLine ( ) ;
9198 } ) ;
99+
100+ return output ;
92101}
93102
94103function withColor ( { score, text } : { score : number ; text ?: string } ) {
0 commit comments