11import { SuiteResult } from './Results' ;
22import { Archiver } from '../framework/Archiver' ;
3- import { Style } from './Style' ;
4- import { Verbosity } from './index' ;
3+ import { Style , styling as styleMap } from './Style' ;
4+ import { StyleType , Verbosity } from './index' ;
55import { version } from '../../package.json' ;
66import { green , red , yellow } from 'ansi-colors' ;
77import { Outcome , SilentDescriber } from './describers/Describer' ;
@@ -39,32 +39,44 @@ export class Reporter {
3939
4040 private archiver : Archiver ;
4141
42- private readonly style : Style ;
42+ private design : Style ;
4343
44- private readonly verbosity : Verbosity ;
44+ private verboseness : Verbosity ;
4545
46- constructor ( style : Style , verbosity : Verbosity = Verbosity . normal ) {
47- this . style = style ;
48- this . verbosity = verbosity ;
46+ constructor ( style : StyleType = StyleType . plain , verbosity : Verbosity = Verbosity . normal ) {
47+ this . design = styleMap ( style ) ;
48+ this . verboseness = verbosity ;
4949 this . archiver = new Archiver ( `${ process . env . TESTFILE ?. replace ( '.asserts.wast' , '.wast' ) ?? 'suite' } .${ Date . now ( ) } .log` ) ;
5050 this . archiver . set ( 'date' , new Date ( Date . now ( ) ) . toISOString ( ) ) ;
5151 }
5252
5353 private indent ( override ?: number ) {
54- return indent ( override ?? this . indentationLevel , this . style . indentation ) ;
54+ return indent ( override ?? this . indentationLevel , this . design . indentation ) ;
55+ }
56+
57+ style ( type : StyleType ) {
58+ this . design = styleMap ( type ) ;
59+ }
60+
61+ styling ( ) : StyleType {
62+ return this . design . type ;
63+ }
64+
65+ verbosity ( level : Verbosity ) {
66+ this . verboseness = level ;
5567 }
5668
5769 general ( ) {
58- console . log ( this . indent ( ) + this . style . colors . highlight ( this . style . bullet ) + this . style . colors . highlight ( 'latch.' ) + this . style . emph ( ' General information' ) ) ;
70+ console . log ( this . indent ( ) + this . design . colors . highlight ( this . design . bullet ) + this . design . colors . highlight ( 'latch.' ) + this . design . emph ( ' General information' ) ) ;
5971 // console.log(blue(`${this.indent()}===================`));
60- console . log ( this . indent ( ) + ' ' . repeat ( 2 ) + this . style . emph ( 'version' ) + ' ' . repeat ( 5 ) + version ) ;
61- console . log ( this . indent ( ) + ' ' . repeat ( 2 ) + this . style . emph ( 'archive' ) + ' ' . repeat ( 5 ) + this . archiver . archive ) ;
72+ console . log ( this . indent ( ) + ' ' . repeat ( 2 ) + this . design . emph ( 'version' ) + ' ' . repeat ( 5 ) + version ) ;
73+ console . log ( this . indent ( ) + ' ' . repeat ( 2 ) + this . design . emph ( 'archive' ) + ' ' . repeat ( 5 ) + this . archiver . archive ) ;
6274 console . log ( ) ;
6375 }
6476
6577 report ( suiteResult : SuiteResult ) {
6678 this . suites . push ( suiteResult ) ;
67- const report : string [ ] = describer ( this . verbosity , suiteResult ) . describe ( this . style ) ;
79+ const report : string [ ] = describer ( this . verboseness , suiteResult ) . describe ( this . design ) ;
6880
6981 for ( const line of report ) {
7082 console . log ( this . indent ( ) + line ) ;
@@ -88,7 +100,7 @@ export class Reporter {
88100 this . archiver . set ( 'skipped scenarios' , skipped ) ;
89101 this . archiver . set ( 'failed scenarios' , failing ) ;
90102
91- console . log ( this . indent ( ) + this . style . colors . highlight ( this . style . bullet ) + this . style . colors . highlight ( 'results.' ) + this . style . emph ( ' Overview' ) ) ;
103+ console . log ( this . indent ( ) + this . design . colors . highlight ( this . design . bullet ) + this . design . colors . highlight ( 'results.' ) + this . design . emph ( ' Overview' ) ) ;
92104 console . log ( ) ;
93105 this . indentationLevel += 1 ;
94106
@@ -106,19 +118,23 @@ export class Reporter {
106118
107119 const len : number = 12 ;
108120 const pss = [ `${ sc } passing` , `${ passing } passing` , `${ psa } passing` ]
109- console . log ( this . indent ( ) + this . style . emph ( 'Test suites:' ) + ' ' . repeat ( len - pss [ 0 ] . length ) + this . style . emph ( ( sc === tl ? green : red ) ( pss [ 0 ] ) ) + `, ${ tl } total` + this . style . emph ( ` (${ time . toFixed ( 0 ) } ms)` ) ) ;
110- if ( this . verbosity > Verbosity . minimal ) {
111- console . log ( this . indent ( ) + this . style . emph ( 'Scenarios:' ) +
112- ' ' . repeat ( 2 + len - pss [ 1 ] . length ) + this . style . emph ( ( passing === scs . length ? green : red ) ( pss [ 1 ] ) ) +
113- ( skipped > 0 ? ', ' + this . style . emph ( yellow ( `${ skipped } skipped` ) ) : '' ) + `, ${ scs . length } total` ) ;
114- console . log ( this . indent ( ) + this . style . emph ( 'Actions:' ) + ' ' . repeat ( 4 + len - pss [ 2 ] . length ) + this . style . emph ( ( passing === scs . length ? green : red ) ( pss [ 2 ] ) ) + ( timeouts > 0 ? `, ${ timeouts } timeouts` : '' ) + `, ${ total } total` ) ;
121+ console . log ( this . indent ( ) + this . design . emph ( 'Test suites:' ) + ' ' . repeat ( len - pss [ 0 ] . length ) + this . design . emph ( ( sc === tl ? green : red ) ( pss [ 0 ] ) ) + `, ${ tl } total` + this . design . emph ( ` (${ time . toFixed ( 0 ) } ms)` ) ) ;
122+ if ( this . verboseness > Verbosity . minimal ) {
123+ console . log ( this . indent ( ) + this . design . emph ( 'Scenarios:' ) +
124+ ' ' . repeat ( 2 + len - pss [ 1 ] . length ) + this . design . emph ( ( passing === scs . length ? green : red ) ( pss [ 1 ] ) ) +
125+ ( skipped > 0 ? ', ' + this . design . emph ( yellow ( `${ skipped } skipped` ) ) : '' ) + `, ${ scs . length } total` ) ;
126+ console . log ( this . indent ( ) + this . design . emph ( 'Actions:' ) + ' ' . repeat ( 4 + len - pss [ 2 ] . length ) + this . design . emph ( ( passing === scs . length ? green : red ) ( pss [ 2 ] ) ) + ( timeouts > 0 ? `, ${ timeouts } timeouts` : '' ) + `, ${ total } total` ) ;
115127 }
116128 this . indentationLevel -= 1 ;
117129
118130 console . log ( ) ;
119131 this . archiver . write ( ) ;
120132 }
121133
134+ info ( text : string ) {
135+ this . output += `info: ${ text } \n` ;
136+ }
137+
122138 error ( text : string ) {
123139 this . output += `error: ${ text } \n` ;
124140 }
0 commit comments