diff --git a/lib/tools/phantomas/phantomasWrapper.js b/lib/tools/phantomas/phantomasWrapper.js index 65d53d7..b83ca33 100644 --- a/lib/tools/phantomas/phantomasWrapper.js +++ b/lib/tools/phantomas/phantomasWrapper.js @@ -115,6 +115,7 @@ var PhantomasWrapper = function() { async.retry(triesNumber, function(cb) { var process = phantomas(task.url, options, function(err, json, results) { + var errorCode = err ? parseInt(err.message, 10) : null; if (isKilled) { debug('Process was killed, too late Phantomas, sorry...'); @@ -122,28 +123,28 @@ var PhantomasWrapper = function() { } - debug('Returning from Phantomas with error %s', err); + debug('Returning from Phantomas with error %s', errorCode); // Adding some YellowLabTools errors here if (json && json.metrics && (!json.metrics.javascriptExecutionTree || !json.offenders.javascriptExecutionTree)) { - err = 1001; + errorCode = 1001; } - if (!err && (!json || !json.metrics)) { - err = 1002; + if (!errorCode && (!json || !json.metrics)) { + errorCode = 1002; } // Don't cancel test if it is a timeout and we've got some results - if (err === 252 && json) { + if (errorCode === 252 && json) { debug('Timeout after ' + options.timeout + ' seconds. But it\'s not a problem, the test is valid.'); - err = null; + errorCode = null; } - if (err) { - debug('Attempt failed. Error code ' + err); + if (errorCode) { + debug('Attempt failed. Error code ' + errorCode); } - cb(err, json); + cb(errorCode, json); }); phantomasPid = process.pid; diff --git a/test/core/phantomasWrapperTest.js b/test/core/phantomasWrapperTest.js index ef5cef8..b6d6372 100644 --- a/test/core/phantomasWrapperTest.js +++ b/test/core/phantomasWrapperTest.js @@ -51,11 +51,14 @@ describe('phantomasWrapper', function() { done('Error: unwanted success'); }).fail(function(err) { + try { + should.exist(err); + err.should.equal(254); - should.exist(err); - err.should.equal(254); - - done(); + done(); + } catch(error) { + done(error); + } }); }); @@ -72,16 +75,20 @@ describe('phantomasWrapper', function() { } }).then(function(data) { /*jshint -W030 */ - - data.should.be.an('object'); - data.should.have.a.property('generator'); - data.generator.should.contain('phantomas'); - data.should.have.a.property('url').that.equals(url); - data.should.have.a.property('metrics').that.is.an('object').not.empty; - data.should.have.a.property('offenders').that.is.an('object').not.empty; - data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty; - done(); + try { + data.should.be.an('object'); + data.should.have.a.property('generator'); + data.generator.should.contain('phantomas'); + data.should.have.a.property('url').that.equals(url); + data.should.have.a.property('metrics').that.is.an('object').not.empty; + data.should.have.a.property('offenders').that.is.an('object').not.empty; + data.offenders.should.have.a.property('javascriptExecutionTree').that.is.a('array').not.empty; + + done(); + } catch(error) { + done(error); + } }).fail(function(err) { done(err); });