Skip to content

Commit 538737a

Browse files
committed
chore(ionic-snapshot): make it so screenshots are posting asynchronously
1 parent 6697e66 commit 538737a

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

config/lib/ionic-snapshot.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
var q = require('q');
12

23
var IonicSnapshot = function(options) {
34

@@ -22,6 +23,7 @@ var IonicSnapshot = function(options) {
2223
self.width = browser.params.width || -1;
2324
self.height = browser.params.height || -1;
2425
self.highestMismatch = 0;
26+
self.screenshotRequestPromises = [];
2527

2628
self.flow = protractor.promise.controlFlow();
2729

@@ -48,7 +50,6 @@ var IonicSnapshot = function(options) {
4850
};
4951
});
5052
});
51-
5253
process.on('exit', function() {
5354
log(colors.green('Highest Mismatch:'), self.highestMismatch, '%');
5455
});
@@ -61,7 +62,7 @@ var IonicSnapshot = function(options) {
6162

6263
if(!self.testData.total_specs) {
6364
self.testData.total_specs = 0;
64-
var allSpecs = jasmine.getEnv().currentRunner().specs()
65+
var allSpecs = jasmine.getEnv().currentRunner().specs();
6566
for(var sId in allSpecs) {
6667
self.testData.total_specs++;
6768
}
@@ -75,30 +76,34 @@ var IonicSnapshot = function(options) {
7576
browser.sleep(self.sleepBetweenSpecs).then(function(){
7677

7778
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());
7981

8082
self.testData.spec_id = spec.id;
8183
self.testData.description = spec.getFullName();
8284
self.testData.highest_mismatch = self.highestMismatch;
8385
self.testData.png_base64 = pngBase64;
8486
pngBase64 = null;
8587

88+
var requestDeferred = q.defer();
89+
self.screenshotRequestPromises.push(requestDeferred.promise);
90+
8691
request.post(
8792
'http://' + self.domain + '/screenshot',
8893
{ form: self.testData },
8994
function (error, response, body) {
90-
log('reportSpecResults:', body);
95+
log(specIdString, 'reportSpecResults:', body);
9196
try {
9297
var rspData = JSON.parse(body);
9398
self.highestMismatch = Math.max(self.highestMismatch, rspData.Mismatch);
9499
} catch(e) {
95-
log(colors.red('reportSpecResults error posting screenshot:'), e);
100+
log(specIdString, colors.red('reportSpecResults', 'error posting screenshot:'), e);
96101
}
97-
d.fulfill();
102+
requestDeferred.resolve();
98103
}
99104
);
105+
d.fulfill();
100106
});
101-
102107
});
103108

104109
});
@@ -107,6 +112,22 @@ var IonicSnapshot = function(options) {
107112
});
108113
};
109114

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+
110131
this.jasmine.getEnv().addReporter( new IonicReporter(options) );
111132

112133
};

config/protractor.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ exports.config = {
1010
jasmineNodeOpts: {
1111
showColors: true, // Use colors in the command line report.
1212
defaultTimeoutInterval: 120000,
13-
isVerbose: true
13+
// isVerbose: true
1414
},
1515

1616
baseUrl: 'http://localhost:' + buildConfig.protractorPort,

0 commit comments

Comments
 (0)