@@ -23,6 +23,7 @@ const icon = path.resolve(__dirname, '../assets/jest_logo.png');
2323export default class NotifyReporter extends BaseReporter {
2424 _startRun : ( globalConfig : GlobalConfig ) => * ;
2525 _globalConfig : GlobalConfig ;
26+ _previousSuccess : boolean ;
2627
2728 constructor (
2829 globalConfig : GlobalConfig ,
@@ -31,21 +32,37 @@ export default class NotifyReporter extends BaseReporter {
3132 super ( ) ;
3233 this . _globalConfig = globalConfig ;
3334 this . _startRun = startRun ;
35+ this . _previousSuccess = false ;
36+ this . _firstRun = true ;
3437 }
3538
3639 onRunComplete ( contexts : Set < Context > , result : AggregatedResult ) : void {
3740 const success =
3841 result . numFailedTests === 0 && result . numRuntimeErrorTestSuites === 0 ;
3942
40- if ( success ) {
43+ if (
44+ success &&
45+ ( this . _globalConfig === 'always' ||
46+ this . _globalConfig === 'success' ||
47+ ( this . _globalConfig === 'change' &&
48+ ( ! this . _previousSuccess || this . _firstRun ) ) )
49+ ) {
4150 const title = util . format ( '%d%% Passed' , 100 ) ;
4251 const message = util . format (
4352 ( isDarwin ? '\u2705 ' : '' ) + '%d tests passed' ,
4453 result . numPassedTests ,
4554 ) ;
4655
4756 notifier . notify ( { icon, message, title} ) ;
48- } else {
57+ this . _previousSuccess = true ;
58+ this . _firstRun = false ;
59+ } else if (
60+ ! success &&
61+ ( this . _globalConfig === 'always' ||
62+ this . _globalConfig === 'failure' ||
63+ ( this . _globalConfig === 'change' &&
64+ ( this . _previousSuccess || this . _firstRun ) ) )
65+ ) {
4966 const failed = result . numFailedTests / result . numTotalTests ;
5067
5168 const title = util . format (
@@ -81,6 +98,8 @@ export default class NotifyReporter extends BaseReporter {
8198 }
8299 } ,
83100 ) ;
101+ this . _previousSuccess = false ;
102+ this . _firstRun = false ;
84103 }
85104 }
86105}
0 commit comments