@@ -16,6 +16,7 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
1616
1717 this . failures = [ ] ;
1818 this . USE_COLORS = false ;
19+ this . slowPokes = [ ] ;
1920
2021 // colorize output of BaseReporter functions
2122 if ( config . colors ) {
@@ -46,11 +47,15 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
4647 this . logFinalErrors ( this . failures ) ;
4748 }
4849 }
50+ if ( this . reportSlowerThan ) {
51+ this . logFinalSlow ( this . slowPokes ) ;
52+ }
4953 }
5054
5155 this . write ( '\n' ) ;
5256 this . failures = [ ] ;
5357 this . currentSuite = [ ] ;
58+ this . slowPokes = [ ] ;
5459 } ;
5560
5661 this . logFinalErrors = function ( errors ) {
@@ -78,6 +83,35 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
7883 this . writeCommonMsg ( '\n' ) ;
7984 } ;
8085
86+ this . logFinalSlow = function ( slowPokes ) {
87+ this . writeCommonMsg ( '\n\n' ) ;
88+ this . WHITESPACE = ' ' ;
89+ slowPokes
90+ . sort ( function ( next , prev ) {
91+ if ( next . time > prev . time ) {
92+ return - 1 ;
93+ } else if ( next . time < prev . time ) {
94+ return 1 ;
95+ } else {
96+ return 0 ;
97+ }
98+ } )
99+ . forEach ( function ( slowPoke , index ) {
100+ // Only show the top 5
101+ if ( index > 4 ) {
102+ return ;
103+ }
104+
105+ index = index + 1 ;
106+
107+ if ( index == 1 ) {
108+ this . writeCommonMsg ( ( 'SLOW: ' + slowPokes . length + '\n\n' ) . yellow ) ;
109+ this . writeCommonMsg ( ( '5 Slowest: ' + '\n' ) . yellow ) ;
110+ }
111+ this . writeCommonMsg ( ( index + ') ' + slowPoke . fullName + ' (' + slowPoke . time + ')' + '\n' ) . yellow ) ;
112+ } , this ) ;
113+ } ;
114+
81115 this . currentSuite = [ ] ;
82116 this . writeSpecMessage = function ( status ) {
83117 return ( function ( browser , result ) {
@@ -102,6 +136,10 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
102136 var browserName = reporterCfg . showBrowser ? ' [' + browser . name + ']' : '' ;
103137 var elapsedTime = reporterCfg . showSpecTiming ? ' (' + result . time + 'ms)' : '' ;
104138
139+ if ( this . reportSlowerThan && result . time > config . reportSlowerThan ) {
140+ this . logSlowPoke ( result ) ;
141+ }
142+
105143 if ( this . USE_COLORS ) {
106144 if ( result . skipped ) specName = specName . cyan ;
107145 else if ( ! result . success ) specName = specName . red ;
@@ -146,12 +184,21 @@ var SpecReporter = function (baseReporterDecorator, formatError, config) {
146184 }
147185 } ;
148186
149- this . specSuccess = reporterCfg . suppressPassed ? noop : this . writeSpecMessage ( this . USE_COLORS ? this . prefixes . success . green : this . prefixes . success ) ;
150- this . specSkipped = reporterCfg . suppressSkipped ? noop : this . writeSpecMessage ( this . USE_COLORS ? this . prefixes . skipped . cyan : this . prefixes . skipped ) ;
187+ this . logSlowPoke = function ( result ) {
188+ this . slowPokes . push ( result ) ;
189+ } ;
190+
191+ this . specSuccess = reporterCfg . suppressPassed
192+ ? noop
193+ : this . writeSpecMessage ( this . USE_COLORS ? this . prefixes . success . green : this . prefixes . success ) ;
194+ this . specSkipped = reporterCfg . suppressSkipped
195+ ? noop
196+ : this . writeSpecMessage ( this . USE_COLORS ? this . prefixes . skipped . cyan : this . prefixes . skipped ) ;
151197 this . specFailure = reporterCfg . suppressFailed ? noop : this . onSpecFailure ;
152198 this . suppressErrorSummary = reporterCfg . suppressErrorSummary || false ;
153199 this . showSpecTiming = reporterCfg . showSpecTiming || false ;
154200 this . showBrowser = reporterCfg . showBrowser || false ;
201+ this . reportSlowerThan = config . reportSlowerThan || false ;
155202} ;
156203
157204SpecReporter . $inject = [ 'baseReporterDecorator' , 'formatError' , 'config' ] ;
0 commit comments