diff --git a/lib/rediff.js b/lib/rediff.js index 7a742c3..3677536 100644 --- a/lib/rediff.js +++ b/lib/rediff.js @@ -48,7 +48,7 @@ const generateJobQueue = () => { const screenshots = { diff: config.resultsDir + specName + '-' + viewport + '-diff.png' }; let workerJobs = []; - Object.keys(config.environments).forEach(function(env) { + Object.keys(config.environments).forEach(env => { const outputFile = config.resultsDir + specName + '-' + viewport + '-' + env + '.png'; workerJobs.push({ viewport: { @@ -116,7 +116,7 @@ const diffPixel = (pixel1, pixel2, match) => { const diffImages = (test, input1, input2, output) => { if (fs.existsSync(input1) && fs.existsSync(input2)) { - return diff.outputDiff(input1, input2, output, diffPixel).then(function(data) { + return diff.outputDiff(input1, input2, output, diffPixel).then(data => { test.diff = data.metric; return data.output; }); @@ -125,8 +125,8 @@ const diffImages = (test, input1, input2, output) => { }; const convertImages = pngs => { - return Promise.map(pngs, function(fileToConvert) { - return new Promise(function(resolve) { + return Promise.map(pngs, fileToConvert => { + return new Promise(resolve => { if (fs.existsSync(fileToConvert)) { convert( { @@ -134,9 +134,7 @@ const convertImages = pngs => { output: fileToConvert.replace(/\.png$/, '.jpg'), quality: 80, }, - function() { - resolve(fileToConvert); - } + () => resolve(fileToConvert) ); } else { resolve(fileToConvert); @@ -160,7 +158,7 @@ const gzipFiles = files => { }; const removeFiles = files => { - return Promise.map(files, function(fileToRemove) { + return Promise.map(files, fileToRemove => { if (fs.existsSync(fileToRemove)) { fs.unlinkSync(fileToRemove); } @@ -168,50 +166,25 @@ const removeFiles = files => { }; const processJob = (jobs, test, specName) => { - const images = envNames.concat(['diff']).map(function(env) { - return test.screenshots[env]; - }); + const images = envNames.concat(['diff']).map(env => test.screenshots[env]); - const loImages = images.map(function(image) { - return image.replace(/\.png$/, '.jpg'); - }); + const loImages = images.map(image => image.replace(/\.png$/, '.jpg')); - const workerPromises = jobs.map(function(job) { - return worker.addSpec(job, handleError.bind(null, job, 'TestRunner')); - }); + const workerPromises = jobs.map(job => worker.addSpec(job, handleError.bind(null, job, 'TestRunner'))); return Promise.all(workerPromises) - .catch(function(err) { - handleError(test, 'Crawler', err); - }) - .then(function() { - return diffImages(test, images[0], images[1], images[2]); - }) - .catch(function(err) { - handleError(test, 'Comparison', err); - }) - .then(function() { - return convertImages(images); - }) - .then(function() { - return removeFiles(images); - }) - .then(function() { - gzipFiles(loImages); - }) - .catch(function(err) { - handleError(test, 'General', err); - }) - .finally(function() { - reporter.push(test, specName); - }); + .catch(err => handleError(test, 'Crawler', err)) + .then(() => diffImages(test, images[0], images[1], images[2])) + .catch(err => handleError(test, 'Comparison', err)) + .then(() => convertImages(images)) + .then(() => removeFiles(images)) + .then(() => gzipFiles(loImages)) + .catch(err => handleError(test, 'General', err)) + .finally(() => reporter.push(test, specName)); }; -const processJobSet = job => { - return Promise.map(job.worker, function(jobs, idx) { - return processJob(job.worker[idx], job.tests[idx], job.spec.name); - }); -}; +const processJobSet = job => + Promise.map(job.worker, (jobs, idx) => processJob(job.worker[idx], job.tests[idx], job.spec.name)); const run = (cfg, specList) => { config = cfg; @@ -222,14 +195,11 @@ const run = (cfg, specList) => { reporter.initialize( config, - queue.map(function(item) { - return item.spec; - }) + queue.map(item => item.spec) ); - Promise.map(queue, processJobSet).then(function() { - console.log('Test completed.'); - }); + Promise.map(queue, processJobSet) + .then(() => console.log('Test completed.')); }; module.exports = run; diff --git a/lib/reporter.js b/lib/reporter.js index 5c0ccb7..4894b51 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -25,8 +25,8 @@ const report = () => { const initialize = (cfg, specsData) => { config = cfg; - specs = specsData.map(function(spec) { - return _.merge( + specs = specsData.map(spec => + _.merge( { // name, url tests: { @@ -36,8 +36,8 @@ const initialize = (cfg, specsData) => { }, }, spec - ); - }); + ) + ); metadata = { tests: { @@ -61,7 +61,7 @@ const push = (result, specName) => { metadata.tests.failing++; } - _.keys(result.screenshots).forEach(function(screenshot) { + _.keys(result.screenshots).forEach(screenshot => { result.screenshots[screenshot] = result.screenshots[screenshot] .replace(config.resultsDir, '') .replace(/\.png$/, '.jpg'); diff --git a/lib/util.js b/lib/util.js index fdb62cd..f5b574e 100644 --- a/lib/util.js +++ b/lib/util.js @@ -5,7 +5,7 @@ const getSpecViewports = (viewports, filter) => { return viewports; } let result = {}; - filter.forEach(function(name) { + filter.forEach(name => { if (!viewports[name]) { console.warn( 'WARNING: You are trying to use viewport "' + diff --git a/lib/worker.js b/lib/worker.js index d867110..be5d34b 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -13,12 +13,10 @@ function Worker(config) { Worker.prototype = { addSpec: function(spec, errorHandler) { - return new Promise( - function(resolve, reject) { - this.queue.push([spec, errorHandler, resolve, reject]); - this.handleQueue(); - }.bind(this) - ); + return new Promise((resolve, reject) => { + this.queue.push([spec, errorHandler, resolve, reject]); + this.handleQueue(); + }); }, handleQueue: function() { @@ -44,7 +42,7 @@ Worker.prototype = { body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' }, }) - .then(function(response) { + .then(response => { if (!response.ok || response.status < 200 || response.status >= 400) { throw new Error(`External service error at ${response.url}/v1/screenshot/${body.url}`, { status: response.status, @@ -66,11 +64,7 @@ Worker.prototype = { .catch(error => { reject({ spec: spec, error: error }); }) - .then( - function() { - this.handleQueue(); - }.bind(this) - ); + .then(() => this.handleQueue()); }, }; diff --git a/package.json b/package.json index 6d3b071..f334713 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rediff", - "version": "1.0.0", + "version": "1.0.1", "description": "Perceptual difference testing tool based on Pediff", "author": "Lukasz Blacha ", "contributors": [