Skip to content

Commit

Permalink
Merge pull request #39 from LeiZeng/bugfix-phantom
Browse files Browse the repository at this point in the history
lei: bug fix for phantomjs error
  • Loading branch information
winsonwq committed Oct 31, 2014
2 parents 29a7496 + 5448f9f commit 7f8a10b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/canvas.drawimage.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -62,7 +67,6 @@ class CanvasDrawImage

, nope, imageDataUrl, location, size


exit: () ->
@cachedPh.exit()
@cachedPh = @cachedPage = null
Expand Down
2 changes: 1 addition & 1 deletion src/comparison.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
25 changes: 14 additions & 11 deletions src/viff.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 7f8a10b

Please sign in to comment.