Skip to content

Commit

Permalink
Merge pull request #54 from w0rm/53-pixelmatch
Browse files Browse the repository at this point in the history
compare binary data of screenshots
  • Loading branch information
w0rm committed Oct 17, 2015
2 parents dddf6f5 + f597d96 commit 48de00a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 45 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ node_js:
- '0.12'
- iojs
- '4.0.0'
sudo: true
before_install:
- sudo apt-get install graphicsmagick
sudo: false
env:
global:
- secure: LK3KvcJyMhVa4yAGSCrZ7cb2oGmlGDRFn/yEmkxZ7eu8gW32mp9IBcyuHboSxNnSlZT088cFp8H7ly1kfXs1anZzrRD9GBeNiyVBS8pgidMsKM7JvHDG54HygwHag4xdzZHyxUSEhBFP50VCDrpS3EE1KI6/AMRyVjv0kH5CWHI=
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@
},
"devDependencies": {
"finalhandler": "^0.4.0",
"gm": "^1.18.1",
"gulp": "^3.6.2",
"gulp-inject": "^1.0.1",
"mocha": "^2.3.2",
"serve-static": "^1.9.3",
"sinon": "^1.16.1",
"tmp": "0.0.26",
"wd": "^0.3.4"
},
"keywords": [
Expand Down
45 changes: 5 additions & 40 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ var port = process.env.PORT || 8888
var wd = require('wd')
var assert = require('assert')
var Q = wd.Q
var fs = require('fs')
var gm = require('gm')
var tmp = require('tmp')
var svgstore = require('./index')
var gutil = require('gulp-util')
var cheerio = require('cheerio')
Expand All @@ -18,30 +15,6 @@ var finalhandler = require('finalhandler')
var serveStatic = require('serve-static')
var http = require('http')
var sandbox = sinon.sandbox.create()
tmp.setGracefulCleanup()


function writeScreenshot (data) {
return Q.Promise(function (resolve, reject) {
tmp.tmpName(function (err, path) {
if (err) reject(new Error(err))
fs.writeFile(path, data, 'base64', function (err) {
if (err) reject(new Error(err))
resolve(path)
})
})
})
}


function compareScreenshots (path1, path2) {
return Q.Promise(function (resolve, reject) {
gm.compare(path1, path2, function (err, isEqual, equality) {
if (err) reject(new Error(err))
resolve(isEqual && equality === 0)
})
})
}


describe('gulp-svgstore usage test', function () {
Expand Down Expand Up @@ -82,29 +55,21 @@ describe('gulp-svgstore usage test', function () {
})

it('stored image should equal original svg', function () {
var screenshot1, screenshot2
var screenshot1
return browser
.get('http://localhost:' + port + '/inline-svg.html')
.title()
.then(function (title) {
assert.equal(title, 'gulp-svgstore', 'Test page is not loaded')
})
.takeScreenshot()
.then(writeScreenshot)
.then(function (path) {
screenshot1 = path
.then(function (data) {
screenshot1 = data
})
.get('http://localhost:' + port + '/dest/inline-svg.html')
.takeScreenshot()
.then(writeScreenshot)
.then(function (path) {
screenshot2 = path
})
.then(function () {
return compareScreenshots(screenshot1, screenshot2)
})
.then(function (isEqual) { // jshint ignore:line
assert.ok(isEqual, 'Screenshots are different')
.then(function (screenshot2) {
assert(screenshot1.toString() === screenshot2.toString(), 'Screenshots are different')
})
})

Expand Down

0 comments on commit 48de00a

Please sign in to comment.