From f597d96823b15059b8bcbb1e0baf314a655b13a9 Mon Sep 17 00:00:00 2001 From: Andrey Kuzmin Date: Thu, 15 Oct 2015 22:17:54 +0200 Subject: [PATCH] compare binary data of screenshots --- .travis.yml | 4 +--- package.json | 2 -- test.js | 45 +++++---------------------------------------- 3 files changed, 6 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2aff8c..04be19b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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= diff --git a/package.json b/package.json index 86bc342..0c60390 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/test.js b/test.js index a950a36..8098326 100644 --- a/test.js +++ b/test.js @@ -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') @@ -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 () { @@ -82,7 +55,7 @@ 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() @@ -90,21 +63,13 @@ describe('gulp-svgstore usage test', function () { 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') }) })