Permalink
Browse files

jshint fixes

  • Loading branch information...
1 parent 57f0b50 commit 87baa84a72a22617f21f7a75b4be73a406dc0918 @christian-bromann christian-bromann committed May 10, 2015
View
@@ -14,5 +14,17 @@
"eqnull": true,
"node": true,
"quotmark": "single",
- "indent": 4
-}
+ "indent": 4,
+ "globals": {
+ "describe": true,
+ "it": true,
+ "before": true,
+ "beforeEach": true,
+ "after": true,
+ "afterEach": true,
+ "document": true,
+ "window": true,
+ "navigator": true,
+ "expect": true
+ }
+}
@@ -7,7 +7,7 @@
var workflow = require('./workflow.js'),
endSession = require('./endSession.js');
-module.exports = function(err,res) {
+module.exports = function(err) {
var that = this;
@@ -28,7 +28,7 @@ var async = require('async'),
fs = require('fs'),
gm = require('gm'),
rimraf = require('rimraf'),
- generateUUID = require("./generateUUID.js"),
+ generateUUID = require('./generateUUID.js'),
path = require('path');
module.exports = function documentScreenshot(fileName) {
@@ -88,7 +88,7 @@ module.exports = function documentScreenshot(fileName) {
tmpDir = path.join(__dirname, '..', '.tmp-' + uuid);
fs.exists(tmpDir, function(exists) {
- return exists ? cb() : fs.mkdir(tmpDir, 0755, cb);
+ return exists ? cb() : fs.mkdir(tmpDir, 755, cb);
});
},
@@ -101,7 +101,7 @@ module.exports = function documentScreenshot(fileName) {
/**
* remove scrollbars
*/
- document.body.style.overflow = "hidden";
+ document.body.style.overflow = 'hidden';
/**
* scroll back to start scanning
@@ -134,7 +134,7 @@ module.exports = function documentScreenshot(fileName) {
/*!
* while expression
*/
- function(callback) {
+ function() {
return (currentXPos < (response.execute[0].value.documentWidth / response.execute[0].value.screenWidth));
},
@@ -239,7 +239,7 @@ module.exports = function documentScreenshot(fileName) {
function(res, cb) {
response.execute.push(res);
self.execute(function() {
- document.body.style.overflow = "visible";
+ document.body.style.overflow = 'visible';
}, cb);
}
], function(err) {
View
@@ -25,16 +25,16 @@ module.exports = function(done) {
/**
* end session when using applitools
*/
- function(cb) {
+ function() {
var cb = arguments[arguments.length - 1];
if(!that.self.usesApplitools) {
return cb();
}
// Whether or not we should automatically save this test as baseline.
- var updateBaseline = (that.self.isNew && that.applitools.saveNewTests)
- || (!that.self.isNew && that.applitools.saveFailedTests);
+ var updateBaseline = (that.self.isNew && that.applitools.saveNewTests) ||
+ (!that.self.isNew && that.applitools.saveFailedTests);
return request({
qs: {apiKey: that.applitools.apiKey, updateBaseline: updateBaseline},
@@ -62,7 +62,7 @@ module.exports = function(done) {
return cb();
}
- ], function(err, res, body) {
+ ], function(err) {
return done(err);
});
};
View
@@ -9,6 +9,6 @@ module.exports = function (){
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = (d + Math.random()*16)%16 | 0;
d = Math.floor(d/16);
- return (c=='x' ? r : (r&0x7|0x8)).toString(16);
+ return (c === 'x' ? r : (r&0x7|0x8)).toString(16);
});
};
View
@@ -22,8 +22,7 @@ module.exports = function(done) {
response = {
excludeRect: [],
scrollPos: {x: 0, y:0},
- };
-
+ },
excludeRect = [],
element = that.currentArgs.elem || 'body';
@@ -41,7 +40,7 @@ module.exports = function(done) {
var x = 0,
y = 0;
- if (typeof(window.pageYOffset) == 'number') {
+ if (typeof window.pageYOffset === 'number') {
/* Netscape compliant */
y = window.pageYOffset;
@@ -3,16 +3,13 @@
/**
* make screenshot via [GET] /session/:sessionId/screenshot
*/
-var fs = require('fs'),
- takenShots = {};
-
var modifyElements = function(elements, style, value) {
if(elements.length === 0) {
return;
}
this.instance.selectorExecute(elements, function() {
- var args = Array.prototype.slice.call(arguments).filter(function(n){ return n != undefined }),
+ var args = Array.prototype.slice.call(arguments).filter(function(n){ return n !== undefined }),
style = args[args.length - 2],
value = args[args.length - 1];
View
@@ -7,14 +7,6 @@
var async = require('async'),
takenScreenSizes = {};
-function renameFiles() {
- this.baselinePath = this.baselinePath.replace(/\.(baseline|regression|diff)\.png/,'.' + this.newScreenSize.width + 'px.$1.png');
- this.regressionPath = this.regressionPath.replace(/\.(baseline|regression|diff)\.png/,'.' + this.newScreenSize.width + 'px.$1.png');
- this.diffPath = this.diffPath.replace(/\.(baseline|regression|diff)\.png/, '.' + this.newScreenSize.width + 'px.$1.png');
- this.screenshot = this.screenshot.replace(/\.png/, '.' + this.newScreenSize.width + 'px.png');
- this.filename = this.baselinePath;
-}
-
module.exports = function(done) {
var that = this;
@@ -75,7 +67,11 @@ module.exports = function(done) {
* if shot will be taken in a specific screenWidth, rename file and append screen width
* value in filename
*/
- renameFiles.call(that);
+ this.baselinePath = this.baselinePath.replace(/\.(baseline|regression|diff)\.png/,'.' + this.newScreenSize.width + 'px.$1.png');
+ this.regressionPath = this.regressionPath.replace(/\.(baseline|regression|diff)\.png/,'.' + this.newScreenSize.width + 'px.$1.png');
+ this.diffPath = this.diffPath.replace(/\.(baseline|regression|diff)\.png/, '.' + this.newScreenSize.width + 'px.$1.png');
+ this.screenshot = this.screenshot.replace(/\.png/, '.' + this.newScreenSize.width + 'px.png');
+ this.filename = this.baselinePath;
that.instance.setViewportSize({width: that.newScreenSize.width, height: that.newScreenSize.height})
.pause(100)
View
@@ -2,7 +2,8 @@
var pkg = require('../package.json'),
request = require('request'),
- async = require('async');
+ async = require('async'),
+ WebdriverIO = require('webdriverio');
module.exports = function() {
@@ -27,16 +28,16 @@ module.exports = function() {
useragent: navigator.userAgent,
screenWidth: Math.max(document.documentElement.clientWidth, window.innerWidth || 0),
documentHeight: document.documentElement.scrollHeight
- }
+ };
}, function(err, res) {
that.useragent = res.value.useragent;
that.displaySize = {
width: that.screenWidth && that.screenWidth.length ? that.screenWidth[0] : res.value.screenWidth,
height: res.value.documentHeight
- }
+ };
return cb();
- })
+ });
},
/**
@@ -72,13 +73,13 @@ module.exports = function() {
], function(err, res, body) {
if (err || res.statusCode !== 200 && res.statusCode !== 201) {
- return done(new webdriverio.ErrorHandler.CommandError('Couldn\'t start applitools session'));
+ return done(new WebdriverIO.ErrorHandler.CommandError('Couldn\'t start applitools session'));
}
that.self.sessionId = body.id;
that.self.url = body.url;
that.self.isNew = res.statusCode === 201;
return done();
- })
+ });
};
View
@@ -0,0 +1,122 @@
+'use strict';
+
+var fs = require('fs-extra'),
+ tar = require('tar'),
+ zlib = require('zlib'),
+ targz = require('tar.gz'),
+ rimraf = require('rimraf'),
+ request = require('request');
+
+/**
+ * sync down
+ * downloads tarball from API and unzip it
+ *
+ * @param {Function} done callback to be called after sync finishes
+ */
+var syncDown = function(done) {
+
+ var args = {
+ url: this.api + (this.api.substr(-1) !== '/' ? '/' : '') + this.screenshotRoot + '.tar.gz',
+ headers: { 'accept-encoding': 'gzip,deflate' },
+ };
+
+ if(typeof this.user === 'string' && typeof this.key === 'string') {
+ args.auth = {
+ user: this.user,
+ pass: this.key
+ };
+ }
+
+ var r = request.get(args),
+ self = this;
+
+ r.on('error', done);
+ r.on('response', function(resp) {
+
+ /*!
+ * no error if repository doesn't exists
+ */
+ /*istanbul ignore if*/
+ if(resp.statusCode === 404) {
+ return done();
+ }
+
+ /*istanbul ignore next*/
+ if(resp.statusCode !== 200 || resp.headers['content-type'] !== 'application/octet-stream') {
+ return done(new Error('unexpected statusCode (' + resp.statusCode + ' != 200) or content-type (' + resp.headers['content-type'] + ' != application/octet-stream)'));
+ }
+
+ /**
+ * check if repository directory already exists and
+ * clear it if yes
+ */
+ if(fs.existsSync(self.screenshotRoot)) {
+ rimraf.sync(self.screenshotRoot);
+ fs.mkdirsSync(self.screenshotRoot, 755, true);
+ }
+
+ resp.pipe(zlib.Gunzip()).pipe(tar.Extract({ path: '.' })).on('end', done);
+
+ });
+};
+
+/**
+ * sync up
+ * zips image repository and uploads it to API
+ *
+ * @param {Function} done callback to be called after tarball was uploaded
+ */
+var syncUp = function(done) {
+ var screenshotRoot = this.screenshotRoot,
+ args = { url: this.api };
+
+ if(typeof this.user === 'string' && typeof this.key === 'string') {
+ args.auth = {
+ user: this.user,
+ pass: this.key
+ };
+ }
+
+ new targz().compress(screenshotRoot, screenshotRoot + '.tar.gz', function(err){
+
+ /*istanbul ignore if*/
+ if(err) {
+ return done(new Error(err));
+ }
+
+ var r = request.post(args, done);
+
+ var form = r.form();
+ form.append('gz', fs.createReadStream(screenshotRoot + '.tar.gz'));
+
+ });
+};
+
+/**
+ * sync command
+ * decides according to `needToSync` flag when to sync down and when to sync up
+ *
+ * @param {Function} done callback to be called after syncing
+ * @return {Object} WebdriverCSS instance
+ */
+module.exports = function(done) {
+
+ if(!this.api) {
+ return done(new Error('No sync options specified! Please provide an api path and user/key (optional).'));
+ }
+
+ var sync = this.needToSync ? syncUp : syncDown;
+ this.needToSync = false;
+
+ sync.call(this, function(err, httpResponse, body) {
+
+ /*istanbul ignore next*/
+ if(err || (httpResponse && httpResponse.statusCode !== 200)) {
+ return done(new Error(err || body));
+ }
+
+ done();
+
+ });
+ return this;
+};
@@ -7,9 +7,7 @@
*/
var async = require('async'),
- fs = require('fs'),
- gm = require('gm'),
- rimraf = require('rimraf');
+ gm = require('gm');
module.exports = function viewportScreenshot(fileName) {
@@ -35,32 +33,32 @@ module.exports = function viewportScreenshot(fileName) {
var getScrollingPosition = function() {
var position = [0, 0];
- if (typeof window.pageYOffset != 'undefined') {
+ if (typeof window.pageYOffset !== 'undefined') {
position = [
window.pageXOffset,
window.pageYOffset
];
- } else if (typeof document.documentElement.scrollTop != 'undefined' && document.documentElement.scrollTop > 0) {
+ } else if (typeof document.documentElement.scrollTop !== 'undefined' && document.documentElement.scrollTop > 0) {
position = [
document.documentElement.scrollLeft,
document.documentElement.scrollTop
];
- } else if (typeof document.body.scrollTop != 'undefined') {
+ } else if (typeof document.body.scrollTop !== 'undefined') {
position = [
document.body.scrollLeft,
document.body.scrollTop
];
}
return position;
- }
+ };
async.waterfall([
/*!
* get scroll position
*/
function(cb) {
- self.execute(getScrollingPosition, null, cb)
+ self.execute(getScrollingPosition, null, cb);
},
/*!
Oops, something went wrong.

0 comments on commit 87baa84

Please sign in to comment.