Skip to content

Commit

Permalink
chore(ionic-snapshot): make it so screenshots are posting asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Jun 4, 2014
1 parent 6697e66 commit 538737a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions config/lib/ionic-snapshot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var q = require('q');

var IonicSnapshot = function(options) {

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

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

Expand All @@ -48,7 +50,6 @@ var IonicSnapshot = function(options) {
};
});
});

process.on('exit', function() {
log(colors.green('Highest Mismatch:'), self.highestMismatch, '%');
});
Expand All @@ -61,7 +62,7 @@ var IonicSnapshot = function(options) {

if(!self.testData.total_specs) {
self.testData.total_specs = 0;
var allSpecs = jasmine.getEnv().currentRunner().specs()
var allSpecs = jasmine.getEnv().currentRunner().specs();
for(var sId in allSpecs) {
self.testData.total_specs++;
}
Expand All @@ -75,30 +76,34 @@ var IonicSnapshot = function(options) {
browser.sleep(self.sleepBetweenSpecs).then(function(){

browser.takeScreenshot().then(function(pngBase64){
log('spec:', spec.id + 1, 'of', self.testData.total_specs);
var specIdString = '[' + (spec.id+1) + '/' + self.testData.total_specs + ']';
log(specIdString, spec.getFullName());

self.testData.spec_id = spec.id;
self.testData.description = spec.getFullName();
self.testData.highest_mismatch = self.highestMismatch;
self.testData.png_base64 = pngBase64;
pngBase64 = null;

var requestDeferred = q.defer();
self.screenshotRequestPromises.push(requestDeferred.promise);

request.post(
'http://' + self.domain + '/screenshot',
{ form: self.testData },
function (error, response, body) {
log('reportSpecResults:', body);
log(specIdString, 'reportSpecResults:', body);
try {
var rspData = JSON.parse(body);
self.highestMismatch = Math.max(self.highestMismatch, rspData.Mismatch);
} catch(e) {
log(colors.red('reportSpecResults error posting screenshot:'), e);
log(specIdString, colors.red('reportSpecResults', 'error posting screenshot:'), e);
}
d.fulfill();
requestDeferred.resolve();
}
);
d.fulfill();
});

});

});
Expand All @@ -107,6 +112,22 @@ var IonicSnapshot = function(options) {
});
};

IonicReporter.prototype.reportRunnerResults = function() {
var self = this;

self.flow.execute(function() {
var d = protractor.promise.defer();
log('Waiting for all screenshots to be posted...');
// allSettled waits until all the promises are done, whether they are rejected or resolved
q.allSettled(self.screenshotRequestPromises).then(function(all) {
d.fulfill();
log('Finished!');
});
});
};



this.jasmine.getEnv().addReporter( new IonicReporter(options) );

};
Expand Down
2 changes: 1 addition & 1 deletion config/protractor.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.config = {
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
defaultTimeoutInterval: 120000,
isVerbose: true
// isVerbose: true
},

baseUrl: 'http://localhost:' + buildConfig.protractorPort,
Expand Down

0 comments on commit 538737a

Please sign in to comment.