From 5448f9f1d00ec836d37c81b0531d7b1ee7af1a48 Mon Sep 17 00:00:00 2001 From: Eric Zeng Date: Mon, 29 Sep 2014 13:18:23 +0800 Subject: [PATCH] lei: bug fix for phantomjs error --- src/canvas.drawimage.coffee | 6 +++++- src/comparison.coffee | 2 +- src/viff.coffee | 25 ++++++++++++++----------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/canvas.drawimage.coffee b/src/canvas.drawimage.coffee index 7e0522a..67c0351 100644 --- a/src/canvas.drawimage.coffee +++ b/src/canvas.drawimage.coffee @@ -38,6 +38,11 @@ class CanvasDrawImage else if data.done @running = false cb resultDataUrl + else if data.error + @running = false + cb '' + @cachedPage.set 'onError', (err) => + cb '' @cachedPage.evaluate (dataUrl, loc, sz) -> image = new Image() @@ -62,7 +67,6 @@ class CanvasDrawImage , nope, imageDataUrl, location, size - exit: () -> @cachedPh.exit() @cachedPh = @cachedPage = null diff --git a/src/comparison.coffee b/src/comparison.coffee index cb361bb..5fbbe03 100644 --- a/src/comparison.coffee +++ b/src/comparison.coffee @@ -35,7 +35,7 @@ class Comparison @compare: (fileAData, fileBData, callback) -> defer = Q.defer() promise = defer.promise.then callback - + if !fileAData && !fileBData then defer.resolve {} r = resemble.get() r.running = true r.compare dataUrlHelper.toDataURL(fileAData), dataUrlHelper.toDataURL(fileBData), (data) -> diff --git a/src/viff.coffee b/src/viff.coffee index 8ee3fa7..d4e5647 100644 --- a/src/viff.coffee +++ b/src/viff.coffee @@ -88,14 +88,17 @@ class Viff extends EventEmitter compareTo = that.takeScreenshot _case.to.capability, _case.to.host, _case.url Q.allSettled([compareTo]).then ([ts]) -> - if fs.reason or ts.reason that.emit 'afterEach', _case, 0, fs.reason, ts.reason next() - else + else if fs.value and ts.value Viff.runCase(_case, fs.value, ts.value).then (c) -> that.emit 'afterEach', _case, Date.now() - startcase, fs.reason, ts.reason next() + else + that.emit 'afterEach', _case, 0, fs.reason, ts.reason + next() + , (err) -> endTime = Date.now() - start @@ -123,15 +126,15 @@ class Viff extends EventEmitter @dealWithPartial: (base64Img, driver, selector, callback) -> driver.elementByCss(selector) - .then((elem) -> - Q.all([elem.getLocation(), elem.getSize()]).then ([location, size]) -> - defer = Q.defer() - cvs = partialCanvas.get() - cvs.drawImage dataUrlHelper.toDataURL(base64Img), location, size, (data) -> + .then (elem) -> + Q.all([elem.getLocation(), elem.getSize()]).then ([location, size]) -> + defer = Q.defer() + cvs = partialCanvas.get() + cvs.drawImage dataUrlHelper.toDataURL(base64Img), location, size, (data) -> + if data defer.resolve new Buffer(dataUrlHelper.toData(data), 'base64') - - defer.promise - ) - .then callback + else defer.resolve '' + defer.promise + .then callback module.exports = Viff