1
+ var q = require ( 'q' ) ;
1
2
2
3
var IonicSnapshot = function ( options ) {
3
4
@@ -22,6 +23,7 @@ var IonicSnapshot = function(options) {
22
23
self . width = browser . params . width || - 1 ;
23
24
self . height = browser . params . height || - 1 ;
24
25
self . highestMismatch = 0 ;
26
+ self . screenshotRequestPromises = [ ] ;
25
27
26
28
self . flow = protractor . promise . controlFlow ( ) ;
27
29
@@ -48,7 +50,6 @@ var IonicSnapshot = function(options) {
48
50
} ;
49
51
} ) ;
50
52
} ) ;
51
-
52
53
process . on ( 'exit' , function ( ) {
53
54
log ( colors . green ( 'Highest Mismatch:' ) , self . highestMismatch , '%' ) ;
54
55
} ) ;
@@ -61,7 +62,7 @@ var IonicSnapshot = function(options) {
61
62
62
63
if ( ! self . testData . total_specs ) {
63
64
self . testData . total_specs = 0 ;
64
- var allSpecs = jasmine . getEnv ( ) . currentRunner ( ) . specs ( )
65
+ var allSpecs = jasmine . getEnv ( ) . currentRunner ( ) . specs ( ) ;
65
66
for ( var sId in allSpecs ) {
66
67
self . testData . total_specs ++ ;
67
68
}
@@ -75,30 +76,34 @@ var IonicSnapshot = function(options) {
75
76
browser . sleep ( self . sleepBetweenSpecs ) . then ( function ( ) {
76
77
77
78
browser . takeScreenshot ( ) . then ( function ( pngBase64 ) {
78
- log ( 'spec:' , spec . id + 1 , 'of' , self . testData . total_specs ) ;
79
+ var specIdString = '[' + ( spec . id + 1 ) + '/' + self . testData . total_specs + ']' ;
80
+ log ( specIdString , spec . getFullName ( ) ) ;
79
81
80
82
self . testData . spec_id = spec . id ;
81
83
self . testData . description = spec . getFullName ( ) ;
82
84
self . testData . highest_mismatch = self . highestMismatch ;
83
85
self . testData . png_base64 = pngBase64 ;
84
86
pngBase64 = null ;
85
87
88
+ var requestDeferred = q . defer ( ) ;
89
+ self . screenshotRequestPromises . push ( requestDeferred . promise ) ;
90
+
86
91
request . post (
87
92
'http://' + self . domain + '/screenshot' ,
88
93
{ form : self . testData } ,
89
94
function ( error , response , body ) {
90
- log ( 'reportSpecResults:' , body ) ;
95
+ log ( specIdString , 'reportSpecResults:' , body ) ;
91
96
try {
92
97
var rspData = JSON . parse ( body ) ;
93
98
self . highestMismatch = Math . max ( self . highestMismatch , rspData . Mismatch ) ;
94
99
} catch ( e ) {
95
- log ( colors . red ( 'reportSpecResults error posting screenshot:' ) , e ) ;
100
+ log ( specIdString , colors . red ( 'reportSpecResults' , ' error posting screenshot:') , e ) ;
96
101
}
97
- d . fulfill ( ) ;
102
+ requestDeferred . resolve ( ) ;
98
103
}
99
104
) ;
105
+ d . fulfill ( ) ;
100
106
} ) ;
101
-
102
107
} ) ;
103
108
104
109
} ) ;
@@ -107,6 +112,22 @@ var IonicSnapshot = function(options) {
107
112
} ) ;
108
113
} ;
109
114
115
+ IonicReporter . prototype . reportRunnerResults = function ( ) {
116
+ var self = this ;
117
+
118
+ self . flow . execute ( function ( ) {
119
+ var d = protractor . promise . defer ( ) ;
120
+ log ( 'Waiting for all screenshots to be posted...' ) ;
121
+ // allSettled waits until all the promises are done, whether they are rejected or resolved
122
+ q . allSettled ( self . screenshotRequestPromises ) . then ( function ( all ) {
123
+ d . fulfill ( ) ;
124
+ log ( 'Finished!' ) ;
125
+ } ) ;
126
+ } ) ;
127
+ } ;
128
+
129
+
130
+
110
131
this . jasmine . getEnv ( ) . addReporter ( new IonicReporter ( options ) ) ;
111
132
112
133
} ;
0 commit comments