From cbdbbe535afd8608125029825f32829e17acab4b Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Wed, 26 Oct 2016 11:52:45 +0100 Subject: [PATCH] Update tests to meet semistandard code standards Switch to const/let instead of var --- circle.yml | 2 + package.json | 3 - test/bench/parallel.js | 30 +- test/bench/perf.js | 273 +++++++++-------- test/bench/random.js | 34 +-- test/saliency/humanae/download.js | 6 +- test/saliency/humanae/tone.js | 7 +- test/saliency/report.js | 25 +- test/saliency/userData.js | 14 +- test/unit/alpha.js | 56 ++-- test/unit/bandbool.js | 30 +- test/unit/blur.js | 42 +-- test/unit/boolean.js | 42 ++- test/unit/cache.js | 6 +- test/unit/clone.js | 38 ++- test/unit/colourspace.js | 39 ++- test/unit/convolve.js | 37 ++- test/unit/cpplint.js | 25 +- test/unit/crop.js | 57 ++-- test/unit/embed.js | 38 ++- test/unit/extend.js | 35 ++- test/unit/extract.js | 89 +++--- test/unit/extractChannel.js | 46 ++- test/unit/fixtures.js | 22 +- test/unit/gamma.js | 34 ++- test/unit/interpolation.js | 34 +-- test/unit/io.js | 484 +++++++++++++++--------------- test/unit/metadata.js | 131 ++++---- test/unit/negate.js | 191 ++++++------ test/unit/normalize.js | 40 ++- test/unit/overlay.js | 249 ++++++++------- test/unit/require.js | 12 +- test/unit/resize.js | 268 ++++++++--------- test/unit/rotate.js | 95 +++--- test/unit/sharpen.js | 48 ++- test/unit/threshold.js | 91 +++--- test/unit/trim.js | 27 +- test/unit/util.js | 83 +++-- 38 files changed, 1378 insertions(+), 1405 deletions(-) diff --git a/circle.yml b/circle.yml index 9b10fadd..84d386e4 100644 --- a/circle.yml +++ b/circle.yml @@ -1,4 +1,6 @@ machine: + node: + version: v4.6.1 services: - docker test: diff --git a/package.json b/package.json index 8af294af..eaece710 100755 --- a/package.json +++ b/package.json @@ -87,9 +87,6 @@ "semistandard": { "env": [ "mocha" - ], - "ignore": [ - "test" ] } } diff --git a/test/bench/parallel.js b/test/bench/parallel.js index 549783ce..403b8578 100644 --- a/test/bench/parallel.js +++ b/test/bench/parallel.js @@ -2,43 +2,43 @@ process.env.UV_THREADPOOL_SIZE = 64; -var assert = require('assert'); -var async = require('async'); +const assert = require('assert'); +const async = require('async'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -var width = 720; -var height = 480; +const width = 720; +const height = 480; sharp.concurrency(1); sharp.simd(true); -var timer = setInterval(function() { +const timer = setInterval(function () { console.dir(sharp.counters()); }, 100); -async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function(parallelism, next) { - var start = new Date().getTime(); +async.mapSeries([1, 1, 2, 4, 8, 16, 32, 64], function (parallelism, next) { + const start = new Date().getTime(); async.times(parallelism, - function(id, callback) { - /*jslint unused: false */ - sharp(fixtures.inputJpg).resize(width, height).toBuffer(function(err, buffer) { + function (id, callback) { + /* jslint unused: false */ + sharp(fixtures.inputJpg).resize(width, height).toBuffer(function (err, buffer) { buffer = null; callback(err, new Date().getTime() - start); }); }, - function(err, ids) { + function (err, ids) { assert(!err); assert(ids.length === parallelism); - var mean = ids.reduce(function(a, b) { + const mean = ids.reduce(function (a, b) { return a + b; }) / ids.length; console.log(parallelism + ' parallel calls: fastest=' + ids[0] + 'ms slowest=' + ids[ids.length - 1] + 'ms mean=' + mean + 'ms'); next(); } ); -}, function() { +}, function () { clearInterval(timer); console.dir(sharp.counters()); }); diff --git a/test/bench/perf.js b/test/bench/perf.js index cd5ca8cb..c9392ba2 100644 --- a/test/bench/perf.js +++ b/test/bench/perf.js @@ -1,34 +1,33 @@ 'use strict'; -var fs = require('fs'); +const fs = require('fs'); -var async = require('async'); -var assert = require('assert'); -var Benchmark = require('benchmark'); -var semver = require('semver'); +const async = require('async'); +const assert = require('assert'); +const Benchmark = require('benchmark'); // Contenders -var gm = require('gm'); -var imagemagick = require('imagemagick'); -var jimp = require('jimp'); -var sharp = require('../../'); -var imagemagickNative; +const gm = require('gm'); +const imagemagick = require('imagemagick'); +const jimp = require('jimp'); +const sharp = require('../../'); +let imagemagickNative; try { imagemagickNative = require('imagemagick-native'); } catch (err) { console.log('Excluding imagemagick-native'); } -var lwip; +let lwip; try { lwip = require('lwip'); } catch (err) { console.log('Excluding lwip'); } -var fixtures = require('../fixtures'); +const fixtures = require('../fixtures'); -var width = 720; -var height = 480; +const width = 720; +const height = 480; // Disable libvips cache to ensure tests are as fair as they can be sharp.cache(false); @@ -36,18 +35,18 @@ sharp.cache(false); sharp.simd(true); async.series({ - 'jpeg': function(callback) { - var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); - var jpegSuite = new Benchmark.Suite('jpeg'); + 'jpeg': function (callback) { + const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); + const jpegSuite = new Benchmark.Suite('jpeg'); // jimp jpegSuite.add('jimp-buffer-buffer', { defer: true, - fn: function(deferred) { - new jimp(inputJpgBuffer, function(err) { + fn: function (deferred) { + jimp.read(inputJpgBuffer, function (err, image) { if (err) { throw err; } else { - this + image .resize(width, height) .quality(80) .getBuffer(jimp.MIME_JPEG, function (err) { @@ -62,12 +61,12 @@ async.series({ } }).add('jimp-file-file', { defer: true, - fn: function(deferred) { - new jimp(fixtures.inputJpg, function(err) { + fn: function (deferred) { + jimp.read(fixtures.inputJpg, function (err, image) { if (err) { throw err; } else { - this + image .resize(width, height) .quality(80) .write(fixtures.outputJpg, function (err) { @@ -85,7 +84,7 @@ async.series({ if (typeof lwip !== 'undefined') { jpegSuite.add('lwip-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { lwip.open(fixtures.inputJpg, function (err, image) { if (err) { throw err; @@ -105,7 +104,7 @@ async.series({ } }).add('lwip-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { lwip.open(inputJpgBuffer, 'jpg', function (err, image) { if (err) { throw err; @@ -129,7 +128,7 @@ async.series({ // imagemagick jpegSuite.add('imagemagick-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { imagemagick.resize({ srcPath: fixtures.inputJpg, dstPath: fixtures.outputJpg, @@ -138,7 +137,7 @@ async.series({ height: height, format: 'jpg', filter: 'Lanczos' - }, function(err) { + }, function (err) { if (err) { throw err; } else { @@ -151,7 +150,7 @@ async.series({ if (typeof imagemagickNative !== 'undefined') { jpegSuite.add('imagemagick-native-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { imagemagickNative.convert({ srcData: inputJpgBuffer, quality: 80, @@ -173,7 +172,7 @@ async.series({ // gm jpegSuite.add('gm-buffer-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(inputJpgBuffer) .resize(width, height) .filter('Lanczos') @@ -188,7 +187,7 @@ async.series({ } }).add('gm-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(inputJpgBuffer) .resize(width, height) .filter('Lanczos') @@ -204,7 +203,7 @@ async.series({ } }).add('gm-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(fixtures.inputJpg) .resize(width, height) .filter('Lanczos') @@ -219,7 +218,7 @@ async.series({ } }).add('gm-file-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(fixtures.inputJpg) .resize(width, height) .filter('Lanczos') @@ -237,10 +236,10 @@ async.series({ // sharp jpegSuite.add('sharp-buffer-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) - .toFile(fixtures.outputJpg, function(err) { + .toFile(fixtures.outputJpg, function (err) { if (err) { throw err; } else { @@ -250,10 +249,10 @@ async.series({ } }).add('sharp-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -264,10 +263,10 @@ async.series({ } }).add('sharp-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputJpg) .resize(width, height) - .toFile(fixtures.outputJpg, function(err) { + .toFile(fixtures.outputJpg, function (err) { if (err) { throw err; } else { @@ -277,22 +276,22 @@ async.series({ } }).add('sharp-stream-stream', { defer: true, - fn: function(deferred) { - var readable = fs.createReadStream(fixtures.inputJpg); - var writable = fs.createWriteStream(fixtures.outputJpg); - writable.on('finish', function() { + fn: function (deferred) { + const readable = fs.createReadStream(fixtures.inputJpg); + const writable = fs.createWriteStream(fixtures.outputJpg); + writable.on('finish', function () { deferred.resolve(); }); - var pipeline = sharp() + const pipeline = sharp() .resize(width, height); readable.pipe(pipeline).pipe(writable); } }).add('sharp-file-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputJpg) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -303,32 +302,32 @@ async.series({ } }).add('sharp-promise', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .toBuffer() - .then(function(buffer) { + .then(function (buffer) { assert.notStrictEqual(null, buffer); deferred.resolve(); }); } - }).on('cycle', function(event) { + }).on('cycle', function (event) { console.log('jpeg ' + String(event.target)); - }).on('complete', function() { + }).on('complete', function () { callback(null, this.filter('fastest').map('name')); }).run(); }, // Effect of applying operations - operations: function(callback) { - var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); - var operationsSuite = new Benchmark.Suite('operations'); + operations: function (callback) { + const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); + const operationsSuite = new Benchmark.Suite('operations'); operationsSuite.add('sharp-sharpen-mild', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .sharpen() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -339,11 +338,11 @@ async.series({ } }).add('sharp-sharpen-radius', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .sharpen(3, 1, 3) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -354,11 +353,11 @@ async.series({ } }).add('sharp-blur-mild', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .blur() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -369,11 +368,11 @@ async.series({ } }).add('sharp-blur-radius', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .blur(3) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -384,11 +383,11 @@ async.series({ } }).add('sharp-gamma', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .gamma() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -399,11 +398,11 @@ async.series({ } }).add('sharp-normalise', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .normalise() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -414,11 +413,11 @@ async.series({ } }).add('sharp-greyscale', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .greyscale() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -429,12 +428,12 @@ async.series({ } }).add('sharp-greyscale-gamma', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .gamma() .greyscale() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -445,11 +444,11 @@ async.series({ } }).add('sharp-progressive', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .progressive() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -460,11 +459,11 @@ async.series({ } }).add('sharp-without-chroma-subsampling', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .withoutChromaSubsampling() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -475,11 +474,11 @@ async.series({ } }).add('sharp-rotate', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .rotate(90) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -490,11 +489,11 @@ async.series({ } }).add('sharp-without-simd', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp.simd(false); sharp(inputJpgBuffer) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { sharp.simd(true); if (err) { throw err; @@ -506,11 +505,11 @@ async.series({ } }).add('sharp-sequentialRead', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .sequentialRead() .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -521,11 +520,11 @@ async.series({ } }).add('sharp-crop-entropy', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .crop(sharp.strategy.entropy) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -536,11 +535,11 @@ async.series({ } }).add('sharp-crop-attention', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height) .crop(sharp.strategy.attention) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -549,21 +548,21 @@ async.series({ } }); } - }).on('cycle', function(event) { + }).on('cycle', function (event) { console.log('operations ' + String(event.target)); - }).on('complete', function() { + }).on('complete', function () { callback(null, this.filter('fastest').map('name')); }).run(); }, // Comparitive speed of kernels - kernels: function(callback) { - var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); + kernels: function (callback) { + const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); (new Benchmark.Suite('kernels')).add('sharp-cubic', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height, { kernel: 'cubic' }) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -574,10 +573,10 @@ async.series({ } }).add('sharp-lanczos2', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height, { kernel: 'lanczos2' }) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -588,10 +587,10 @@ async.series({ } }).add('sharp-lanczos3', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputJpgBuffer) .resize(width, height, { kernel: 'lanczos3' }) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -600,25 +599,25 @@ async.series({ } }); } - }).on('cycle', function(event) { + }).on('cycle', function (event) { console.log('kernels ' + String(event.target)); - }).on('complete', function() { + }).on('complete', function () { callback(null, this.filter('fastest').map('name')); }).run(); }, // PNG - png: function(callback) { - var inputPngBuffer = fs.readFileSync(fixtures.inputPng); - var pngSuite = new Benchmark.Suite('png'); + png: function (callback) { + const inputPngBuffer = fs.readFileSync(fixtures.inputPng); + const pngSuite = new Benchmark.Suite('png'); // jimp pngSuite.add('jimp-buffer-buffer', { defer: true, - fn: function(deferred) { - new jimp(inputPngBuffer, function(err) { + fn: function (deferred) { + jimp.read(inputPngBuffer, function (err, image) { if (err) { throw err; } else { - this + image .resize(width, height) .getBuffer(jimp.MIME_PNG, function (err) { if (err) { @@ -632,12 +631,12 @@ async.series({ } }).add('jimp-file-file', { defer: true, - fn: function(deferred) { - new jimp(fixtures.inputPng, function(err) { + fn: function (deferred) { + jimp.read(fixtures.inputPng, function (err, image) { if (err) { throw err; } else { - this + image .resize(width, height) .write(fixtures.outputPng, function (err) { if (err) { @@ -654,7 +653,7 @@ async.series({ if (typeof lwip !== 'undefined') { pngSuite.add('lwip-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { lwip.open(inputPngBuffer, 'png', function (err, image) { if (err) { throw err; @@ -678,14 +677,14 @@ async.series({ // imagemagick pngSuite.add('imagemagick-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { imagemagick.resize({ srcPath: fixtures.inputPng, dstPath: fixtures.outputPng, width: width, height: height, filter: 'Lanczos' - }, function(err) { + }, function (err) { if (err) { throw err; } else { @@ -698,7 +697,7 @@ async.series({ if (typeof imagemagickNative !== 'undefined') { pngSuite.add('imagemagick-native-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { imagemagickNative.convert({ srcData: inputPngBuffer, width: width, @@ -713,7 +712,7 @@ async.series({ // gm pngSuite.add('gm-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(fixtures.inputPng) .resize(width, height) .filter('Lanczos') @@ -727,7 +726,7 @@ async.series({ } }).add('gm-file-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(fixtures.inputPng) .resize(width, height) .filter('Lanczos') @@ -744,10 +743,10 @@ async.series({ // sharp pngSuite.add('sharp-buffer-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputPngBuffer) .resize(width, height) - .toFile(fixtures.outputPng, function(err) { + .toFile(fixtures.outputPng, function (err) { if (err) { throw err; } else { @@ -757,10 +756,10 @@ async.series({ } }).add('sharp-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputPngBuffer) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -771,10 +770,10 @@ async.series({ } }).add('sharp-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputPng) .resize(width, height) - .toFile(fixtures.outputPng, function(err) { + .toFile(fixtures.outputPng, function (err) { if (err) { throw err; } else { @@ -784,10 +783,10 @@ async.series({ } }).add('sharp-file-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputPng) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -798,11 +797,11 @@ async.series({ } }).add('sharp-progressive', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputPngBuffer) .resize(width, height) .progressive() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -813,11 +812,11 @@ async.series({ } }).add('sharp-withoutAdaptiveFiltering', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputPngBuffer) .resize(width, height) .withoutAdaptiveFiltering() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -827,21 +826,21 @@ async.series({ }); } }); - pngSuite.on('cycle', function(event) { + pngSuite.on('cycle', function (event) { console.log(' png ' + String(event.target)); - }).on('complete', function() { + }).on('complete', function () { callback(null, this.filter('fastest').map('name')); }).run(); }, // WebP - webp: function(callback) { - var inputWebPBuffer = fs.readFileSync(fixtures.inputWebP); + webp: function (callback) { + const inputWebPBuffer = fs.readFileSync(fixtures.inputWebP); (new Benchmark.Suite('webp')).add('sharp-buffer-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputWebPBuffer) .resize(width, height) - .toFile(fixtures.outputWebP, function(err) { + .toFile(fixtures.outputWebP, function (err) { if (err) { throw err; } else { @@ -851,10 +850,10 @@ async.series({ } }).add('sharp-buffer-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(inputWebPBuffer) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -865,10 +864,10 @@ async.series({ } }).add('sharp-file-file', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputWebP) .resize(width, height) - .toFile(fixtures.outputWebP, function(err) { + .toFile(fixtures.outputWebP, function (err) { if (err) { throw err; } else { @@ -878,10 +877,10 @@ async.series({ } }).add('sharp-file-buffer', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputWebp) .resize(width, height) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -890,15 +889,15 @@ async.series({ } }); } - }).on('cycle', function(event) { + }).on('cycle', function (event) { console.log('webp ' + String(event.target)); - }).on('complete', function() { + }).on('complete', function () { callback(null, this.filter('fastest').map('name')); }).run(); } -}, function(err, results) { +}, function (err, results) { assert(!err, err); - Object.keys(results).forEach(function(format) { + Object.keys(results).forEach(function (format) { if (results[format].toString().substr(0, 5) !== 'sharp') { console.log('sharp was slower than ' + results[format] + ' for ' + format); } diff --git a/test/bench/random.js b/test/bench/random.js index a781e76a..88388130 100644 --- a/test/bench/random.js +++ b/test/bench/random.js @@ -1,26 +1,26 @@ 'use strict'; -var imagemagick = require('imagemagick'); -var gm = require('gm'); -var assert = require('assert'); -var Benchmark = require('benchmark'); +const imagemagick = require('imagemagick'); +const gm = require('gm'); +const assert = require('assert'); +const Benchmark = require('benchmark'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); sharp.cache(false); sharp.simd(true); -var min = 320; -var max = 960; +const min = 320; +const max = 960; -var randomDimension = function() { +const randomDimension = function () { return Math.ceil(Math.random() * (max - min) + min); }; new Benchmark.Suite('random').add('imagemagick', { defer: true, - fn: function(deferred) { + fn: function (deferred) { imagemagick.resize({ srcPath: fixtures.inputJpg, dstPath: fixtures.outputJpg, @@ -29,7 +29,7 @@ new Benchmark.Suite('random').add('imagemagick', { height: randomDimension(), format: 'jpg', filter: 'Lanczos' - }, function(err) { + }, function (err) { if (err) { throw err; } else { @@ -39,7 +39,7 @@ new Benchmark.Suite('random').add('imagemagick', { } }).add('gm', { defer: true, - fn: function(deferred) { + fn: function (deferred) { gm(fixtures.inputJpg) .resize(randomDimension(), randomDimension()) .filter('Lanczos') @@ -55,10 +55,10 @@ new Benchmark.Suite('random').add('imagemagick', { } }).add('sharp', { defer: true, - fn: function(deferred) { + fn: function (deferred) { sharp(fixtures.inputJpg) .resize(randomDimension(), randomDimension()) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) { throw err; } else { @@ -67,9 +67,9 @@ new Benchmark.Suite('random').add('imagemagick', { } }); } -}).on('cycle', function(event) { +}).on('cycle', function (event) { console.log(String(event.target)); -}).on('complete', function() { - var winner = this.filter('fastest').map('name'); +}).on('complete', function () { + const winner = this.filter('fastest').map('name'); assert.strictEqual('sharp', String(winner), 'sharp was slower than ' + winner); }).run(); diff --git a/test/saliency/humanae/download.js b/test/saliency/humanae/download.js index 18e88d90..7a43fd42 100644 --- a/test/saliency/humanae/download.js +++ b/test/saliency/humanae/download.js @@ -1,5 +1,4 @@ 'use strict'; -/*jshint esversion: 6 */ const fs = require('fs'); const request = require('request'); @@ -10,7 +9,7 @@ const client = tumblr.createClient({ consumer_secret: '***' }); -const fetchImages = function(offset) { +const fetchImages = function (offset) { console.log(`Fetching offset ${offset}`); client.posts('humanae', { type: 'photo', @@ -21,8 +20,7 @@ const fetchImages = function(offset) { response.posts.forEach((post) => { const url = post.photos[0].alt_sizes .filter((image) => image.width === 100) - .map((image) => image.url) - [0]; + .map((image) => image.url)[0]; const filename = `./images/${post.id}.jpg`; try { fs.statSync(filename); diff --git a/test/saliency/humanae/tone.js b/test/saliency/humanae/tone.js index d89d023d..65f37d1a 100644 --- a/test/saliency/humanae/tone.js +++ b/test/saliency/humanae/tone.js @@ -1,8 +1,7 @@ 'use strict'; -/*jshint esversion: 6 */ const fs = require('fs'); -const child_process = require('child_process'); +const childProcess = require('child_process'); const a = []; const b = []; @@ -12,7 +11,7 @@ fs.readdirSync('./images') .forEach((file) => { // Extract one pixel, avoiding first DCT block, and return value of A and B channels const command = `convert ./images/${file}[1x1+8+8] -colorspace lab -format "%[fx:u.g] %[fx:u.b]" info:`; - const result = child_process.execSync(command, { encoding: 'utf8' }); + const result = childProcess.execSync(command, { encoding: 'utf8' }); const ab = result.split(' '); a.push(ab[0]); b.push(ab[1]); @@ -22,7 +21,7 @@ a.sort((v1, v2) => v1 - v2); b.sort((v1, v2) => v1 - v2); // Convert from 0..1 to -128..128 -const convert = function(v) { +const convert = function (v) { return Math.round(256 * (v - 0.5)); }; diff --git a/test/saliency/report.js b/test/saliency/report.js index c46abc76..42c64ad3 100644 --- a/test/saliency/report.js +++ b/test/saliency/report.js @@ -1,5 +1,4 @@ 'use strict'; -/*jshint esversion: 6 */ const os = require('os'); const fs = require('fs'); @@ -16,7 +15,7 @@ const concurrency = os.cpus().length; const scores = {}; -const incrementScore = function(accuracy, crop) { +const incrementScore = function (accuracy, crop) { if (typeof scores[accuracy] === 'undefined') { scores[accuracy] = {}; } @@ -29,36 +28,36 @@ const incrementScore = function(accuracy, crop) { const userData = require('./userData.json'); const files = Object.keys(userData); -async.eachLimit(files, concurrency, function(file, done) { +async.eachLimit(files, concurrency, function (file, done) { const filename = path.join(__dirname, 'Image', file); const salientWidth = userData[file].right - userData[file].left; const salientHeight = userData[file].bottom - userData[file].top; - sharp(filename).metadata(function(err, metadata) { + sharp(filename).metadata(function (err, metadata) { if (err) console.log(err); - async.each(Object.keys(crops), function(crop, done) { + async.each(Object.keys(crops), function (crop, done) { async.parallel([ // Left edge accuracy - function(done) { - sharp(filename).resize(salientWidth, metadata.height).crop(crops[crop]).toBuffer(function(err, data, info) { + function (done) { + sharp(filename).resize(salientWidth, metadata.height).crop(crops[crop]).toBuffer(function (err, data, info) { const accuracy = Math.round(Math.abs(userData[file].left - info.cropCalcLeft) / (metadata.width - salientWidth) * 100); incrementScore(accuracy, crop); - done(); + done(err); }); }, // Top edge accuracy - function(done) { - sharp(filename).resize(metadata.width, salientHeight).crop(crops[crop]).toBuffer(function(err, data, info) { + function (done) { + sharp(filename).resize(metadata.width, salientHeight).crop(crops[crop]).toBuffer(function (err, data, info) { const accuracy = Math.round(Math.abs(userData[file].top - info.cropCalcTop) / (metadata.height - salientHeight) * 100); incrementScore(accuracy, crop); - done(); + done(err); }); } ], done); }, done); }); -}, function() { +}, function () { const report = []; - Object.keys(scores).forEach(function(accuracy) { + Object.keys(scores).forEach(function (accuracy) { report.push( Object.assign({ accuracy: parseInt(accuracy, 10) diff --git a/test/saliency/userData.js b/test/saliency/userData.js index ab2961db..c5358d30 100644 --- a/test/saliency/userData.js +++ b/test/saliency/userData.js @@ -1,5 +1,4 @@ 'use strict'; -/*jshint esversion: 6, loopfunc: true */ const fs = require('fs'); const path = require('path'); @@ -8,8 +7,8 @@ const userDataDir = 'UserData'; const images = {}; -const median = function(values) { - values.sort(function(a,b) { +const median = function (values) { + values.sort(function (a, b) { return a - b; }); const half = Math.floor(values.length / 2); @@ -21,7 +20,7 @@ const median = function(values) { }; // List of files -fs.readdirSync(userDataDir).forEach(function(file) { +fs.readdirSync(userDataDir).forEach(function (file) { // Contents of file const lines = fs.readFileSync(path.join(userDataDir, file), {encoding: 'utf-8'}).split(/\r\n/); // First line = number of entries @@ -39,8 +38,11 @@ fs.readdirSync(userDataDir).forEach(function(file) { const regions = lines[linePos].split('; '); linePos = linePos + 2; // Parse human-labelled regions for min/max coords - const lefts = [], tops = [], rights = [], bottoms = []; - regions.forEach(function(region) { + const lefts = []; + const tops = []; + const rights = []; + const bottoms = []; + regions.forEach(function (region) { if (region.indexOf(' ') !== -1) { const coords = region.split(' '); lefts.push(parseInt(coords[0], 10)); diff --git a/test/unit/alpha.js b/test/unit/alpha.js index 1f27544d..5514846e 100644 --- a/test/unit/alpha.js +++ b/test/unit/alpha.js @@ -1,16 +1,15 @@ 'use strict'; -var assert = require('assert'); -var fixtures = require('../fixtures'); -var sharp = require('../../index'); +const assert = require('assert'); +const fixtures = require('../fixtures'); +const sharp = require('../../index'); -describe('Alpha transparency', function() { - - it('Flatten to black', function(done) { +describe('Alpha transparency', function () { + it('Flatten to black', function (done) { sharp(fixtures.inputPngWithTransparency) .flatten() .resize(400, 300) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(400, info.width); assert.strictEqual(300, info.height); @@ -18,12 +17,12 @@ describe('Alpha transparency', function() { }); }); - it('Flatten to RGB orange', function(done) { + it('Flatten to RGB orange', function (done) { sharp(fixtures.inputPngWithTransparency) .flatten() .background({r: 255, g: 102, b: 0}) .resize(400, 300) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(400, info.width); assert.strictEqual(300, info.height); @@ -31,12 +30,12 @@ describe('Alpha transparency', function() { }); }); - it('Flatten to CSS/hex orange', function(done) { + it('Flatten to CSS/hex orange', function (done) { sharp(fixtures.inputPngWithTransparency) .flatten() .background('#ff6600') .resize(400, 300) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(400, info.width); assert.strictEqual(300, info.height); @@ -44,12 +43,12 @@ describe('Alpha transparency', function() { }); }); - it('Flatten 16-bit PNG with transparency to orange', function(done) { - var output = fixtures.path('output.flatten-rgb16-orange.jpg'); + it('Flatten 16-bit PNG with transparency to orange', function (done) { + const output = fixtures.path('output.flatten-rgb16-orange.jpg'); sharp(fixtures.inputPngWithTransparency16bit) .flatten() .background({r: 255, g: 102, b: 0}) - .toFile(output, function(err, info) { + .toFile(output, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual(32, info.width); @@ -59,10 +58,10 @@ describe('Alpha transparency', function() { }); }); - it('Do not flatten', function(done) { + it('Do not flatten', function (done) { sharp(fixtures.inputPngWithTransparency) .flatten(false) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(4, info.channels); @@ -70,11 +69,11 @@ describe('Alpha transparency', function() { }); }); - it('Ignored for JPEG', function(done) { + it('Ignored for JPEG', function (done) { sharp(fixtures.inputJpg) .background('#ff0000') .flatten() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); @@ -82,13 +81,13 @@ describe('Alpha transparency', function() { }); }); - it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function(done) { - var BASE_NAME = 'alpha-premultiply-enlargement-2048x1536-paper.png'; - var actual = fixtures.path('output.' + BASE_NAME); - var expected = fixtures.expected(BASE_NAME); + it('Enlargement with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) { + const base = 'alpha-premultiply-enlargement-2048x1536-paper.png'; + const actual = fixtures.path('output.' + base); + const expected = fixtures.expected(base); sharp(fixtures.inputPngAlphaPremultiplicationSmall) .resize(2048, 1536) - .toFile(actual, function(err) { + .toFile(actual, function (err) { if (err) { done(err); } else { @@ -98,13 +97,13 @@ describe('Alpha transparency', function() { }); }); - it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function(done) { - var BASE_NAME = 'alpha-premultiply-reduction-1024x768-paper.png'; - var actual = fixtures.path('output.' + BASE_NAME); - var expected = fixtures.expected(BASE_NAME); + it('Reduction with non-nearest neighbor interpolation shouldn’t cause dark edges', function (done) { + const base = 'alpha-premultiply-reduction-1024x768-paper.png'; + const actual = fixtures.path('output.' + base); + const expected = fixtures.expected(base); sharp(fixtures.inputPngAlphaPremultiplicationLarge) .resize(1024, 768) - .toFile(actual, function(err) { + .toFile(actual, function (err) { if (err) { done(err); } else { @@ -113,5 +112,4 @@ describe('Alpha transparency', function() { } }); }); - }); diff --git a/test/unit/bandbool.js b/test/unit/bandbool.js index 81e1ec2a..a5481312 100644 --- a/test/unit/bandbool.js +++ b/test/unit/bandbool.js @@ -1,22 +1,21 @@ 'use strict'; -var assert = require('assert'); -var fixtures = require('../fixtures'); -var sharp = require('../../index'); - -describe('Bandbool per-channel boolean operations', function() { +const assert = require('assert'); +const fixtures = require('../fixtures'); +const sharp = require('../../index'); +describe('Bandbool per-channel boolean operations', function () { [ sharp.bool.and, sharp.bool.or, sharp.bool.eor ] - .forEach(function(op) { - it(op + ' operation', function(done) { + .forEach(function (op) { + it(op + ' operation', function (done) { sharp(fixtures.inputPngBooleanNoAlpha) .bandbool(op) .toColourspace('b-w') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(200, info.width); assert.strictEqual(200, info.height); @@ -26,23 +25,24 @@ describe('Bandbool per-channel boolean operations', function() { }); }); - it('sRGB image retains 3 channels', function(done) { + it('sRGB image retains 3 channels', function (done) { sharp(fixtures.inputJpg) .bandbool('and') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual(3, info.channels); done(); }); - }); + }); - it('Invalid operation', function() { - assert.throws(function() { + it('Invalid operation', function () { + assert.throws(function () { sharp().bandbool('fail'); }); }); - it('Missing operation', function() { - assert.throws(function() { + it('Missing operation', function () { + assert.throws(function () { sharp().bandbool(); }); }); diff --git a/test/unit/blur.js b/test/unit/blur.js index e56aee08..76ffd345 100644 --- a/test/unit/blur.js +++ b/test/unit/blur.js @@ -1,17 +1,17 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Blur', function() { - - it('specific radius 1', function(done) { +describe('Blur', function () { + it('specific radius 1', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .blur(1) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -19,11 +19,12 @@ describe('Blur', function() { }); }); - it('specific radius 10', function(done) { + it('specific radius 10', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .blur(10) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -31,11 +32,12 @@ describe('Blur', function() { }); }); - it('specific radius 0.3', function(done) { + it('specific radius 0.3', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .blur(0.3) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -43,11 +45,12 @@ describe('Blur', function() { }); }); - it('mild blur', function(done) { + it('mild blur', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .blur() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -55,17 +58,18 @@ describe('Blur', function() { }); }); - it('invalid radius', function() { - assert.throws(function() { + it('invalid radius', function () { + assert.throws(function () { sharp(fixtures.inputJpg).blur(0.1); }); }); - it('blurred image is smaller than non-blurred', function(done) { + it('blurred image is smaller than non-blurred', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .blur(false) - .toBuffer(function(err, notBlurred, info) { + .toBuffer(function (err, notBlurred, info) { + if (err) throw err; assert.strictEqual(true, notBlurred.length > 0); assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -73,7 +77,8 @@ describe('Blur', function() { sharp(fixtures.inputJpg) .resize(320, 240) .blur(true) - .toBuffer(function(err, blurred, info) { + .toBuffer(function (err, blurred, info) { + if (err) throw err; assert.strictEqual(true, blurred.length > 0); assert.strictEqual(true, blurred.length < notBlurred.length); assert.strictEqual('jpeg', info.format); @@ -83,5 +88,4 @@ describe('Blur', function() { }); }); }); - }); diff --git a/test/unit/boolean.js b/test/unit/boolean.js index 57538688..0dd82fd1 100644 --- a/test/unit/boolean.js +++ b/test/unit/boolean.js @@ -1,26 +1,25 @@ 'use strict'; -var fs = require('fs'); -var assert = require('assert'); -var fixtures = require('../fixtures'); -var sharp = require('../../index'); +const fs = require('fs'); +const assert = require('assert'); -describe('Boolean operation between two images', function() { +const fixtures = require('../fixtures'); +const sharp = require('../../index'); - var inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest); +describe('Boolean operation between two images', function () { + const inputJpgBooleanTestBuffer = fs.readFileSync(fixtures.inputJpgBooleanTest); [ sharp.bool.and, sharp.bool.or, sharp.bool.eor ] - .forEach(function(op) { - - it(op + ' operation, file', function(done) { + .forEach(function (op) { + it(op + ' operation, file', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .boolean(fixtures.inputJpgBooleanTest, op) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -28,11 +27,11 @@ describe('Boolean operation between two images', function() { }); }); - it(op + ' operation, buffer', function(done) { + it(op + ' operation, buffer', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .boolean(inputJpgBooleanTestBuffer, op) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -40,15 +39,15 @@ describe('Boolean operation between two images', function() { }); }); - it(op + ' operation, raw', function(done) { + it(op + ' operation, raw', function (done) { sharp(fixtures.inputJpgBooleanTest) .raw() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; sharp(fixtures.inputJpg) .resize(320, 240) .boolean(data, op, { raw: info }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -56,23 +55,22 @@ describe('Boolean operation between two images', function() { }); }); }); - }); - it('Invalid operation', function() { - assert.throws(function() { + it('Invalid operation', function () { + assert.throws(function () { sharp().boolean(fixtures.inputJpgBooleanTest, 'fail'); }); }); - it('Invalid operation, non-string', function() { - assert.throws(function() { + it('Invalid operation, non-string', function () { + assert.throws(function () { sharp().boolean(fixtures.inputJpgBooleanTest, null); }); }); - it('Missing input', function() { - assert.throws(function() { + it('Missing input', function () { + assert.throws(function () { sharp().boolean(); }); }); diff --git a/test/unit/cache.js b/test/unit/cache.js index 7f113edc..30b2c084 100644 --- a/test/unit/cache.js +++ b/test/unit/cache.js @@ -1,9 +1,9 @@ 'use strict'; -var sharp = require('../../index'); +const sharp = require('../../index'); // Define SHARP_TEST_WITHOUT_CACHE environment variable to prevent use of libvips' cache -beforeEach(function() { - sharp.cache(process.env.SHARP_TEST_WITHOUT_CACHE ? false : true); +beforeEach(function () { + sharp.cache(!process.env.SHARP_TEST_WITHOUT_CACHE); }); diff --git a/test/unit/clone.js b/test/unit/clone.js index c59d5b89..445b5030 100644 --- a/test/unit/clone.js +++ b/test/unit/clone.js @@ -1,27 +1,26 @@ 'use strict'; -var fs = require('fs'); -var assert = require('assert'); +const fs = require('fs'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Clone', function() { - - beforeEach(function() { +describe('Clone', function () { + beforeEach(function () { sharp.cache(false); }); - afterEach(function() { + afterEach(function () { sharp.cache(true); }); - it('Read from Stream and write to multiple Streams', function(done) { - var finishEventsExpected = 2; + it('Read from Stream and write to multiple Streams', function (done) { + let finishEventsExpected = 2; // Output stream 1 - var output1 = fixtures.path('output.multi-stream.1.jpg'); - var writable1 = fs.createWriteStream(output1); - writable1.on('finish', function() { - sharp(output1).toBuffer(function(err, data, info) { + const output1 = fixtures.path('output.multi-stream.1.jpg'); + const writable1 = fs.createWriteStream(output1); + writable1.on('finish', function () { + sharp(output1).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -36,10 +35,10 @@ describe('Clone', function() { }); }); // Output stream 2 - var output2 = fixtures.path('output.multi-stream.2.jpg'); - var writable2 = fs.createWriteStream(output2); - writable2.on('finish', function() { - sharp(output2).toBuffer(function(err, data, info) { + const output2 = fixtures.path('output.multi-stream.2.jpg'); + const writable2 = fs.createWriteStream(output2); + writable2.on('finish', function () { + sharp(output2).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -54,12 +53,11 @@ describe('Clone', function() { }); }); // Create parent instance - var rotator = sharp().rotate(90); + const rotator = sharp().rotate(90); // Cloned instances with differing dimensions rotator.clone().resize(320, 240).pipe(writable1); rotator.clone().resize(100, 122).pipe(writable2); // Go fs.createReadStream(fixtures.inputJpg).pipe(rotator); }); - }); diff --git a/test/unit/colourspace.js b/test/unit/colourspace.js index 1eb4ee31..ac96174b 100644 --- a/test/unit/colourspace.js +++ b/test/unit/colourspace.js @@ -1,20 +1,19 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Colour space conversion', function() { - - it('To greyscale', function(done) { +describe('Colour space conversion', function () { + it('To greyscale', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .greyscale() .toFile(fixtures.path('output.greyscale-gamma-0.0.jpg'), done); }); - it('To greyscale with gamma correction', function(done) { + it('To greyscale with gamma correction', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .gamma() @@ -22,19 +21,19 @@ describe('Colour space conversion', function() { .toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done); }); - it('Not to greyscale', function(done) { + it('Not to greyscale', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .greyscale(false) .toFile(fixtures.path('output.greyscale-not.jpg'), done); }); - it('Greyscale with single channel output', function(done) { + it('Greyscale with single channel output', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .greyscale() .toColourspace('b-w') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(1, info.channels); assert.strictEqual(320, info.width); @@ -44,10 +43,10 @@ describe('Colour space conversion', function() { }); if (sharp.format.tiff.input.file && sharp.format.webp.output.buffer) { - it('From 1-bit TIFF to sRGB WebP [slow]', function(done) { + it('From 1-bit TIFF to sRGB WebP [slow]', function (done) { sharp(fixtures.inputTiff) .webp() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('webp', info.format); @@ -56,10 +55,10 @@ describe('Colour space conversion', function() { }); } - it('From CMYK to sRGB', function(done) { + it('From CMYK to sRGB', function (done) { sharp(fixtures.inputJpgWithCmykProfile) .resize(320) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -68,12 +67,12 @@ describe('Colour space conversion', function() { }); }); - it('From CMYK to sRGB with white background, not yellow', function(done) { + it('From CMYK to sRGB with white background, not yellow', function (done) { sharp(fixtures.inputJpgWithCmykProfile) .resize(320, 240) .background('white') .embed() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -82,10 +81,10 @@ describe('Colour space conversion', function() { }); }); - it('From profile-less CMYK to sRGB', function(done) { + it('From profile-less CMYK to sRGB', function (done) { sharp(fixtures.inputJpgWithCmykNoProfile) .resize(320) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -93,8 +92,8 @@ describe('Colour space conversion', function() { }); }); - it('Invalid input', function() { - assert.throws(function() { + it('Invalid input', function () { + assert.throws(function () { sharp(fixtures.inputJpg) .toColourspace(null); }); diff --git a/test/unit/convolve.js b/test/unit/convolve.js index 082b5a1a..2a9b4676 100644 --- a/test/unit/convolve.js +++ b/test/unit/convolve.js @@ -1,13 +1,12 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Convolve', function() { - - it('specific convolution kernel 1', function(done) { +describe('Convolve', function () { + it('specific convolution kernel 1', function (done) { sharp(fixtures.inputPngStripesV) .convolve({ width: 3, @@ -15,10 +14,10 @@ describe('Convolve', function() { scale: 50, offset: 0, kernel: [ 10, 20, 10, - 0, 0, 0, + 0, 0, 0, 10, 20, 10 ] }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(320, info.width); @@ -27,7 +26,7 @@ describe('Convolve', function() { }); }); - it('specific convolution kernel 2', function(done) { + it('specific convolution kernel 2', function (done) { sharp(fixtures.inputPngStripesH) .convolve({ width: 3, @@ -36,7 +35,7 @@ describe('Convolve', function() { 2, 0, 2, 1, 0, 1 ] }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(320, info.width); @@ -45,7 +44,7 @@ describe('Convolve', function() { }); }); - it('horizontal Sobel operator', function(done) { + it('horizontal Sobel operator', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .convolve({ @@ -55,7 +54,7 @@ describe('Convolve', function() { -2, 0, 2, -1, 0, 1 ] }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -64,14 +63,14 @@ describe('Convolve', function() { }); }); - describe('invalid kernel specification', function() { - it('missing', function() { - assert.throws(function() { + describe('invalid kernel specification', function () { + it('missing', function () { + assert.throws(function () { sharp(fixtures.inputJpg).convolve({}); }); }); - it('incorrect data format', function() { - assert.throws(function() { + it('incorrect data format', function () { + assert.throws(function () { sharp(fixtures.inputJpg).convolve({ width: 3, height: 3, @@ -79,8 +78,8 @@ describe('Convolve', function() { }); }); }); - it('incorrect dimensions', function() { - assert.throws(function() { + it('incorrect dimensions', function () { + assert.throws(function () { sharp(fixtures.inputJpg).convolve({ width: 3, height: 4, diff --git a/test/unit/cpplint.js b/test/unit/cpplint.js index ae174dba..ed474cb8 100644 --- a/test/unit/cpplint.js +++ b/test/unit/cpplint.js @@ -1,21 +1,20 @@ 'use strict'; -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); +const fs = require('fs'); +const path = require('path'); +const assert = require('assert'); -var cpplint = require('node-cpplint/lib/'); - -describe('cpplint', function() { +const cpplint = require('node-cpplint/lib/'); +describe('cpplint', function () { // Ignore cpplint failures, possibly newline-related, on Windows if (process.platform !== 'win32') { // List C++ source files - fs.readdirSync(path.join(__dirname, '..', '..', 'src')).filter(function(source) { + fs.readdirSync(path.join(__dirname, '..', '..', 'src')).filter(function (source) { return source !== 'libvips'; - }).forEach(function(source) { - var file = path.join('src', source); - it(file, function(done) { + }).forEach(function (source) { + const file = path.join('src', source); + it(file, function (done) { // Lint each source file cpplint({ files: [file], @@ -34,18 +33,16 @@ describe('cpplint', function() { indentation_namespace: false } } - }, function(err, report) { + }, function (err, report) { if (err) { throw err; } - var expected = {}; + const expected = {}; expected[file] = []; assert.deepEqual(expected, report); done(); }); }); - }); } - }); diff --git a/test/unit/crop.js b/test/unit/crop.js index 0c7ac156..b4ffc408 100644 --- a/test/unit/crop.js +++ b/test/unit/crop.js @@ -1,12 +1,11 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); - -describe('Crop', function() { +const sharp = require('../../index'); +const fixtures = require('../fixtures'); +describe('Crop', function () { [ { name: 'North', @@ -113,12 +112,12 @@ describe('Crop', function() { gravity: sharp.gravity.northwest, fixture: 'gravity-west.jpg' } - ].forEach(function(settings) { - it(settings.name + ' gravity', function(done) { + ].forEach(function (settings) { + it(settings.name + ' gravity', function (done) { sharp(fixtures.inputJpg) .resize(settings.width, settings.height) .crop(settings.gravity) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(settings.width, info.width); assert.strictEqual(settings.height, info.height); @@ -127,11 +126,11 @@ describe('Crop', function() { }); }); - it('Allows specifying the gravity as a string', function(done) { + it('Allows specifying the gravity as a string', function (done) { sharp(fixtures.inputJpg) .resize(80, 320) .crop('east') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(80, info.width); assert.strictEqual(320, info.height); @@ -139,34 +138,33 @@ describe('Crop', function() { }); }); - it('Invalid values fail', function() { - assert.throws(function() { + it('Invalid values fail', function () { + assert.throws(function () { sharp().crop(9); }); - assert.throws(function() { + assert.throws(function () { sharp().crop(1.1); }); - assert.throws(function() { + assert.throws(function () { sharp().crop(-1); }); - assert.throws(function() { + assert.throws(function () { sharp().crop('zoinks'); }); }); - it('Uses default value when none specified', function() { - assert.doesNotThrow(function() { + it('Uses default value when none specified', function () { + assert.doesNotThrow(function () { sharp().crop(); }); }); - describe('Entropy-based strategy', function() { - - it('JPEG', function(done) { + describe('Entropy-based strategy', function () { + it('JPEG', function (done) { sharp(fixtures.inputJpgWithCmykProfile) .resize(80, 320) .crop(sharp.strategy.entropy) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); @@ -178,11 +176,11 @@ describe('Crop', function() { }); }); - it('PNG', function(done) { + it('PNG', function (done) { sharp(fixtures.inputPngWithTransparency) .resize(320, 80) .crop(sharp.strategy.entropy) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(4, info.channels); @@ -193,16 +191,14 @@ describe('Crop', function() { fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done); }); }); - }); - describe('Attention strategy', function() { - - it('JPEG', function(done) { + describe('Attention strategy', function () { + it('JPEG', function (done) { sharp(fixtures.inputJpgWithCmykProfile) .resize(80, 320) .crop(sharp.strategy.attention) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); @@ -214,11 +210,11 @@ describe('Crop', function() { }); }); - it('PNG', function(done) { + it('PNG', function (done) { sharp(fixtures.inputPngWithTransparency) .resize(320, 80) .crop(sharp.strategy.attention) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(4, info.channels); @@ -229,6 +225,5 @@ describe('Crop', function() { fixtures.assertSimilar(fixtures.expected('crop-strategy.png'), data, done); }); }); - }); }); diff --git a/test/unit/embed.js b/test/unit/embed.js index 32d91fad..68df784c 100644 --- a/test/unit/embed.js +++ b/test/unit/embed.js @@ -1,18 +1,17 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Embed', function() { - - it('JPEG within PNG, no alpha channel', function(done) { +describe('Embed', function () { + it('JPEG within PNG, no alpha channel', function (done) { sharp(fixtures.inputJpg) .embed() .resize(320, 240) .png() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -24,13 +23,13 @@ describe('Embed', function() { }); if (sharp.format.webp.output.buffer) { - it('JPEG within WebP, to include alpha channel', function(done) { + it('JPEG within WebP, to include alpha channel', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .background({r: 0, g: 0, b: 0, a: 0}) .embed() .webp() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('webp', info.format); @@ -42,11 +41,11 @@ describe('Embed', function() { }); } - it('PNG with alpha channel', function(done) { + it('PNG with alpha channel', function (done) { sharp(fixtures.inputPngWithTransparency) .resize(50, 50) .embed() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -57,11 +56,11 @@ describe('Embed', function() { }); }); - it('16-bit PNG with alpha channel', function(done) { + it('16-bit PNG with alpha channel', function (done) { sharp(fixtures.inputPngWithTransparency16bit) .resize(32, 16) .embed() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -72,12 +71,12 @@ describe('Embed', function() { }); }); - it('16-bit PNG with alpha channel onto RGBA', function(done) { + it('16-bit PNG with alpha channel onto RGBA', function (done) { sharp(fixtures.inputPngWithTransparency16bit) .resize(32, 16) .embed() .background({r: 0, g: 0, b: 0, a: 0}) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -88,12 +87,12 @@ describe('Embed', function() { }); }); - it('PNG with 2 channels', function(done) { + it('PNG with 2 channels', function (done) { sharp(fixtures.inputPngWithGreyAlpha) .resize(32, 16) .embed() .background({r: 0, g: 0, b: 0, a: 0}) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -104,11 +103,11 @@ describe('Embed', function() { }); }); - it('Enlarge and embed', function(done) { + it('Enlarge and embed', function (done) { sharp(fixtures.inputPngWithOneColor) .embed() .resize(320, 240) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -118,5 +117,4 @@ describe('Embed', function() { fixtures.assertSimilar(fixtures.expected('embed-enlarge.png'), data, done); }); }); - }); diff --git a/test/unit/extend.js b/test/unit/extend.js index ca48d350..ef53838c 100644 --- a/test/unit/extend.js +++ b/test/unit/extend.js @@ -1,18 +1,17 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); describe('Extend', function () { - - it('extend all sides equally with RGB', function(done) { + it('extend all sides equally with RGB', function (done) { sharp(fixtures.inputJpg) .resize(120) .background({r: 255, g: 0, b: 0}) .extend(10) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(140, info.width); assert.strictEqual(118, info.height); @@ -20,12 +19,12 @@ describe('Extend', function () { }); }); - it('extend sides unequally with RGBA', function(done) { + it('extend sides unequally with RGBA', function (done) { sharp(fixtures.inputPngWithTransparency16bit) .resize(120) .background({r: 0, g: 0, b: 0, a: 0}) .extend({top: 50, bottom: 0, left: 10, right: 35}) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(165, info.width); assert.strictEqual(170, info.height); @@ -33,32 +32,32 @@ describe('Extend', function () { }); }); - it('missing parameter fails', function() { - assert.throws(function() { + it('missing parameter fails', function () { + assert.throws(function () { sharp().extend(); }); }); - it('negative fails', function() { - assert.throws(function() { + it('negative fails', function () { + assert.throws(function () { sharp().extend(-1); }); }); - it('partial object fails', function() { - assert.throws(function() { + it('partial object fails', function () { + assert.throws(function () { sharp().extend({top: 1}); }); }); - it('should add alpha channel before extending with a transparent Background', function( done ){ + it('should add alpha channel before extending with a transparent Background', function (done) { sharp(fixtures.inputJpgWithLandscapeExif1) .background({r: 0, g: 0, b: 0, a: 0}) - .toFormat( sharp.format.png ) + .toFormat(sharp.format.png) .extend({top: 0, bottom: 10, left: 0, right: 10}) - .toBuffer( function(err, data, info){ + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual(610, info.width); assert.strictEqual(460, info.height); fixtures.assertSimilar(fixtures.expected('addAlphaChanelBeforeExtend.png'), data, done); }); }); - }); diff --git a/test/unit/extract.js b/test/unit/extract.js index 655eab52..fb79375d 100644 --- a/test/unit/extract.js +++ b/test/unit/extract.js @@ -1,16 +1,15 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Partial image extraction', function() { - - it('JPEG', function(done) { +describe('Partial image extraction', function () { + it('JPEG', function (done) { sharp(fixtures.inputJpg) .extract({ left: 2, top: 2, width: 20, height: 20 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(20, info.width); assert.strictEqual(20, info.height); @@ -18,10 +17,10 @@ describe('Partial image extraction', function() { }); }); - it('PNG', function(done) { + it('PNG', function (done) { sharp(fixtures.inputPng) .extract({ left: 200, top: 300, width: 400, height: 200 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(400, info.width); assert.strictEqual(200, info.height); @@ -30,10 +29,10 @@ describe('Partial image extraction', function() { }); if (sharp.format.webp.output.file) { - it('WebP', function(done) { + it('WebP', function (done) { sharp(fixtures.inputWebP) .extract({ left: 100, top: 50, width: 125, height: 200 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(125, info.width); assert.strictEqual(200, info.height); @@ -43,11 +42,11 @@ describe('Partial image extraction', function() { } if (sharp.format.tiff.output.file) { - it('TIFF', function(done) { + it('TIFF', function (done) { sharp(fixtures.inputTiff) .extract({ left: 34, top: 63, width: 341, height: 529 }) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(341, info.width); assert.strictEqual(529, info.height); @@ -56,11 +55,11 @@ describe('Partial image extraction', function() { }); } - it('Before resize', function(done) { + it('Before resize', function (done) { sharp(fixtures.inputJpg) .extract({ left: 10, top: 10, width: 10, height: 500 }) .resize(100, 100) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(100, info.width); assert.strictEqual(100, info.height); @@ -68,12 +67,12 @@ describe('Partial image extraction', function() { }); }); - it('After resize and crop', function(done) { + it('After resize and crop', function (done) { sharp(fixtures.inputJpg) .resize(500, 500) .crop(sharp.gravity.north) .extract({ left: 10, top: 10, width: 100, height: 100 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(100, info.width); assert.strictEqual(100, info.height); @@ -81,13 +80,13 @@ describe('Partial image extraction', function() { }); }); - it('Before and after resize and crop', function(done) { + it('Before and after resize and crop', function (done) { sharp(fixtures.inputJpg) .extract({ left: 0, top: 0, width: 700, height: 700 }) .resize(500, 500) .crop(sharp.gravity.north) .extract({ left: 10, top: 10, width: 100, height: 100 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(100, info.width); assert.strictEqual(100, info.height); @@ -95,11 +94,11 @@ describe('Partial image extraction', function() { }); }); - it('Extract then rotate', function(done) { + it('Extract then rotate', function (done) { sharp(fixtures.inputPngWithGreyAlpha) .extract({ left: 20, top: 10, width: 380, height: 280 }) .rotate(90) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(280, info.width); assert.strictEqual(380, info.height); @@ -107,11 +106,11 @@ describe('Partial image extraction', function() { }); }); - it('Rotate then extract', function(done) { + it('Rotate then extract', function (done) { sharp(fixtures.inputPngWithGreyAlpha) .rotate(90) .extract({ left: 20, top: 10, width: 280, height: 380 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(280, info.width); assert.strictEqual(380, info.height); @@ -119,69 +118,69 @@ describe('Partial image extraction', function() { }); }); - describe('Invalid parameters', function() { + describe('Invalid parameters', function () { describe('using the legacy extract(top,left,width,height) syntax', function () { - it('String top', function() { - assert.throws(function() { + it('String top', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract('spoons', 10, 10, 10); }); }); - it('Non-integral left', function() { - assert.throws(function() { + it('Non-integral left', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract(10, 10.2, 10, 10); }); }); - it('Negative width - negative', function() { - assert.throws(function() { + it('Negative width - negative', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract(10, 10, -10, 10); }); }); - it('Null height', function() { - assert.throws(function() { + it('Null height', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract(10, 10, 10, null); }); }); }); - it('Undefined', function() { - assert.throws(function() { + it('Undefined', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract(); }); }); - it('String top', function() { - assert.throws(function() { + it('String top', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract({ left: 10, top: 'spoons', width: 10, height: 10 }); }); }); - it('Non-integral left', function() { - assert.throws(function() { + it('Non-integral left', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract({ left: 10.2, top: 10, width: 10, height: 10 }); }); }); - it('Negative width - negative', function() { - assert.throws(function() { + it('Negative width - negative', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: -10, height: 10 }); }); }); - it('Null height', function() { - assert.throws(function() { + it('Null height', function () { + assert.throws(function () { sharp(fixtures.inputJpg).extract({ left: 10, top: 10, width: 10, height: null }); }); }); - it('Bad image area', function(done) { + it('Bad image area', function (done) { sharp(fixtures.inputJpg) .extract({ left: 3000, top: 10, width: 10, height: 10 }) - .toBuffer(function(err) { + .toBuffer(function (err) { assert(err instanceof Error); - assert.strictEqual(err.message, "extract_area: bad extract area\n"); + assert.strictEqual(err.message, 'extract_area: bad extract area\n'); done(); }); }); diff --git a/test/unit/extractChannel.js b/test/unit/extractChannel.js index 60f69b5f..59fc7001 100644 --- a/test/unit/extractChannel.js +++ b/test/unit/extractChannel.js @@ -1,17 +1,16 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Image channel extraction', function() { - - it('Red channel', function(done) { +describe('Image channel extraction', function () { + it('Red channel', function (done) { sharp(fixtures.inputJpg) .extractChannel('red') - .resize(320,240) - .toBuffer(function(err, data, info) { + .resize(320, 240) + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -19,11 +18,11 @@ describe('Image channel extraction', function() { }); }); - it('Green channel', function(done) { + it('Green channel', function (done) { sharp(fixtures.inputJpg) .extractChannel('green') - .resize(320,240) - .toBuffer(function(err, data, info) { + .resize(320, 240) + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -31,11 +30,11 @@ describe('Image channel extraction', function() { }); }); - it('Blue channel', function(done) { + it('Blue channel', function (done) { sharp(fixtures.inputJpg) .extractChannel('blue') - .resize(320,240) - .toBuffer(function(err, data, info) { + .resize(320, 240) + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -43,11 +42,11 @@ describe('Image channel extraction', function() { }); }); - it('Blue channel by number', function(done) { + it('Blue channel by number', function (done) { sharp(fixtures.inputJpg) .extractChannel(2) - .resize(320,240) - .toBuffer(function(err, data, info) { + .resize(320, 240) + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -55,27 +54,26 @@ describe('Image channel extraction', function() { }); }); - it('Invalid channel number', function() { - assert.throws(function() { + it('Invalid channel number', function () { + assert.throws(function () { sharp(fixtures.inputJpg) .extractChannel(-1); }); }); - it('No arguments', function() { - assert.throws(function() { + it('No arguments', function () { + assert.throws(function () { sharp(fixtures.inputJpg) .extractChannel(); }); }); - it('Non-existant channel', function(done) { + it('Non-existant channel', function (done) { sharp(fixtures.inputPng) .extractChannel(1) - .toBuffer(function(err) { + .toBuffer(function (err) { assert(err instanceof Error); done(); }); }); - }); diff --git a/test/unit/fixtures.js b/test/unit/fixtures.js index 5d5e8373..8fecf2de 100644 --- a/test/unit/fixtures.js +++ b/test/unit/fixtures.js @@ -1,25 +1,25 @@ 'use strict'; -var assert = require('assert'); -var fixtures = require('../fixtures'); +const assert = require('assert'); +const fixtures = require('../fixtures'); -describe('Test fixtures', function() { - describe('assertMaxColourDistance', function() { - it('should throw an Error when images have a different number of channels', function() { - assert.throws(function() { +describe('Test fixtures', function () { + describe('assertMaxColourDistance', function () { + it('should throw an Error when images have a different number of channels', function () { + assert.throws(function () { fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer1, fixtures.inputJpg); }); }); - it('should throw an Error when images have different dimensions', function() { - assert.throws(function() { + it('should throw an Error when images have different dimensions', function () { + assert.throws(function () { fixtures.assertMaxColourDistance(fixtures.inputJpg, fixtures.inputJpgWithExif); }); }); - it('should accept a zero threshold when comparing an image to itself', function() { - var image = fixtures.inputPngOverlayLayer0; + it('should accept a zero threshold when comparing an image to itself', function () { + const image = fixtures.inputPngOverlayLayer0; fixtures.assertMaxColourDistance(image, image, 0); }); - it('should accept a numeric threshold for two different images', function() { + it('should accept a numeric threshold for two different images', function () { fixtures.assertMaxColourDistance(fixtures.inputPngOverlayLayer0, fixtures.inputPngOverlayLayer1, 100); }); }); diff --git a/test/unit/gamma.js b/test/unit/gamma.js index 252dce65..d2f09164 100644 --- a/test/unit/gamma.js +++ b/test/unit/gamma.js @@ -1,16 +1,16 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Gamma correction', function() { - - it('value of 0.0 (disabled)', function(done) { +describe('Gamma correction', function () { + it('value of 0.0 (disabled)', function (done) { sharp(fixtures.inputJpgWithGammaHoliness) .resize(129, 111) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(129, info.width); assert.strictEqual(111, info.height); @@ -18,11 +18,12 @@ describe('Gamma correction', function() { }); }); - it('value of 2.2 (default)', function(done) { + it('value of 2.2 (default)', function (done) { sharp(fixtures.inputJpgWithGammaHoliness) .resize(129, 111) .gamma() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(129, info.width); assert.strictEqual(111, info.height); @@ -30,11 +31,12 @@ describe('Gamma correction', function() { }); }); - it('value of 3.0', function(done) { + it('value of 3.0', function (done) { sharp(fixtures.inputJpgWithGammaHoliness) .resize(129, 111) .gamma(3) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(129, info.width); assert.strictEqual(111, info.height); @@ -42,21 +44,21 @@ describe('Gamma correction', function() { }); }); - it('alpha transparency', function(done) { + it('alpha transparency', function (done) { sharp(fixtures.inputPngOverlayLayer1) .resize(320) .gamma() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(320, info.width); fixtures.assertSimilar(fixtures.expected('gamma-alpha.jpg'), data, { threshold: 11 }, done); }); }); - it('invalid value', function() { - assert.throws(function() { + it('invalid value', function () { + assert.throws(function () { sharp(fixtures.inputJpgWithGammaHoliness).gamma(4); }); }); - }); diff --git a/test/unit/interpolation.js b/test/unit/interpolation.js index 8aad57ef..c61ce8ad 100644 --- a/test/unit/interpolation.js +++ b/test/unit/interpolation.js @@ -1,22 +1,21 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Interpolators and kernels', function() { - - describe('Reducers', function() { +describe('Interpolators and kernels', function () { + describe('Reducers', function () { [ sharp.kernel.cubic, sharp.kernel.lanczos2, sharp.kernel.lanczos3 - ].forEach(function(kernel) { - it(kernel, function(done) { + ].forEach(function (kernel) { + it(kernel, function (done) { sharp(fixtures.inputJpg) .resize(320, null, { kernel: kernel }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -26,7 +25,7 @@ describe('Interpolators and kernels', function() { }); }); - describe('Enlargers', function() { + describe('Enlargers', function () { [ sharp.interpolator.nearest, sharp.interpolator.bilinear, @@ -34,11 +33,11 @@ describe('Interpolators and kernels', function() { sharp.interpolator.nohalo, sharp.interpolator.locallyBoundedBicubic, sharp.interpolator.vertexSplitQuadraticBasisSpline - ].forEach(function(interpolator) { - it(interpolator, function(done) { + ].forEach(function (interpolator) { + it(interpolator, function (done) { sharp(fixtures.inputJpg) .resize(320, null, { interpolator: interpolator }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -48,16 +47,15 @@ describe('Interpolators and kernels', function() { }); }); - it('unknown kernel throws', function() { - assert.throws(function() { + it('unknown kernel throws', function () { + assert.throws(function () { sharp().resize(null, null, { kernel: 'unknown' }); }); }); - it('unknown interpolator throws', function() { - assert.throws(function() { + it('unknown interpolator throws', function () { + assert.throws(function () { sharp().resize(null, null, { interpolator: 'unknown' }); }); }); - }); diff --git a/test/unit/io.js b/test/unit/io.js index 05b0462b..981b174e 100644 --- a/test/unit/io.js +++ b/test/unit/io.js @@ -1,24 +1,23 @@ 'use strict'; -var fs = require('fs'); -var assert = require('assert'); +const fs = require('fs'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Input/output', function() { - - beforeEach(function() { +describe('Input/output', function () { + beforeEach(function () { sharp.cache(false); }); - afterEach(function() { + afterEach(function () { sharp.cache(true); }); - it('Read from File and write to Stream', function(done) { - var writable = fs.createWriteStream(fixtures.outputJpg); - writable.on('finish', function() { - sharp(fixtures.outputJpg).toBuffer(function(err, data, info) { + it('Read from File and write to Stream', function (done) { + const writable = fs.createWriteStream(fixtures.outputJpg); + writable.on('finish', function () { + sharp(fixtures.outputJpg).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -32,11 +31,11 @@ describe('Input/output', function() { sharp(fixtures.inputJpg).resize(320, 240).pipe(writable); }); - it('Read from Buffer and write to Stream', function(done) { - var inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); - var writable = fs.createWriteStream(fixtures.outputJpg); - writable.on('finish', function() { - sharp(fixtures.outputJpg).toBuffer(function(err, data, info) { + it('Read from Buffer and write to Stream', function (done) { + const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg); + const writable = fs.createWriteStream(fixtures.outputJpg); + writable.on('finish', function () { + sharp(fixtures.outputJpg).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -50,9 +49,9 @@ describe('Input/output', function() { sharp(inputJpgBuffer).resize(320, 240).pipe(writable); }); - it('Read from Stream and write to File', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function(err, info) { + it('Read from Stream and write to File', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('jpeg', info.format); @@ -64,9 +63,9 @@ describe('Input/output', function() { readable.pipe(pipeline); }); - it('Read from Stream and write to Buffer', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var pipeline = sharp().resize(320, 240).toBuffer(function(err, data, info) { + it('Read from Stream and write to Buffer', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const pipeline = sharp().resize(320, 240).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -78,23 +77,23 @@ describe('Input/output', function() { readable.pipe(pipeline); }); - it('Read from Stream and write to Buffer via Promise', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var pipeline = sharp().resize(1, 1); - pipeline.toBuffer().then(function(data) { + it('Read from Stream and write to Buffer via Promise', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const pipeline = sharp().resize(1, 1); + pipeline.toBuffer().then(function (data) { assert.strictEqual(true, data.length > 0); done(); - }).catch(function(err) { + }).catch(function (err) { throw err; }); readable.pipe(pipeline); }); - it('Read from Stream and write to Stream', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var writable = fs.createWriteStream(fixtures.outputJpg); - writable.on('finish', function() { - sharp(fixtures.outputJpg).toBuffer(function(err, data, info) { + it('Read from Stream and write to Stream', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const writable = fs.createWriteStream(fixtures.outputJpg); + writable.on('finish', function () { + sharp(fixtures.outputJpg).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -105,23 +104,23 @@ describe('Input/output', function() { done(); }); }); - var pipeline = sharp().resize(320, 240); + const pipeline = sharp().resize(320, 240); readable.pipe(pipeline).pipe(writable); }); - it('Stream should emit info event', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var writable = fs.createWriteStream(fixtures.outputJpg); - var pipeline = sharp().resize(320, 240); - var infoEventEmitted = false; - pipeline.on('info', function(info) { + it('Stream should emit info event', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const writable = fs.createWriteStream(fixtures.outputJpg); + const pipeline = sharp().resize(320, 240); + let infoEventEmitted = false; + pipeline.on('info', function (info) { assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); assert.strictEqual(3, info.channels); infoEventEmitted = true; }); - writable.on('finish', function() { + writable.on('finish', function () { assert.strictEqual(true, infoEventEmitted); fs.unlinkSync(fixtures.outputJpg); done(); @@ -129,41 +128,41 @@ describe('Input/output', function() { readable.pipe(pipeline).pipe(writable); }); - it('Handle Stream to Stream error ', function(done) { - var pipeline = sharp().resize(320, 240); - var anErrorWasEmitted = false; - pipeline.on('error', function(err) { + it('Handle Stream to Stream error ', function (done) { + const pipeline = sharp().resize(320, 240); + let anErrorWasEmitted = false; + pipeline.on('error', function (err) { anErrorWasEmitted = !!err; - }).on('end', function() { + }).on('end', function () { assert(anErrorWasEmitted); fs.unlinkSync(fixtures.outputJpg); done(); }); - var readableButNotAnImage = fs.createReadStream(__filename); - var writable = fs.createWriteStream(fixtures.outputJpg); + const readableButNotAnImage = fs.createReadStream(__filename); + const writable = fs.createWriteStream(fixtures.outputJpg); readableButNotAnImage.pipe(pipeline).pipe(writable); }); - it('Handle File to Stream error', function(done) { - var readableButNotAnImage = sharp(__filename).resize(320, 240); - var anErrorWasEmitted = false; - readableButNotAnImage.on('error', function(err) { + it('Handle File to Stream error', function (done) { + const readableButNotAnImage = sharp(__filename).resize(320, 240); + let anErrorWasEmitted = false; + readableButNotAnImage.on('error', function (err) { anErrorWasEmitted = !!err; - }).on('end', function() { + }).on('end', function () { assert(anErrorWasEmitted); fs.unlinkSync(fixtures.outputJpg); done(); }); - var writable = fs.createWriteStream(fixtures.outputJpg); + const writable = fs.createWriteStream(fixtures.outputJpg); readableButNotAnImage.pipe(writable); }); - it('Sequential read, force JPEG', function(done) { + it('Sequential read, force JPEG', function (done) { sharp(fixtures.inputJpg) .sequentialRead() .resize(320, 240) .toFormat(sharp.format.jpeg) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -174,12 +173,12 @@ describe('Input/output', function() { }); }); - it('Not sequential read, force JPEG', function(done) { + it('Not sequential read, force JPEG', function (done) { sharp(fixtures.inputJpg) .sequentialRead(false) .resize(320, 240) .toFormat('jpeg') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -190,41 +189,41 @@ describe('Input/output', function() { }); }); - it('Fail when output File is input File', function(done) { - sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, function(err) { + it('Fail when output File is input File', function (done) { + sharp(fixtures.inputJpg).toFile(fixtures.inputJpg, function (err) { assert(!!err); done(); }); }); - it('Fail when output File is input File via Promise', function(done) { - sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function(data) { + it('Fail when output File is input File via Promise', function (done) { + sharp(fixtures.inputJpg).toFile(fixtures.inputJpg).then(function (data) { assert(false); done(); - }).catch(function(err) { + }).catch(function (err) { assert(!!err); done(); }); }); - it('Fail when output File is empty', function(done) { - sharp(fixtures.inputJpg).toFile('', function(err) { + it('Fail when output File is empty', function (done) { + sharp(fixtures.inputJpg).toFile('', function (err) { assert(!!err); done(); }); }); - it('Fail when output File is empty via Promise', function(done) { - sharp(fixtures.inputJpg).toFile('').then(function(data) { + it('Fail when output File is empty via Promise', function (done) { + sharp(fixtures.inputJpg).toFile('').then(function (data) { assert(false); done(); - }).catch(function(err) { + }).catch(function (err) { assert(!!err); done(); }); }); - it('Fail when input is empty Buffer', function(done) { + it('Fail when input is empty Buffer', function (done) { sharp(new Buffer(0)).toBuffer().then(function () { assert(false); done(); @@ -234,7 +233,7 @@ describe('Input/output', function() { }); }); - it('Fail when input is invalid Buffer', function(done) { + it('Fail when input is invalid Buffer', function (done) { sharp(new Buffer([0x1, 0x2, 0x3, 0x4])).toBuffer().then(function () { assert(false); done(); @@ -244,32 +243,32 @@ describe('Input/output', function() { }); }); - describe('Fail for unsupported input', function() { - it('Numeric', function() { - assert.throws(function() { + describe('Fail for unsupported input', function () { + it('Numeric', function () { + assert.throws(function () { sharp(1); }); }); - it('Boolean', function() { - assert.throws(function() { + it('Boolean', function () { + assert.throws(function () { sharp(true); }); }); - it('Empty Object', function() { - assert.throws(function() { + it('Empty Object', function () { + assert.throws(function () { sharp({}); }); }); - it('Error Object', function() { - assert.throws(function() { + it('Error Object', function () { + assert.throws(function () { sharp(new Error()); }); }); }); - it('Promises/A+', function(done) { - sharp(fixtures.inputJpg).resize(320, 240).toBuffer().then(function(data) { - sharp(data).toBuffer(function(err, data, info) { + it('Promises/A+', function (done) { + sharp(fixtures.inputJpg).resize(320, 240).toBuffer().then(function (data) { + sharp(data).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -278,17 +277,17 @@ describe('Input/output', function() { assert.strictEqual(240, info.height); done(); }); - }).catch(function(err) { + }).catch(function (err) { throw err; }); }); - it('JPEG quality', function(done) { - sharp(fixtures.inputJpg).resize(320, 240).quality(70).toBuffer(function(err, buffer70) { + it('JPEG quality', function (done) { + sharp(fixtures.inputJpg).resize(320, 240).quality(70).toBuffer(function (err, buffer70) { if (err) throw err; - sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function(err, buffer80) { + sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, buffer80) { if (err) throw err; - sharp(fixtures.inputJpg).resize(320, 240).quality(90).toBuffer(function(err, buffer90) { + sharp(fixtures.inputJpg).resize(320, 240).quality(90).toBuffer(function (err, buffer90) { if (err) throw err; assert(buffer70.length < buffer80.length); assert(buffer80.length < buffer90.length); @@ -298,29 +297,29 @@ describe('Input/output', function() { }); }); - describe('Invalid quality', function() { - it('Negative integer', function() { - assert.throws(function() { + describe('Invalid quality', function () { + it('Negative integer', function () { + assert.throws(function () { sharp(fixtures.inputJpg).quality(-1); }); }); - it('Non integral', function() { - assert.throws(function() { + it('Non integral', function () { + assert.throws(function () { sharp(fixtures.inputJpg).quality(88.2); }); }); - it('String', function() { - assert.throws(function() { + it('String', function () { + assert.throws(function () { sharp(fixtures.inputJpg).quality('test'); }); }); }); - it('Progressive JPEG image', function(done) { + it('Progressive JPEG image', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .progressive(false) - .toBuffer(function(err, nonProgressiveData, nonProgressiveInfo) { + .toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) { if (err) throw err; assert.strictEqual(true, nonProgressiveData.length > 0); assert.strictEqual(nonProgressiveData.length, nonProgressiveInfo.size); @@ -330,7 +329,7 @@ describe('Input/output', function() { sharp(fixtures.inputJpg) .resize(320, 240) .progressive() - .toBuffer(function(err, progressiveData, progressiveInfo) { + .toBuffer(function (err, progressiveData, progressiveInfo) { if (err) throw err; assert.strictEqual(true, progressiveData.length > 0); assert.strictEqual(progressiveData.length, progressiveInfo.size); @@ -343,12 +342,12 @@ describe('Input/output', function() { }); }); - it('Progressive PNG image', function(done) { + it('Progressive PNG image', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .png() .progressive(false) - .toBuffer(function(err, nonProgressiveData, nonProgressiveInfo) { + .toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) { if (err) throw err; assert.strictEqual(true, nonProgressiveData.length > 0); assert.strictEqual(nonProgressiveData.length, nonProgressiveInfo.size); @@ -357,7 +356,7 @@ describe('Input/output', function() { assert.strictEqual(240, nonProgressiveInfo.height); sharp(nonProgressiveData) .progressive() - .toBuffer(function(err, progressiveData, progressiveInfo) { + .toBuffer(function (err, progressiveData, progressiveInfo) { if (err) throw err; assert.strictEqual(true, progressiveData.length > 0); assert.strictEqual(progressiveData.length, progressiveInfo.size); @@ -371,11 +370,11 @@ describe('Input/output', function() { }); if (sharp.format.webp.output.buffer) { - it('WebP output', function(done) { + it('WebP output', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .toFormat(sharp.format.webp) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('webp', info.format); @@ -386,8 +385,8 @@ describe('Input/output', function() { }); } - it('Invalid output format', function(done) { - var isValid = false; + it('Invalid output format', function (done) { + let isValid = false; try { sharp().toFormat('zoinks'); isValid = true; @@ -396,28 +395,27 @@ describe('Input/output', function() { done(); }); - it('File input with corrupt header fails gracefully', function(done) { + it('File input with corrupt header fails gracefully', function (done) { sharp(fixtures.inputJpgWithCorruptHeader) - .toBuffer(function(err) { + .toBuffer(function (err) { assert.strictEqual(true, !!err); done(); }); }); - it('Buffer input with corrupt header fails gracefully', function(done) { + it('Buffer input with corrupt header fails gracefully', function (done) { sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader)) - .toBuffer(function(err) { + .toBuffer(function (err) { assert.strictEqual(true, !!err); done(); }); }); - describe('Output filename with unknown extension', function() { - - it('Match JPEG input', function(done) { + describe('Output filename with unknown extension', function () { + it('Match JPEG input', function (done) { sharp(fixtures.inputJpg) .resize(320, 80) - .toFile(fixtures.outputZoinks, function(err, info) { + .toFile(fixtures.outputZoinks, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('jpeg', info.format); @@ -428,10 +426,10 @@ describe('Input/output', function() { }); }); - it('Match PNG input', function(done) { + it('Match PNG input', function (done) { sharp(fixtures.inputPng) .resize(320, 80) - .toFile(fixtures.outputZoinks, function(err, info) { + .toFile(fixtures.outputZoinks, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('png', info.format); @@ -443,10 +441,10 @@ describe('Input/output', function() { }); if (sharp.format.webp.input.file) { - it('Match WebP input', function(done) { + it('Match WebP input', function (done) { sharp(fixtures.inputWebP) .resize(320, 80) - .toFile(fixtures.outputZoinks, function(err, info) { + .toFile(fixtures.outputZoinks, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('webp', info.format); @@ -459,10 +457,10 @@ describe('Input/output', function() { } if (sharp.format.tiff.input.file) { - it('Match TIFF input', function(done) { + it('Match TIFF input', function (done) { sharp(fixtures.inputTiff) .resize(320, 80) - .toFile(fixtures.outputZoinks, function(err, info) { + .toFile(fixtures.outputZoinks, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('tiff', info.format); @@ -474,20 +472,20 @@ describe('Input/output', function() { }); } - it('Match GIF input, therefore fail', function(done) { + it('Match GIF input, therefore fail', function (done) { sharp(fixtures.inputGif) .resize(320, 80) - .toFile(fixtures.outputZoinks, function(err) { + .toFile(fixtures.outputZoinks, function (err) { assert(!!err); done(); }); }); - it('Force JPEG format for PNG input', function(done) { + it('Force JPEG format for PNG input', function (done) { sharp(fixtures.inputPng) .resize(320, 80) .jpeg() - .toFile(fixtures.outputZoinks, function(err, info) { + .toFile(fixtures.outputZoinks, function (err, info) { if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('jpeg', info.format); @@ -499,10 +497,9 @@ describe('Input/output', function() { }); }); - describe('PNG output', function() { - - it('compression level is valid', function(done) { - var isValid = false; + describe('PNG output', function () { + it('compression level is valid', function (done) { + let isValid = false; try { sharp().compressionLevel(0); isValid = true; @@ -511,8 +508,8 @@ describe('Input/output', function() { done(); }); - it('compression level is invalid', function(done) { - var isValid = false; + it('compression level is invalid', function (done) { + let isValid = false; try { sharp().compressionLevel(-1); isValid = true; @@ -521,12 +518,12 @@ describe('Input/output', function() { done(); }); - it('withoutAdaptiveFiltering generates smaller file', function(done) { + it('withoutAdaptiveFiltering generates smaller file', function (done) { // First generate with adaptive filtering sharp(fixtures.inputPng) .resize(320, 240) .withoutAdaptiveFiltering(false) - .toBuffer(function(err, adaptiveData, adaptiveInfo) { + .toBuffer(function (err, adaptiveData, adaptiveInfo) { if (err) throw err; assert.strictEqual(true, adaptiveData.length > 0); assert.strictEqual(adaptiveData.length, adaptiveInfo.size); @@ -537,7 +534,7 @@ describe('Input/output', function() { sharp(fixtures.inputPng) .resize(320, 240) .withoutAdaptiveFiltering() - .toBuffer(function(err, withoutAdaptiveData, withoutAdaptiveInfo) { + .toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) { if (err) throw err; assert.strictEqual(true, withoutAdaptiveData.length > 0); assert.strictEqual(withoutAdaptiveData.length, withoutAdaptiveInfo.size); @@ -551,12 +548,12 @@ describe('Input/output', function() { }); }); - it('Without chroma subsampling generates larger file', function(done) { + it('Without chroma subsampling generates larger file', function (done) { // First generate with chroma subsampling (default) sharp(fixtures.inputJpg) .resize(320, 240) .withoutChromaSubsampling(false) - .toBuffer(function(err, withChromaSubsamplingData, withChromaSubsamplingInfo) { + .toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) { if (err) throw err; assert.strictEqual(true, withChromaSubsamplingData.length > 0); assert.strictEqual(withChromaSubsamplingData.length, withChromaSubsamplingInfo.size); @@ -567,7 +564,7 @@ describe('Input/output', function() { sharp(fixtures.inputJpg) .resize(320, 240) .withoutChromaSubsampling() - .toBuffer(function(err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) { + .toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) { if (err) throw err; assert.strictEqual(true, withoutChromaSubsamplingData.length > 0); assert.strictEqual(withoutChromaSubsamplingData.length, withoutChromaSubsamplingInfo.size); @@ -580,12 +577,12 @@ describe('Input/output', function() { }); }); - it('Trellis quantisation', function(done) { + it('Trellis quantisation', function (done) { // First generate without sharp(fixtures.inputJpg) .resize(320, 240) .trellisQuantisation(false) - .toBuffer(function(err, withoutData, withoutInfo) { + .toBuffer(function (err, withoutData, withoutInfo) { if (err) throw err; assert.strictEqual(true, withoutData.length > 0); assert.strictEqual(withoutData.length, withoutInfo.size); @@ -596,7 +593,7 @@ describe('Input/output', function() { sharp(fixtures.inputJpg) .resize(320, 240) .trellisQuantization() - .toBuffer(function(err, withData, withInfo) { + .toBuffer(function (err, withData, withInfo) { if (err) throw err; assert.strictEqual(true, withData.length > 0); assert.strictEqual(withData.length, withInfo.size); @@ -610,12 +607,12 @@ describe('Input/output', function() { }); }); - it('Overshoot deringing', function(done) { + it('Overshoot deringing', function (done) { // First generate without sharp(fixtures.inputJpg) .resize(320, 240) .overshootDeringing(false) - .toBuffer(function(err, withoutData, withoutInfo) { + .toBuffer(function (err, withoutData, withoutInfo) { if (err) throw err; assert.strictEqual(true, withoutData.length > 0); assert.strictEqual(withoutData.length, withoutInfo.size); @@ -626,7 +623,7 @@ describe('Input/output', function() { sharp(fixtures.inputJpg) .resize(320, 240) .overshootDeringing() - .toBuffer(function(err, withData, withInfo) { + .toBuffer(function (err, withData, withInfo) { if (err) throw err; assert.strictEqual(true, withData.length > 0); assert.strictEqual(withData.length, withInfo.size); @@ -638,12 +635,12 @@ describe('Input/output', function() { }); }); - it('Optimise scans', function(done) { + it('Optimise scans', function (done) { // First generate without sharp(fixtures.inputJpg) .resize(320, 240) .optimiseScans(false) - .toBuffer(function(err, withoutData, withoutInfo) { + .toBuffer(function (err, withoutData, withoutInfo) { if (err) throw err; assert.strictEqual(true, withoutData.length > 0); assert.strictEqual(withoutData.length, withoutInfo.size); @@ -654,7 +651,7 @@ describe('Input/output', function() { sharp(fixtures.inputJpg) .resize(320, 240) .optimizeScans() - .toBuffer(function(err, withData, withInfo) { + .toBuffer(function (err, withData, withInfo) { if (err) throw err; assert.strictEqual(true, withData.length > 0); assert.strictEqual(withData.length, withInfo.size); @@ -662,25 +659,25 @@ describe('Input/output', function() { assert.strictEqual(320, withInfo.width); assert.strictEqual(240, withInfo.height); // Verify image is of a different size (progressive output even without mozjpeg) - assert.strictEqual(true, withData.length != withoutData.length); + assert.notEqual(withData.length, withoutData.length); done(); }); }); }); - it('Convert SVG to PNG at default 72DPI', function(done) { + it('Convert SVG to PNG at default 72DPI', function (done) { sharp(fixtures.inputSvg) .resize(1024) .extract({left: 290, top: 760, width: 40, height: 40}) .toFormat('png') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(40, info.width); assert.strictEqual(40, info.height); - fixtures.assertSimilar(fixtures.expected('svg72.png'), data, function(err) { + fixtures.assertSimilar(fixtures.expected('svg72.png'), data, function (err) { if (err) throw err; - sharp(data).metadata(function(err, info) { + sharp(data).metadata(function (err, info) { if (err) throw err; assert.strictEqual(72, info.density); done(); @@ -689,19 +686,19 @@ describe('Input/output', function() { }); }); - it('Convert SVG to PNG at 300DPI', function(done) { + it('Convert SVG to PNG at 300DPI', function (done) { sharp(fixtures.inputSvg, { density: 1200 }) .resize(1024) .extract({left: 290, top: 760, width: 40, height: 40}) .toFormat('png') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(40, info.width); assert.strictEqual(40, info.height); - fixtures.assertSimilar(fixtures.expected('svg1200.png'), data, function(err) { + fixtures.assertSimilar(fixtures.expected('svg1200.png'), data, function (err) { if (err) throw err; - sharp(data).metadata(function(err, info) { + sharp(data).metadata(function (err, info) { if (err) throw err; assert.strictEqual(1200, info.density); done(); @@ -710,10 +707,10 @@ describe('Input/output', function() { }); }); - it('Convert SVG with embedded images to PNG, respecting dimensions', function(done) { + it('Convert SVG with embedded images to PNG, respecting dimensions', function (done) { sharp(fixtures.inputSvgWithEmbeddedImages) .png() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(480, info.width); @@ -724,12 +721,12 @@ describe('Input/output', function() { }); if (sharp.format.tiff.input.buffer) { - it('Load TIFF from Buffer', function(done) { - var inputTiffBuffer = fs.readFileSync(fixtures.inputTiff); + it('Load TIFF from Buffer', function (done) { + const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff); sharp(inputTiffBuffer) .resize(320, 240) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -742,12 +739,12 @@ describe('Input/output', function() { } if (sharp.format.gif.input.buffer) { - it('Load GIF from Buffer', function(done) { - var inputGifBuffer = fs.readFileSync(fixtures.inputGif); + it('Load GIF from Buffer', function (done) { + const inputGifBuffer = fs.readFileSync(fixtures.inputGif); sharp(inputGifBuffer) .resize(320, 240) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -760,11 +757,11 @@ describe('Input/output', function() { } if (sharp.format.gif.input.file) { - it('Load GIF grey+alpha from file', function(done) { + it('Load GIF grey+alpha from file', function (done) { sharp(fixtures.inputGifGreyPlusAlpha) .resize(8, 4) .png() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(data.length, info.size); @@ -778,10 +775,10 @@ describe('Input/output', function() { } if (sharp.format.v.input.file) { - it("Load Vips V file", function(done) { + it('Load Vips V file', function (done) { sharp(fixtures.inputV) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -793,11 +790,11 @@ describe('Input/output', function() { } if (sharp.format.v.output.file) { - it("Save Vips V file", function(done) { + it('Save Vips V file', function (done) { sharp(fixtures.inputJpg) .extract({left: 910, top: 1105, width: 70, height: 60}) - .toFile(fixtures.outputV, function(err, info) { - if(err) throw err; + .toFile(fixtures.outputV, function (err, info) { + if (err) throw err; assert.strictEqual(true, info.size > 0); assert.strictEqual('v', info.format); assert.strictEqual(70, info.width); @@ -807,15 +804,16 @@ describe('Input/output', function() { }); }); } - + if (sharp.format.raw.output.buffer) { - describe('Ouput raw, uncompressed image data', function() { - it('1 channel greyscale image', function(done) { + describe('Ouput raw, uncompressed image data', function () { + it('1 channel greyscale image', function (done) { sharp(fixtures.inputJpg) .greyscale() .resize(32, 24) .raw() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual(32 * 24 * 1, info.size); assert.strictEqual(data.length, info.size); assert.strictEqual('raw', info.format); @@ -824,11 +822,12 @@ describe('Input/output', function() { done(); }); }); - it('3 channel colour image without transparency', function(done) { + it('3 channel colour image without transparency', function (done) { sharp(fixtures.inputJpg) .resize(32, 24) .toFormat('raw') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual(32 * 24 * 3, info.size); assert.strictEqual(data.length, info.size); assert.strictEqual('raw', info.format); @@ -837,11 +836,12 @@ describe('Input/output', function() { done(); }); }); - it('4 channel colour image with transparency', function(done) { + it('4 channel colour image with transparency', function (done) { sharp(fixtures.inputPngWithTransparency) .resize(32, 24) .toFormat(sharp.format.raw) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual(32 * 24 * 4, info.size); assert.strictEqual(data.length, info.size); assert.strictEqual('raw', info.format); @@ -853,10 +853,9 @@ describe('Input/output', function() { }); } - describe('Limit pixel count of input image', function() { - - it('Invalid fails - negative', function(done) { - var isValid = false; + describe('Limit pixel count of input image', function () { + it('Invalid fails - negative', function (done) { + let isValid = false; try { sharp().limitInputPixels(-1); isValid = true; @@ -865,8 +864,8 @@ describe('Input/output', function() { done(); }); - it('Invalid fails - float', function(done) { - var isValid = false; + it('Invalid fails - float', function (done) { + let isValid = false; try { sharp().limitInputPixels(12.3); isValid = true; @@ -875,8 +874,8 @@ describe('Input/output', function() { done(); }); - it('Invalid fails - string', function(done) { - var isValid = false; + it('Invalid fails - string', function (done) { + let isValid = false; try { sharp().limitInputPixels('fail'); isValid = true; @@ -885,104 +884,103 @@ describe('Input/output', function() { done(); }); - it('Same size as input works', function(done) { - sharp(fixtures.inputJpg).metadata(function(err, metadata) { + it('Same size as input works', function (done) { + sharp(fixtures.inputJpg).metadata(function (err, metadata) { if (err) throw err; sharp(fixtures.inputJpg) .limitInputPixels(metadata.width * metadata.height) - .toBuffer(function(err) { + .toBuffer(function (err) { assert.strictEqual(true, !err); done(); }); }); }); - it('Disabling limit works', function(done) { + it('Disabling limit works', function (done) { sharp(fixtures.inputJpgLarge) .limitInputPixels(false) .resize(2) - .toBuffer(function(err) { + .toBuffer(function (err) { assert.strictEqual(true, !err); done(); }); }); - it('Enabling default limit works and fails with a large image', function(done) { + it('Enabling default limit works and fails with a large image', function (done) { sharp(fixtures.inputJpgLarge) .limitInputPixels(true) - .toBuffer(function(err) { + .toBuffer(function (err) { assert.strictEqual(true, !!err); done(); }); }); - it('Smaller than input fails', function(done) { - sharp(fixtures.inputJpg).metadata(function(err, metadata) { + it('Smaller than input fails', function (done) { + sharp(fixtures.inputJpg).metadata(function (err, metadata) { if (err) throw err; sharp(fixtures.inputJpg) .limitInputPixels(metadata.width * metadata.height - 1) - .toBuffer(function(err) { + .toBuffer(function (err) { assert.strictEqual(true, !!err); done(); }); }); }); - }); - describe('Input options', function() { - it('Non-Object options fails', function() { - assert.throws(function() { + describe('Input options', function () { + it('Non-Object options fails', function () { + assert.throws(function () { sharp(null, 'zoinks'); }); }); - it('Invalid density: string', function() { - assert.throws(function() { - sharp(null, { density: 'zoinks' } ); + it('Invalid density: string', function () { + assert.throws(function () { + sharp(null, { density: 'zoinks' }); }); }); - it('Invalid density: float', function() { - assert.throws(function() { - sharp(null, { density: 0.5 } ); + it('Invalid density: float', function () { + assert.throws(function () { + sharp(null, { density: 0.5 }); }); }); - it('Ignore unknown attribute', function() { - sharp(null, { unknown: true } ); + it('Ignore unknown attribute', function () { + sharp(null, { unknown: true }); }); }); - describe('Raw pixel input', function() { - it('Missing options', function() { - assert.throws(function() { - sharp(null, { raw: {} } ); + describe('Raw pixel input', function () { + it('Missing options', function () { + assert.throws(function () { + sharp(null, { raw: {} }); }); }); - it('Incomplete options', function() { - assert.throws(function() { - sharp(null, { raw: { width: 1, height: 1} } ); + it('Incomplete options', function () { + assert.throws(function () { + sharp(null, { raw: { width: 1, height: 1 } }); }); }); - it('Invalid channels', function() { - assert.throws(function() { - sharp(null, { raw: { width: 1, height: 1, channels: 5} } ); + it('Invalid channels', function () { + assert.throws(function () { + sharp(null, { raw: { width: 1, height: 1, channels: 5 } }); }); }); - it('Invalid height', function() { - assert.throws(function() { - sharp(null, { raw: { width: 1, height: 0, channels: 4} } ); + it('Invalid height', function () { + assert.throws(function () { + sharp(null, { raw: { width: 1, height: 0, channels: 4 } }); }); }); - it('Invalid width', function() { - assert.throws(function() { - sharp(null, { raw: { width: 'zoinks', height: 1, channels: 4} } ); + it('Invalid width', function () { + assert.throws(function () { + sharp(null, { raw: { width: 'zoinks', height: 1, channels: 4 } }); }); }); - it('RGB', function(done) { + it('RGB', function (done) { // Convert to raw pixel data sharp(fixtures.inputJpg) .resize(256) .raw() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(256, info.width); assert.strictEqual(209, info.height); @@ -995,7 +993,7 @@ describe('Input/output', function() { channels: info.channels }}) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(256, info.width); assert.strictEqual(209, info.height); @@ -1004,12 +1002,12 @@ describe('Input/output', function() { }); }); }); - it('RGBA', function(done) { + it('RGBA', function (done) { // Convert to raw pixel data sharp(fixtures.inputPngOverlayLayer1) .resize(256) .raw() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(256, info.width); assert.strictEqual(192, info.height); @@ -1022,7 +1020,7 @@ describe('Input/output', function() { channels: info.channels }}) .png() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(256, info.width); assert.strictEqual(192, info.height); @@ -1033,17 +1031,17 @@ describe('Input/output', function() { }); }); - it('Queue length change events', function(done) { - var eventCounter = 0; - var queueListener = function(queueLength) { + it('Queue length change events', function (done) { + let eventCounter = 0; + const queueListener = function (queueLength) { assert.strictEqual(true, queueLength === 0 || queueLength === 1); eventCounter++; }; sharp.queue.on('change', queueListener); sharp(fixtures.inputJpg) .resize(320, 240) - .toBuffer(function(err) { - process.nextTick(function() { + .toBuffer(function (err) { + process.nextTick(function () { sharp.queue.removeListener('change', queueListener); if (err) throw err; assert.strictEqual(2, eventCounter); @@ -1052,31 +1050,27 @@ describe('Input/output', function() { }); }); - it('Info event data', function(done) { - var readable = fs.createReadStream(fixtures.inputJPGBig); - var inPipeline = sharp() + it('Info event data', function (done) { + const readable = fs.createReadStream(fixtures.inputJPGBig); + const inPipeline = sharp() .resize(840, 472) .raw() - .on('info', function(info) { + .on('info', function (info) { assert.strictEqual(840, info.width); assert.strictEqual(472, info.height); assert.strictEqual(3, info.channels); }); - var badPipeline = sharp(null, {raw: {width: 840, height: 500, channels: 3}}) + const badPipeline = sharp(null, {raw: {width: 840, height: 500, channels: 3}}) .toFormat('jpeg') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { assert.strictEqual(err.message.indexOf('memory area too small') > 0, true); - readable = fs.createReadStream(fixtures.inputJPGBig); - var goodPipeline = sharp(null, {raw: {width: 840, height: 472, channels: 3}}) + const goodPipeline = sharp(null, {raw: {width: 840, height: 472, channels: 3}}) .toFormat('jpeg') - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; done(); }); - inPipeline = sharp() - .resize(840, 472) - .raw(); - readable.pipe(inPipeline).pipe(goodPipeline); + readable.pipe(inPipeline).pipe(goodPipeline); }); readable.pipe(inPipeline).pipe(badPipeline); }); diff --git a/test/unit/metadata.js b/test/unit/metadata.js index 8a9e975c..c397ee1d 100644 --- a/test/unit/metadata.js +++ b/test/unit/metadata.js @@ -1,17 +1,16 @@ 'use strict'; -var fs = require('fs'); -var assert = require('assert'); -var exifReader = require('exif-reader'); -var icc = require('icc'); +const fs = require('fs'); +const assert = require('assert'); +const exifReader = require('exif-reader'); +const icc = require('icc'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Image metadata', function() { - - it('JPEG', function(done) { - sharp(fixtures.inputJpg).metadata(function(err, metadata) { +describe('Image metadata', function () { + it('JPEG', function (done) { + sharp(fixtures.inputJpg).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('jpeg', metadata.format); assert.strictEqual(2725, metadata.width); @@ -28,8 +27,8 @@ describe('Image metadata', function() { }); }); - it('JPEG with EXIF/ICC', function(done) { - sharp(fixtures.inputJpgWithExif).metadata(function(err, metadata) { + it('JPEG with EXIF/ICC', function (done) { + sharp(fixtures.inputJpgWithExif).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('jpeg', metadata.format); assert.strictEqual(450, metadata.width); @@ -43,14 +42,14 @@ describe('Image metadata', function() { // EXIF assert.strictEqual('object', typeof metadata.exif); assert.strictEqual(true, metadata.exif instanceof Buffer); - var exif = exifReader(metadata.exif); + const exif = exifReader(metadata.exif); assert.strictEqual('object', typeof exif); assert.strictEqual('object', typeof exif.image); assert.strictEqual('number', typeof exif.image.XResolution); // ICC assert.strictEqual('object', typeof metadata.icc); assert.strictEqual(true, metadata.icc instanceof Buffer); - var profile = icc.parse(metadata.icc); + const profile = icc.parse(metadata.icc); assert.strictEqual('object', typeof profile); assert.strictEqual('Generic RGB Profile', profile.description); done(); @@ -58,8 +57,8 @@ describe('Image metadata', function() { }); if (sharp.format.tiff.input.file) { - it('TIFF', function(done) { - sharp(fixtures.inputTiff).metadata(function(err, metadata) { + it('TIFF', function (done) { + sharp(fixtures.inputTiff).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('tiff', metadata.format); assert.strictEqual(2464, metadata.width); @@ -77,8 +76,8 @@ describe('Image metadata', function() { }); } - it('PNG', function(done) { - sharp(fixtures.inputPng).metadata(function(err, metadata) { + it('PNG', function (done) { + sharp(fixtures.inputPng).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('png', metadata.format); assert.strictEqual(2809, metadata.width); @@ -95,8 +94,8 @@ describe('Image metadata', function() { }); }); - it('Transparent PNG', function(done) { - sharp(fixtures.inputPngWithTransparency).metadata(function(err, metadata) { + it('Transparent PNG', function (done) { + sharp(fixtures.inputPngWithTransparency).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('png', metadata.format); assert.strictEqual(2048, metadata.width); @@ -114,8 +113,8 @@ describe('Image metadata', function() { }); if (sharp.format.webp.input.file) { - it('WebP', function(done) { - sharp(fixtures.inputWebP).metadata(function(err, metadata) { + it('WebP', function (done) { + sharp(fixtures.inputWebP).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('webp', metadata.format); assert.strictEqual(1024, metadata.width); @@ -134,8 +133,8 @@ describe('Image metadata', function() { } if (sharp.format.gif.input.file) { - it('GIF via giflib', function(done) { - sharp(fixtures.inputGif).metadata(function(err, metadata) { + it('GIF via giflib', function (done) { + sharp(fixtures.inputGif).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('gif', metadata.format); assert.strictEqual(800, metadata.width); @@ -150,8 +149,8 @@ describe('Image metadata', function() { done(); }); }); - it('GIF grey+alpha via giflib', function(done) { - sharp(fixtures.inputGifGreyPlusAlpha).metadata(function(err, metadata) { + it('GIF grey+alpha via giflib', function (done) { + sharp(fixtures.inputGifGreyPlusAlpha).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('gif', metadata.format); assert.strictEqual(2, metadata.width); @@ -169,8 +168,8 @@ describe('Image metadata', function() { } if (sharp.format.openslide.input.file) { - it('Aperio SVS via openslide', function(done) { - sharp(fixtures.inputSvs).metadata(function(err, metadata) { + it('Aperio SVS via openslide', function (done) { + sharp(fixtures.inputSvs).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('openslide', metadata.format); assert.strictEqual(2220, metadata.width); @@ -188,8 +187,8 @@ describe('Image metadata', function() { }); } - it('File in, Promise out', function(done) { - sharp(fixtures.inputJpg).metadata().then(function(metadata) { + it('File in, Promise out', function (done) { + sharp(fixtures.inputJpg).metadata().then(function (metadata) { assert.strictEqual('jpeg', metadata.format); assert.strictEqual(2725, metadata.width); assert.strictEqual(2225, metadata.height); @@ -205,8 +204,8 @@ describe('Image metadata', function() { }); }); - it('Non-existent file in, Promise out', function(done) { - sharp('fail').metadata().then(function(metadata) { + it('Non-existent file in, Promise out', function (done) { + sharp('fail').metadata().then(function (metadata) { throw new Error('Non-existent file'); }, function (err) { assert.ok(!!err); @@ -214,10 +213,10 @@ describe('Image metadata', function() { }); }); - it('Stream in, Promise out', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var pipeline = sharp(); - pipeline.metadata().then(function(metadata) { + it('Stream in, Promise out', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const pipeline = sharp(); + pipeline.metadata().then(function (metadata) { assert.strictEqual('jpeg', metadata.format); assert.strictEqual(2725, metadata.width); assert.strictEqual(2225, metadata.height); @@ -230,15 +229,15 @@ describe('Image metadata', function() { assert.strictEqual('undefined', typeof metadata.exif); assert.strictEqual('undefined', typeof metadata.icc); done(); - }).catch(function(err) { + }).catch(function (err) { throw err; }); readable.pipe(pipeline); }); - it('Stream', function(done) { - var readable = fs.createReadStream(fixtures.inputJpg); - var pipeline = sharp().metadata(function(err, metadata) { + it('Stream', function (done) { + const readable = fs.createReadStream(fixtures.inputJpg); + const pipeline = sharp().metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('jpeg', metadata.format); assert.strictEqual(2725, metadata.width); @@ -256,9 +255,9 @@ describe('Image metadata', function() { readable.pipe(pipeline); }); - it('Resize to half width using metadata', function(done) { - var image = sharp(fixtures.inputJpg); - image.metadata(function(err, metadata) { + it('Resize to half width using metadata', function (done) { + const image = sharp(fixtures.inputJpg); + image.metadata(function (err, metadata) { if (err) throw err; assert.strictEqual('jpeg', metadata.format); assert.strictEqual(2725, metadata.width); @@ -271,7 +270,7 @@ describe('Image metadata', function() { assert.strictEqual('undefined', typeof metadata.orientation); assert.strictEqual('undefined', typeof metadata.exif); assert.strictEqual('undefined', typeof metadata.icc); - image.resize(Math.floor(metadata.width / 2)).toBuffer(function(err, data, info) { + image.resize(Math.floor(metadata.width / 2)).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual(1362, info.width); @@ -281,27 +280,27 @@ describe('Image metadata', function() { }); }); - it('Keep EXIF metadata and add sRGB profile after a resize', function(done) { + it('Keep EXIF metadata and add sRGB profile after a resize', function (done) { sharp(fixtures.inputJpgWithExif) .resize(320, 240) .withMetadata() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) throw err; - sharp(buffer).metadata(function(err, metadata) { + sharp(buffer).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual(true, metadata.hasProfile); assert.strictEqual(8, metadata.orientation); assert.strictEqual('object', typeof metadata.exif); assert.strictEqual(true, metadata.exif instanceof Buffer); // EXIF - var exif = exifReader(metadata.exif); + const exif = exifReader(metadata.exif); assert.strictEqual('object', typeof exif); assert.strictEqual('object', typeof exif.image); assert.strictEqual('number', typeof exif.image.XResolution); // ICC assert.strictEqual('object', typeof metadata.icc); assert.strictEqual(true, metadata.icc instanceof Buffer); - var profile = icc.parse(metadata.icc); + const profile = icc.parse(metadata.icc); assert.strictEqual('object', typeof profile); assert.strictEqual('RGB', profile.colorSpace); assert.strictEqual('Perceptual', profile.intent); @@ -311,13 +310,13 @@ describe('Image metadata', function() { }); }); - it('Remove EXIF metadata after a resize', function(done) { + it('Remove EXIF metadata after a resize', function (done) { sharp(fixtures.inputJpgWithExif) .resize(320, 240) .withMetadata(false) - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) throw err; - sharp(buffer).metadata(function(err, metadata) { + sharp(buffer).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual(false, metadata.hasProfile); assert.strictEqual('undefined', typeof metadata.orientation); @@ -328,12 +327,12 @@ describe('Image metadata', function() { }); }); - it('Remove metadata from PNG output', function(done) { + it('Remove metadata from PNG output', function (done) { sharp(fixtures.inputJpgWithExif) .png() - .toBuffer(function(err, buffer) { + .toBuffer(function (err, buffer) { if (err) throw err; - sharp(buffer).metadata(function(err, metadata) { + sharp(buffer).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual(false, metadata.hasProfile); assert.strictEqual('undefined', typeof metadata.orientation); @@ -344,30 +343,30 @@ describe('Image metadata', function() { }); }); - it('File input with corrupt header fails gracefully', function(done) { + it('File input with corrupt header fails gracefully', function (done) { sharp(fixtures.inputJpgWithCorruptHeader) - .metadata(function(err) { + .metadata(function (err) { assert.strictEqual(true, !!err); done(); }); }); - it('Buffer input with corrupt header fails gracefully', function(done) { + it('Buffer input with corrupt header fails gracefully', function (done) { sharp(fs.readFileSync(fixtures.inputJpgWithCorruptHeader)) - .metadata(function(err) { + .metadata(function (err) { assert.strictEqual(true, !!err); done(); }); }); - describe('Invalid withMetadata parameters', function() { - it('String orientation', function() { - assert.throws(function() { + describe('Invalid withMetadata parameters', function () { + it('String orientation', function () { + assert.throws(function () { sharp().withMetadata({orientation: 'zoinks'}); }); }); - it('Negative orientation', function() { - assert.throws(function() { + it('Negative orientation', function () { + assert.throws(function () { sharp().withMetadata({orientation: -1}); }); }); @@ -376,8 +375,8 @@ describe('Image metadata', function() { sharp().withMetadata({ orientation: 0 }); }); }); - it('Too large orientation', function() { - assert.throws(function() { + it('Too large orientation', function () { + assert.throws(function () { sharp().withMetadata({orientation: 9}); }); }); diff --git a/test/unit/negate.js b/test/unit/negate.js index bffaca7d..3a273eaf 100644 --- a/test/unit/negate.js +++ b/test/unit/negate.js @@ -1,105 +1,110 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Negate', function() { - it('negate (jpeg)', function(done) { - sharp(fixtures.inputJpg) - .resize(320, 240) - .negate() - .toBuffer(function(err, data, info) { - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done); - }); - }); +describe('Negate', function () { + it('negate (jpeg)', function (done) { + sharp(fixtures.inputJpg) + .resize(320, 240) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done); + }); + }); - it('negate (png)', function(done) { - sharp(fixtures.inputPng) - .resize(320, 240) - .negate() - .toBuffer(function(err, data, info) { - assert.strictEqual('png', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate.png'), data, done); - }); - }); + it('negate (png)', function (done) { + sharp(fixtures.inputPng) + .resize(320, 240) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('png', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate.png'), data, done); + }); + }); - it('negate (png, trans)', function(done) { - sharp(fixtures.inputPngWithTransparency) - .resize(320, 240) - .negate() - .toBuffer(function(err, data, info) { - assert.strictEqual('png', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate-trans.png'), data, done); - }); - }); + it('negate (png, trans)', function (done) { + sharp(fixtures.inputPngWithTransparency) + .resize(320, 240) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('png', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate-trans.png'), data, done); + }); + }); - it('negate (png, alpha)', function(done) { - sharp(fixtures.inputPngWithGreyAlpha) - .resize(320, 240) - .negate() - .toBuffer(function(err, data, info) { - assert.strictEqual('png', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate-alpha.png'), data, done); - }); - }); + it('negate (png, alpha)', function (done) { + sharp(fixtures.inputPngWithGreyAlpha) + .resize(320, 240) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('png', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate-alpha.png'), data, done); + }); + }); - if (sharp.format.webp.output.file) { - it('negate (webp)', function(done) { - sharp(fixtures.inputWebP) - .resize(320, 240) - .negate() - .toBuffer(function(err, data, info) { - assert.strictEqual('webp', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate.webp'), data, done); - }); - }); + it('negate (webp)', function (done) { + sharp(fixtures.inputWebP) + .resize(320, 240) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('webp', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate.webp'), data, done); + }); + }); - it('negate (webp, trans)', function(done) { - sharp(fixtures.inputWebPWithTransparency) - .resize(320, 240) - .negate() - .toBuffer(function(err, data, info) { - assert.strictEqual('webp', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done); - }); - }); - } + it('negate (webp, trans)', function (done) { + sharp(fixtures.inputWebPWithTransparency) + .resize(320, 240) + .negate() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('webp', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate-trans.webp'), data, done); + }); + }); - it('negate (true)', function(done) { - sharp(fixtures.inputJpg) - .resize(320, 240) - .negate(true) - .toBuffer(function(err, data, info) { - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(240, info.height); - fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done); - }); - }); + it('negate (true)', function (done) { + sharp(fixtures.inputJpg) + .resize(320, 240) + .negate(true) + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(240, info.height); + fixtures.assertSimilar(fixtures.expected('negate.jpg'), data, done); + }); + }); - it('negate (false)', function(done) { - var output = fixtures.path('output.unmodified-by-negate.png'); - sharp(fixtures.inputJpgWithLowContrast) - .negate(false) - .toFile(output, function(err, info) { - if (err) done(err); - fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0); - done(); - }); - }); + it('negate (false)', function (done) { + const output = fixtures.path('output.unmodified-by-negate.png'); + sharp(fixtures.inputJpgWithLowContrast) + .negate(false) + .toFile(output, function (err, info) { + if (err) throw err; + fixtures.assertMaxColourDistance(output, fixtures.inputJpgWithLowContrast, 0); + done(); + }); + }); }); diff --git a/test/unit/normalize.js b/test/unit/normalize.js index 0539b78b..1957fc17 100644 --- a/test/unit/normalize.js +++ b/test/unit/normalize.js @@ -1,14 +1,14 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -var assertNormalized = function(data) { - var min = 255; - var max = 0; - for (var i = 0; i < data.length; i++) { +const assertNormalized = function (data) { + let min = 255; + let max = 0; + for (let i = 0; i < data.length; i++) { min = Math.min(min, data[i]); max = Math.max(max, data[i]); } @@ -17,12 +17,11 @@ var assertNormalized = function(data) { }; describe('Normalization', function () { - - it('uses the same prototype for both spellings', function() { + it('uses the same prototype for both spellings', function () { assert.strictEqual(sharp.prototype.normalize, sharp.prototype.normalise); }); - it('spreads rgb image values between 0 and 255', function(done) { + it('spreads rgb image values between 0 and 255', function (done) { sharp(fixtures.inputJpgWithLowContrast) .normalize() .raw() @@ -33,7 +32,7 @@ describe('Normalization', function () { }); }); - it('spreads grayscaled image values between 0 and 255', function(done) { + it('spreads grayscaled image values between 0 and 255', function (done) { sharp(fixtures.inputJpgWithLowContrast) .gamma() .greyscale() @@ -46,7 +45,7 @@ describe('Normalization', function () { }); }); - it('stretches greyscale images with alpha channel', function(done) { + it('stretches greyscale images with alpha channel', function (done) { sharp(fixtures.inputPngWithGreyAlpha) .normalize() .raw() @@ -57,12 +56,12 @@ describe('Normalization', function () { }); }); - it('keeps an existing alpha channel', function(done) { + it('keeps an existing alpha channel', function (done) { sharp(fixtures.inputPngWithTransparency) .normalize() .toBuffer(function (err, data) { if (err) throw err; - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { if (err) return done(err); assert.strictEqual(4, metadata.channels); assert.strictEqual(true, metadata.hasAlpha); @@ -72,12 +71,12 @@ describe('Normalization', function () { }); }); - it('keeps the alpha channel of greyscale images intact', function(done) { + it('keeps the alpha channel of greyscale images intact', function (done) { sharp(fixtures.inputPngWithGreyAlpha) .normalize() .toBuffer(function (err, data) { if (err) throw err; - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { if (err) return done(err); assert.strictEqual(true, metadata.hasAlpha); assert.strictEqual(4, metadata.channels); @@ -87,18 +86,18 @@ describe('Normalization', function () { }); }); - it('does not alter images with only one color', function(done) { - var output = fixtures.path('output.unmodified-png-with-one-color.png'); + it('does not alter images with only one color', function (done) { + const output = fixtures.path('output.unmodified-png-with-one-color.png'); sharp(fixtures.inputPngWithOneColor) .normalize() - .toFile(output, function(err, info) { + .toFile(output, function (err, info) { if (err) done(err); fixtures.assertMaxColourDistance(output, fixtures.inputPngWithOneColor, 0); done(); }); }); - it('works with 16-bit RGBA images', function(done) { + it('works with 16-bit RGBA images', function (done) { sharp(fixtures.inputPngWithTransparency16bit) .normalize() .raw() @@ -108,5 +107,4 @@ describe('Normalization', function () { done(); }); }); - }); diff --git a/test/unit/overlay.js b/test/unit/overlay.js index 40c37161..9d1a802e 100644 --- a/test/unit/overlay.js +++ b/test/unit/overlay.js @@ -1,25 +1,26 @@ 'use strict'; -var fs = require('fs'); -var assert = require('assert'); -var fixtures = require('../fixtures'); -var sharp = require('../../index'); +const fs = require('fs'); +const assert = require('assert'); + +const fixtures = require('../fixtures'); +const sharp = require('../../index'); // Helpers -var getPaths = function(baseName, extension) { +const getPaths = function (baseName, extension) { if (typeof extension === 'undefined') { extension = 'png'; } return { actual: fixtures.path('output.' + baseName + '.' + extension), - expected: fixtures.expected(baseName + '.' + extension), + expected: fixtures.expected(baseName + '.' + extension) }; }; // Test -describe('Overlays', function() { - it('Overlay transparent PNG file on solid background', function(done) { - var paths = getPaths('alpha-layer-01'); +describe('Overlays', function () { + it('Overlay transparent PNG file on solid background', function (done) { + const paths = getPaths('alpha-layer-01'); sharp(fixtures.inputPngOverlayLayer0) .overlayWith(fixtures.inputPngOverlayLayer1) @@ -30,8 +31,8 @@ describe('Overlays', function() { }); }); - it('Overlay transparent PNG Buffer on solid background', function(done) { - var paths = getPaths('alpha-layer-01'); + it('Overlay transparent PNG Buffer on solid background', function (done) { + const paths = getPaths('alpha-layer-01'); sharp(fixtures.inputPngOverlayLayer0) .overlayWith(fs.readFileSync(fixtures.inputPngOverlayLayer1)) @@ -42,8 +43,8 @@ describe('Overlays', function() { }); }); - it('Overlay low-alpha transparent PNG on solid background', function(done) { - var paths = getPaths('alpha-layer-01-low-alpha'); + it('Overlay low-alpha transparent PNG on solid background', function (done) { + const paths = getPaths('alpha-layer-01-low-alpha'); sharp(fixtures.inputPngOverlayLayer0) .overlayWith(fixtures.inputPngOverlayLayer1LowAlpha) @@ -54,8 +55,8 @@ describe('Overlays', function() { }); }); - it('Composite three transparent PNGs into one', function(done) { - var paths = getPaths('alpha-layer-012'); + it('Composite three transparent PNGs into one', function (done) { + const paths = getPaths('alpha-layer-012'); sharp(fixtures.inputPngOverlayLayer0) .overlayWith(fixtures.inputPngOverlayLayer1) @@ -71,8 +72,8 @@ describe('Overlays', function() { }); }); - it('Composite two transparent PNGs into one', function(done) { - var paths = getPaths('alpha-layer-12'); + it('Composite two transparent PNGs into one', function (done) { + const paths = getPaths('alpha-layer-12'); sharp(fixtures.inputPngOverlayLayer1) .overlayWith(fixtures.inputPngOverlayLayer2) @@ -83,8 +84,8 @@ describe('Overlays', function() { }); }); - it('Composite two low-alpha transparent PNGs into one', function(done) { - var paths = getPaths('alpha-layer-12-low-alpha'); + it('Composite two low-alpha transparent PNGs into one', function (done) { + const paths = getPaths('alpha-layer-12-low-alpha'); sharp(fixtures.inputPngOverlayLayer1LowAlpha) .overlayWith(fixtures.inputPngOverlayLayer2LowAlpha) @@ -95,8 +96,8 @@ describe('Overlays', function() { }); }); - it('Composite three low-alpha transparent PNGs into one', function(done) { - var paths = getPaths('alpha-layer-012-low-alpha'); + it('Composite three low-alpha transparent PNGs into one', function (done) { + const paths = getPaths('alpha-layer-012-low-alpha'); sharp(fixtures.inputPngOverlayLayer0) .overlayWith(fixtures.inputPngOverlayLayer1LowAlpha) @@ -113,26 +114,26 @@ describe('Overlays', function() { }); }); - it('Composite rgb+alpha PNG onto JPEG', function(done) { - var paths = getPaths('overlay-jpeg-with-rgb', 'jpg'); + it('Composite rgb+alpha PNG onto JPEG', function (done) { + const paths = getPaths('overlay-jpeg-with-rgb', 'jpg'); sharp(fixtures.inputJpg) .resize(2048, 1536) .overlayWith(fixtures.inputPngOverlayLayer1) - .toFile(paths.actual, function(error, info) { + .toFile(paths.actual, function (error, info) { if (error) return done(error); fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102); done(); }); }); - it('Composite greyscale+alpha PNG onto JPEG', function(done) { - var paths = getPaths('overlay-jpeg-with-greyscale', 'jpg'); + it('Composite greyscale+alpha PNG onto JPEG', function (done) { + const paths = getPaths('overlay-jpeg-with-greyscale', 'jpg'); sharp(fixtures.inputJpg) .resize(400, 300) .overlayWith(fixtures.inputPngWithGreyAlpha) - .toFile(paths.actual, function(error, info) { + .toFile(paths.actual, function (error, info) { if (error) return done(error); fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102); done(); @@ -140,13 +141,13 @@ describe('Overlays', function() { }); if (sharp.format.webp.input.file) { - it('Composite WebP onto JPEG', function(done) { - var paths = getPaths('overlay-jpeg-with-webp', 'jpg'); + it('Composite WebP onto JPEG', function (done) { + const paths = getPaths('overlay-jpeg-with-webp', 'jpg'); sharp(fixtures.inputJpg) .resize(300, 300) .overlayWith(fixtures.inputWebPWithTransparency) - .toFile(paths.actual, function(error, info) { + .toFile(paths.actual, function (error, info) { if (error) return done(error); fixtures.assertMaxColourDistance(paths.actual, paths.expected, 102); done(); @@ -154,48 +155,48 @@ describe('Overlays', function() { }); } - it('Composite JPEG onto PNG', function(done) { + it('Composite JPEG onto PNG', function (done) { sharp(fixtures.inputPngOverlayLayer1) .overlayWith(fixtures.inputJpgWithLandscapeExif1) - .toBuffer(function(error) { + .toBuffer(function (error) { if (error) return done(error); done(); }); }); - it('Composite opaque JPEG onto JPEG', function(done) { + it('Composite opaque JPEG onto JPEG', function (done) { sharp(fixtures.inputJpg) .overlayWith(fixtures.inputJpgWithLandscapeExif1) - .toBuffer(function(error) { + .toBuffer(function (error) { if (error) return done(error); done(); }); }); - it('Fail when overlay is larger', function(done) { + it('Fail when overlay is larger', function (done) { sharp(fixtures.inputJpg) .resize(320) .overlayWith(fixtures.inputPngOverlayLayer1) - .toBuffer(function(error) { + .toBuffer(function (error) { assert.strictEqual(true, error instanceof Error); done(); }); }); - it('Fail with empty String parameter', function() { - assert.throws(function() { + it('Fail with empty String parameter', function () { + assert.throws(function () { sharp().overlayWith(''); }); }); - it('Fail with non-String parameter', function() { - assert.throws(function() { + it('Fail with non-String parameter', function () { + assert.throws(function () { sharp().overlayWith(1); }); }); - it('Fail with unsupported gravity', function() { - assert.throws(function() { + it('Fail with unsupported gravity', function () { + assert.throws(function () { sharp() .overlayWith(fixtures.inputPngOverlayLayer1, { gravity: 9 @@ -203,22 +204,22 @@ describe('Overlays', function() { }); }); - it('Empty options', function() { - assert.doesNotThrow(function() { + it('Empty options', function () { + assert.doesNotThrow(function () { sharp().overlayWith(fixtures.inputPngOverlayLayer1, {}); }); }); - describe('Overlay with numeric gravity', function() { - Object.keys(sharp.gravity).forEach(function(gravity) { - it(gravity, function(done) { - var expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg'); + describe('Overlay with numeric gravity', function () { + Object.keys(sharp.gravity).forEach(function (gravity) { + it(gravity, function (done) { + const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg'); sharp(fixtures.inputJpg) .resize(80) .overlayWith(fixtures.inputPngWithTransparency16bit, { gravity: gravity }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -230,16 +231,16 @@ describe('Overlays', function() { }); }); - describe('Overlay with string-based gravity', function() { - Object.keys(sharp.gravity).forEach(function(gravity) { - it(gravity, function(done) { - var expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg'); + describe('Overlay with string-based gravity', function () { + Object.keys(sharp.gravity).forEach(function (gravity) { + it(gravity, function (done) { + const expected = fixtures.expected('overlay-gravity-' + gravity + '.jpg'); sharp(fixtures.inputJpg) .resize(80) .overlayWith(fixtures.inputPngWithTransparency16bit, { gravity: sharp.gravity[gravity] }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -251,17 +252,17 @@ describe('Overlays', function() { }); }); - describe('Overlay with tile enabled and gravity', function() { - Object.keys(sharp.gravity).forEach(function(gravity) { - it(gravity, function(done) { - var expected = fixtures.expected('overlay-tile-gravity-' + gravity + '.jpg'); + describe('Overlay with tile enabled and gravity', function () { + Object.keys(sharp.gravity).forEach(function (gravity) { + it(gravity, function (done) { + const expected = fixtures.expected('overlay-tile-gravity-' + gravity + '.jpg'); sharp(fixtures.inputJpg) .resize(80) .overlayWith(fixtures.inputPngWithTransparency16bit, { tile: true, gravity: gravity }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -273,43 +274,41 @@ describe('Overlays', function() { }); }); - describe("Overlay with top-left offsets", function() { - it('Overlay with 10px top & 10px left offsets', function(done) { - var expected = fixtures.expected('overlay-valid-offsets-10-10.jpg'); + describe('Overlay with top-left offsets', function () { + it('Overlay with 10px top & 10px left offsets', function (done) { + const expected = fixtures.expected('overlay-valid-offsets-10-10.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { top: 10, left: 10 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); fixtures.assertSimilar(expected, data, done); }); - }); - it('Overlay with 100px top & 300px left offsets', function(done) { - var expected = fixtures.expected('overlay-valid-offsets-100-300.jpg'); + it('Overlay with 100px top & 300px left offsets', function (done) { + const expected = fixtures.expected('overlay-valid-offsets-100-300.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { top: 100, left: 300 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); fixtures.assertSimilar(expected, data, done); }); - }); - it('Overlay with only top offset', function() { - assert.throws(function() { + it('Overlay with only top offset', function () { + assert.throws(function () { sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { @@ -318,84 +317,81 @@ describe('Overlays', function() { }); }); - it('Overlay with only left offset', function() { - assert.throws(function() { + it('Overlay with only left offset', function () { + assert.throws(function () { sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { left: 1000 }); - }); + }); }); - it('Overlay with negative offsets', function() { - assert.throws(function() { + it('Overlay with negative offsets', function () { + assert.throws(function () { sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { top: -1000, left: -1000 }); - }); + }); }); - it('Overlay with 0 offset', function(done) { - var expected = fixtures.expected('overlay-offset-0.jpg'); + it('Overlay with 0 offset', function (done) { + const expected = fixtures.expected('overlay-offset-0.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { top: 0, left: 0 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); fixtures.assertSimilar(expected, data, done); }); - }); - it('Overlay with offset and gravity', function(done) { - var expected = fixtures.expected('overlay-offset-with-gravity.jpg'); + it('Overlay with offset and gravity', function (done) { + const expected = fixtures.expected('overlay-offset-with-gravity.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { left: 10, top: 10, - gravity : 4 - + gravity: 4 + }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); fixtures.assertSimilar(expected, data, done); }); - }); - it('Overlay with offset and gravity and tile', function(done) { - var expected = fixtures.expected('overlay-offset-with-gravity-tile.jpg'); + it('Overlay with offset and gravity and tile', function (done) { + const expected = fixtures.expected('overlay-offset-with-gravity-tile.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { left: 10, top: 10, - gravity : 4, + gravity: 4, tile: true }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); fixtures.assertSimilar(expected, data, done); }); - }); - it('Overlay with offset and tile', function(done) { - var expected = fixtures.expected('overlay-offset-with-tile.jpg'); + it('Overlay with offset and tile', function (done) { + const expected = fixtures.expected('overlay-offset-with-tile.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { @@ -403,7 +399,7 @@ describe('Overlays', function() { top: 10, tile: true }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); @@ -411,27 +407,27 @@ describe('Overlays', function() { }); }); - it('Overlay with invalid cutout option', function() { - assert.throws(function() { + it('Overlay with invalid cutout option', function () { + assert.throws(function () { sharp().overlayWith('ignore', { cutout: 1 }); }); }); - it('Overlay with invalid tile option', function() { - assert.throws(function() { + it('Overlay with invalid tile option', function () { + assert.throws(function () { sharp().overlayWith('ignore', { tile: 1 }); }); }); - it('Overlay with very large offset', function(done) { - var expected = fixtures.expected('overlay-very-large-offset.jpg'); + it('Overlay with very large offset', function (done) { + const expected = fixtures.expected('overlay-very-large-offset.jpg'); sharp(fixtures.inputJpg) .resize(400) .overlayWith(fixtures.inputPngWithTransparency16bit, { left: 10000, top: 10000 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(3, info.channels); @@ -439,10 +435,10 @@ describe('Overlays', function() { }); }); - it('Overlay 100x100 with 50x50 so bottom edges meet', function(done) { + it('Overlay 100x100 with 50x50 so bottom edges meet', function (done) { sharp(fixtures.inputJpg) .resize(50, 50) - .toBuffer(function(err, overlay) { + .toBuffer(function (err, overlay) { if (err) throw err; sharp(fixtures.inputJpgWithLandscapeExif1) .resize(100, 100) @@ -450,7 +446,7 @@ describe('Overlays', function() { top: 50, left: 40 }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(100, info.width); @@ -461,15 +457,15 @@ describe('Overlays', function() { }); }); - it('With tile enabled and image rotated 90 degrees', function(done) { - var expected = fixtures.expected('overlay-tile-rotated90.jpg'); + it('With tile enabled and image rotated 90 degrees', function (done) { + const expected = fixtures.expected('overlay-tile-rotated90.jpg'); sharp(fixtures.inputJpg) .rotate(90) .resize(80) .overlayWith(fixtures.inputPngWithTransparency16bit, { tile: true }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -479,8 +475,8 @@ describe('Overlays', function() { }); }); - it('With tile enabled and image rotated 90 degrees and gravity northwest', function(done) { - var expected = fixtures.expected('overlay-tile-rotated90-gravity-northwest.jpg'); + it('With tile enabled and image rotated 90 degrees and gravity northwest', function (done) { + const expected = fixtures.expected('overlay-tile-rotated90-gravity-northwest.jpg'); sharp(fixtures.inputJpg) .rotate(90) .resize(80) @@ -488,7 +484,7 @@ describe('Overlays', function() { tile: true, gravity: 'northwest' }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -498,17 +494,17 @@ describe('Overlays', function() { }); }); - describe('Overlay with cutout enabled and gravity', function() { - Object.keys(sharp.gravity).forEach(function(gravity) { - it(gravity, function(done) { - var expected = fixtures.expected('overlay-cutout-gravity-' + gravity + '.jpg'); + describe('Overlay with cutout enabled and gravity', function () { + Object.keys(sharp.gravity).forEach(function (gravity) { + it(gravity, function (done) { + const expected = fixtures.expected('overlay-cutout-gravity-' + gravity + '.jpg'); sharp(fixtures.inputJpg) .resize(80) .overlayWith(fixtures.inputPngWithTransparency16bit, { cutout: true, gravity: gravity }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -520,15 +516,15 @@ describe('Overlays', function() { }); }); - it('With cutout enabled and image rotated 90 degrees', function(done) { - var expected = fixtures.expected('overlay-cutout-rotated90.jpg'); + it('With cutout enabled and image rotated 90 degrees', function (done) { + const expected = fixtures.expected('overlay-cutout-rotated90.jpg'); sharp(fixtures.inputJpg) .rotate(90) .resize(80) .overlayWith(fixtures.inputPngWithTransparency16bit, { cutout: true }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -538,8 +534,8 @@ describe('Overlays', function() { }); }); - it('With cutout enabled and image rotated 90 degrees and gravity northwest', function(done) { - var expected = fixtures.expected('overlay-cutout-rotated90-gravity-northwest.jpg'); + it('With cutout enabled and image rotated 90 degrees and gravity northwest', function (done) { + const expected = fixtures.expected('overlay-cutout-rotated90-gravity-northwest.jpg'); sharp(fixtures.inputJpg) .rotate(90) .resize(80) @@ -547,7 +543,7 @@ describe('Overlays', function() { cutout: true, gravity: 'northwest' }) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(80, info.width); @@ -557,28 +553,27 @@ describe('Overlays', function() { }); }); - it('Composite RGBA raw buffer onto JPEG', function(done) { + it('Composite RGBA raw buffer onto JPEG', function (done) { sharp(fixtures.inputPngOverlayLayer1) .raw() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; sharp(fixtures.inputJpg) .resize(2048, 1536) .overlayWith(data, { raw: info }) - .toBuffer(function(err, data) { + .toBuffer(function (err, data) { if (err) throw err; fixtures.assertSimilar(fixtures.expected('overlay-jpeg-with-rgb.jpg'), data, done); }); }); }); - it('Throws an error when called with an invalid file', function(done) { + it('Throws an error when called with an invalid file', function (done) { sharp(fixtures.inputJpg) .overlayWith('notfound.png') - .toBuffer(function(err) { + .toBuffer(function (err) { assert(err instanceof Error); done(); }); }); - }); diff --git a/test/unit/require.js b/test/unit/require.js index e195e5a1..e3465ac7 100644 --- a/test/unit/require.js +++ b/test/unit/require.js @@ -1,15 +1,15 @@ 'use strict'; -describe('Require-time checks', function() { +/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "(bufferutil|sharp)" }] */ - /* +describe('Require-time checks', function () { + /** Including sharp alongside another C++ module that does not require -stdlib=libc++ (for its C++11 features) has caused clang/llvm to segfault due to the use of static function variables. */ - it('Require alongside C++ module that does not use libc++', function() { - var bufferutil = require('bufferutil'); - var sharp = require('../../index'); + it('Require alongside C++ module that does not use libc++', function () { + const bufferutil = require('bufferutil'); + const sharp = require('../../index'); }); - }); diff --git a/test/unit/resize.js b/test/unit/resize.js index cecfade2..a3411ee3 100644 --- a/test/unit/resize.js +++ b/test/unit/resize.js @@ -1,14 +1,13 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Resize dimensions', function() { - - it('Exact crop', function(done) { - sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function(err, data, info) { +describe('Resize dimensions', function () { + it('Exact crop', function (done) { + sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -18,8 +17,8 @@ describe('Resize dimensions', function() { }); }); - it('Fixed width', function(done) { - sharp(fixtures.inputJpg).resize(320).toBuffer(function(err, data, info) { + it('Fixed width', function (done) { + sharp(fixtures.inputJpg).resize(320).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -29,8 +28,8 @@ describe('Resize dimensions', function() { }); }); - it('Fixed height', function(done) { - sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function(err, data, info) { + it('Fixed height', function (done) { + sharp(fixtures.inputJpg).resize(null, 320).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -40,8 +39,8 @@ describe('Resize dimensions', function() { }); }); - it('Identity transform', function(done) { - sharp(fixtures.inputJpg).toBuffer(function(err, data, info) { + it('Identity transform', function (done) { + sharp(fixtures.inputJpg).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -51,8 +50,8 @@ describe('Resize dimensions', function() { }); }); - it('Upscale', function(done) { - sharp(fixtures.inputJpg).resize(3000).toBuffer(function(err, data, info) { + it('Upscale', function (done) { + sharp(fixtures.inputJpg).resize(3000).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -62,8 +61,8 @@ describe('Resize dimensions', function() { }); }); - it('Invalid width - NaN', function(done) { - var isValid = true; + it('Invalid width - NaN', function (done) { + let isValid = true; try { sharp(fixtures.inputJpg).resize('spoons', 240); } catch (err) { @@ -73,8 +72,8 @@ describe('Resize dimensions', function() { done(); }); - it('Invalid height - NaN', function(done) { - var isValid = true; + it('Invalid height - NaN', function (done) { + let isValid = true; try { sharp(fixtures.inputJpg).resize(320, 'spoons'); } catch (err) { @@ -84,8 +83,8 @@ describe('Resize dimensions', function() { done(); }); - it('Invalid width - float', function(done) { - var isValid = true; + it('Invalid width - float', function (done) { + let isValid = true; try { sharp(fixtures.inputJpg).resize(1.5, 240); } catch (err) { @@ -95,8 +94,8 @@ describe('Resize dimensions', function() { done(); }); - it('Invalid height - float', function(done) { - var isValid = true; + it('Invalid height - float', function (done) { + let isValid = true; try { sharp(fixtures.inputJpg).resize(320, 1.5); } catch (err) { @@ -106,8 +105,8 @@ describe('Resize dimensions', function() { done(); }); - it('Invalid width - too large', function(done) { - var isValid = true; + it('Invalid width - too large', function (done) { + let isValid = true; try { sharp(fixtures.inputJpg).resize(0x4000, 240); } catch (err) { @@ -117,8 +116,8 @@ describe('Resize dimensions', function() { done(); }); - it('Invalid height - too large', function(done) { - var isValid = true; + it('Invalid height - too large', function (done) { + let isValid = true; try { sharp(fixtures.inputJpg).resize(320, 0x4000); } catch (err) { @@ -129,18 +128,18 @@ describe('Resize dimensions', function() { }); if (sharp.format.webp.output.buffer) { - it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function(done) { + it('WebP shrink-on-load rounds to zero, ensure recalculation is correct', function (done) { sharp(fixtures.inputJpg) .resize(1080, 607) .webp() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('webp', info.format); assert.strictEqual(1080, info.width); assert.strictEqual(607, info.height); sharp(data) .resize(233, 131) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('webp', info.format); assert.strictEqual(233, info.width); @@ -152,12 +151,12 @@ describe('Resize dimensions', function() { } if (sharp.format.tiff.input.file) { - it('TIFF embed known to cause rounding errors', function(done) { + it('TIFF embed known to cause rounding errors', function (done) { sharp(fixtures.inputTiff) .resize(240, 320) .embed() .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -167,11 +166,11 @@ describe('Resize dimensions', function() { }); }); - it('TIFF known to cause rounding errors', function(done) { + it('TIFF known to cause rounding errors', function (done) { sharp(fixtures.inputTiff) .resize(240, 320) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -181,8 +180,8 @@ describe('Resize dimensions', function() { }); }); - it('Max width or height considering ratio (portrait)', function(done) { - sharp(fixtures.inputTiff).resize(320, 320).max().jpeg().toBuffer(function(err, data, info) { + it('Max width or height considering ratio (portrait)', function (done) { + sharp(fixtures.inputTiff).resize(320, 320).max().jpeg().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -192,8 +191,8 @@ describe('Resize dimensions', function() { }); }); - it('Min width or height considering ratio (portrait)', function(done) { - sharp(fixtures.inputTiff).resize(320, 320).min().jpeg().toBuffer(function(err, data, info) { + it('Min width or height considering ratio (portrait)', function (done) { + sharp(fixtures.inputTiff).resize(320, 320).min().jpeg().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -204,8 +203,8 @@ describe('Resize dimensions', function() { }); } - it('Max width or height considering ratio (landscape)', function(done) { - sharp(fixtures.inputJpg).resize(320, 320).max().toBuffer(function(err, data, info) { + it('Max width or height considering ratio (landscape)', function (done) { + sharp(fixtures.inputJpg).resize(320, 320).max().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -215,8 +214,8 @@ describe('Resize dimensions', function() { }); }); - it('Provide only one dimension with max, should default to crop', function(done) { - sharp(fixtures.inputJpg).resize(320).max().toBuffer(function(err, data, info) { + it('Provide only one dimension with max, should default to crop', function (done) { + sharp(fixtures.inputJpg).resize(320).max().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -226,8 +225,8 @@ describe('Resize dimensions', function() { }); }); - it('Min width or height considering ratio (landscape)', function(done) { - sharp(fixtures.inputJpg).resize(320, 320).min().toBuffer(function(err, data, info) { + it('Min width or height considering ratio (landscape)', function (done) { + sharp(fixtures.inputJpg).resize(320, 320).min().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -237,8 +236,8 @@ describe('Resize dimensions', function() { }); }); - it('Provide only one dimension with min, should default to crop', function(done) { - sharp(fixtures.inputJpg).resize(320).min().toBuffer(function(err, data, info) { + it('Provide only one dimension with min, should default to crop', function (done) { + sharp(fixtures.inputJpg).resize(320).min().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -248,11 +247,11 @@ describe('Resize dimensions', function() { }); }); - it('Do not enlarge when input width is already less than output width', function(done) { + it('Do not enlarge when input width is already less than output width', function (done) { sharp(fixtures.inputJpg) .resize(2800) .withoutEnlargement() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -262,11 +261,11 @@ describe('Resize dimensions', function() { }); }); - it('Do not enlarge when input height is already less than output height', function(done) { + it('Do not enlarge when input height is already less than output height', function (done) { sharp(fixtures.inputJpg) .resize(null, 2300) .withoutEnlargement() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -276,11 +275,11 @@ describe('Resize dimensions', function() { }); }); - it('Do enlarge when input width is less than output width', function(done) { + it('Do enlarge when input width is less than output width', function (done) { sharp(fixtures.inputJpg) .resize(2800) .withoutEnlargement(false) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -289,9 +288,9 @@ describe('Resize dimensions', function() { done(); }); }); - - it('Downscale width and height, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(320, 320).ignoreAspectRatio().toBuffer(function(err, data, info) { + + it('Downscale width and height, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(320, 320).ignoreAspectRatio().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -300,9 +299,9 @@ describe('Resize dimensions', function() { done(); }); }); - - it('Downscale width, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(320).ignoreAspectRatio().toBuffer(function(err, data, info) { + + it('Downscale width, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(320).ignoreAspectRatio().toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -311,82 +310,81 @@ describe('Resize dimensions', function() { done(); }); }); - - it('Downscale height, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(null, 320).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Upscale width and height, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(3000, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3000, info.width); - assert.strictEqual(3000, info.height); - done(); - }); - }); - - it('Upscale width, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(3000).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3000, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); - - it('Upscale height, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(null, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(3000, info.height); - done(); - }); - }); - - it('Downscale width, upscale height, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(320, 3000).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(320, info.width); - assert.strictEqual(3000, info.height); - done(); - }); - }); - - it('Upscale width, downscale height, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).resize(3000, 320).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(3000, info.width); - assert.strictEqual(320, info.height); - done(); - }); - }); - - it('Identity transform, ignoring aspect ratio', function(done) { - sharp(fixtures.inputJpg).ignoreAspectRatio().toBuffer(function(err, data, info) { - if (err) throw err; - assert.strictEqual(true, data.length > 0); - assert.strictEqual('jpeg', info.format); - assert.strictEqual(2725, info.width); - assert.strictEqual(2225, info.height); - done(); - }); - }); + it('Downscale height, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(null, 320).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(2725, info.width); + assert.strictEqual(320, info.height); + done(); + }); + }); + + it('Upscale width and height, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(3000, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(3000, info.width); + assert.strictEqual(3000, info.height); + done(); + }); + }); + + it('Upscale width, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(3000).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(3000, info.width); + assert.strictEqual(2225, info.height); + done(); + }); + }); + + it('Upscale height, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(null, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(2725, info.width); + assert.strictEqual(3000, info.height); + done(); + }); + }); + + it('Downscale width, upscale height, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(320, 3000).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(320, info.width); + assert.strictEqual(3000, info.height); + done(); + }); + }); + + it('Upscale width, downscale height, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).resize(3000, 320).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(3000, info.width); + assert.strictEqual(320, info.height); + done(); + }); + }); + + it('Identity transform, ignoring aspect ratio', function (done) { + sharp(fixtures.inputJpg).ignoreAspectRatio().toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual(true, data.length > 0); + assert.strictEqual('jpeg', info.format); + assert.strictEqual(2725, info.width); + assert.strictEqual(2225, info.height); + done(); + }); + }); }); diff --git a/test/unit/rotate.js b/test/unit/rotate.js index f4dfe894..33daa74a 100644 --- a/test/unit/rotate.js +++ b/test/unit/rotate.js @@ -1,19 +1,18 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Rotation', function() { - - ['Landscape', 'Portrait'].forEach(function(orientation) { - [1,2,3,4,5,6,7,8].forEach(function(exifTag) { - it('Input image has Orientation EXIF tag value of (' + exifTag + '), auto-rotate', function(done) { - sharp(fixtures['inputJpgWith'+orientation+'Exif'+exifTag]) +describe('Rotation', function () { + ['Landscape', 'Portrait'].forEach(function (orientation) { + [1, 2, 3, 4, 5, 6, 7, 8].forEach(function (exifTag) { + it('Input image has Orientation EXIF tag value of (' + exifTag + '), auto-rotate', function (done) { + sharp(fixtures['inputJpgWith' + orientation + 'Exif' + exifTag]) .rotate() .resize(320) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -24,8 +23,8 @@ describe('Rotation', function() { }); }); - it('Rotate by 90 degrees, respecting output input size', function(done) { - sharp(fixtures.inputJpg).rotate(90).resize(320, 240).toBuffer(function(err, data, info) { + it('Rotate by 90 degrees, respecting output input size', function (done) { + sharp(fixtures.inputJpg).rotate(90).resize(320, 240).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -35,16 +34,17 @@ describe('Rotation', function() { }); }); - it('Rotate by 270 degrees, square output ignoring aspect ratio', function(done) { + it('Rotate by 270 degrees, square output ignoring aspect ratio', function (done) { sharp(fixtures.inputJpg) .resize(240, 240) .ignoreAspectRatio() .rotate(270) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(240, info.width); assert.strictEqual(240, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { + if (err) throw err; assert.strictEqual(240, metadata.width); assert.strictEqual(240, metadata.height); done(); @@ -52,16 +52,17 @@ describe('Rotation', function() { }); }); - it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function(done) { + it('Rotate by 270 degrees, rectangular output ignoring aspect ratio', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .ignoreAspectRatio() .rotate(270) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { + if (err) throw err; assert.strictEqual(320, metadata.width); assert.strictEqual(240, metadata.height); done(); @@ -69,28 +70,29 @@ describe('Rotation', function() { }); }); - it('Input image has Orientation EXIF tag but do not rotate output', function(done) { + it('Input image has Orientation EXIF tag but do not rotate output', function (done) { sharp(fixtures.inputJpgWithExif) .resize(320) .withMetadata() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(427, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { + if (err) throw err; assert.strictEqual(8, metadata.orientation); done(); }); }); }); - it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function(done) { + it('Input image has Orientation EXIF tag value of 8 (270 degrees), auto-rotate', function (done) { sharp(fixtures.inputJpgWithExif) .rotate() .resize(320) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -99,42 +101,44 @@ describe('Rotation', function() { }); }); - it('Override EXIF Orientation tag metadata after auto-rotate', function(done) { + it('Override EXIF Orientation tag metadata after auto-rotate', function (done) { sharp(fixtures.inputJpgWithExif) .rotate() .resize(320) .withMetadata({orientation: 3}) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { + if (err) throw err; assert.strictEqual(3, metadata.orientation); fixtures.assertSimilar(fixtures.expected('exif-8.jpg'), data, done); }); }); }); - it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function(done) { + it('Input image has Orientation EXIF tag value of 5 (270 degrees + flip), auto-rotate', function (done) { sharp(fixtures.inputJpgWithExifMirroring) .rotate() .resize(320) .withMetadata() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { + if (err) throw err; assert.strictEqual(1, metadata.orientation); fixtures.assertSimilar(fixtures.expected('exif-5.jpg'), data, done); }); }); }); - it('Attempt to auto-rotate using image that has no EXIF', function(done) { - sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function(err, data, info) { + it('Attempt to auto-rotate using image that has no EXIF', function (done) { + sharp(fixtures.inputJpg).rotate().resize(320).toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -144,12 +148,12 @@ describe('Rotation', function() { }); }); - it('Attempt to auto-rotate image format without EXIF support', function(done) { + it('Attempt to auto-rotate image format without EXIF support', function (done) { sharp(fixtures.inputPng) .rotate() .resize(320) .jpeg() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('jpeg', info.format); @@ -159,23 +163,23 @@ describe('Rotation', function() { }); }); - it('Rotate to an invalid angle, should fail', function() { - assert.throws(function() { + it('Rotate to an invalid angle, should fail', function () { + assert.throws(function () { sharp(fixtures.inputJpg).rotate(1); }); }); - it('Flip - vertical', function(done) { + it('Flip - vertical', function (done) { sharp(fixtures.inputJpg) .resize(320) .flip() .withMetadata() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(261, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual(1, metadata.orientation); fixtures.assertSimilar(fixtures.expected('flip.jpg'), data, done); @@ -183,17 +187,17 @@ describe('Rotation', function() { }); }); - it('Flop - horizontal', function(done) { + it('Flop - horizontal', function (done) { sharp(fixtures.inputJpg) .resize(320) .flop() .withMetadata() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(261, info.height); - sharp(data).metadata(function(err, metadata) { + sharp(data).metadata(function (err, metadata) { if (err) throw err; assert.strictEqual(1, metadata.orientation); fixtures.assertSimilar(fixtures.expected('flop.jpg'), data, done); @@ -201,11 +205,11 @@ describe('Rotation', function() { }); }); - it('Flip and flop', function(done) { + it('Flip and flop', function (done) { sharp(fixtures.inputJpg) .resize(320) .flop() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -214,12 +218,12 @@ describe('Rotation', function() { }); }); - it('Neither flip nor flop', function(done) { + it('Neither flip nor flop', function (done) { sharp(fixtures.inputJpg) .resize(320) .flip(false) .flop(false) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -227,5 +231,4 @@ describe('Rotation', function() { fixtures.assertSimilar(fixtures.inputJpg, data, done); }); }); - }); diff --git a/test/unit/sharpen.js b/test/unit/sharpen.js index b06b4556..1122479f 100644 --- a/test/unit/sharpen.js +++ b/test/unit/sharpen.js @@ -1,17 +1,16 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Sharpen', function() { - - it('specific radius 10 (sigma 6)', function(done) { +describe('Sharpen', function () { + it('specific radius 10 (sigma 6)', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen(6) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -20,11 +19,11 @@ describe('Sharpen', function() { }); }); - it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function(done) { + it('specific radius 3 (sigma 1.5) and levels 0.5, 2.5', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen(1.5, 0.5, 2.5) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -33,11 +32,11 @@ describe('Sharpen', function() { }); }); - it('specific radius 5 (sigma 3.5) and levels 2, 4', function(done) { + it('specific radius 5 (sigma 3.5) and levels 2, 4', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen(3.5, 2, 4) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -47,11 +46,11 @@ describe('Sharpen', function() { }); if (!process.env.SHARP_TEST_WITHOUT_CACHE) { - it('specific radius/levels with alpha channel', function(done) { + it('specific radius/levels with alpha channel', function (done) { sharp(fixtures.inputPngWithTransparency) .resize(320, 240) .sharpen(5, 4, 8) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(4, info.channels); @@ -62,11 +61,11 @@ describe('Sharpen', function() { }); } - it('mild sharpen', function(done) { + it('mild sharpen', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); @@ -75,29 +74,29 @@ describe('Sharpen', function() { }); }); - it('invalid sigma', function() { - assert.throws(function() { + it('invalid sigma', function () { + assert.throws(function () { sharp(fixtures.inputJpg).sharpen(-1.5); }); }); - it('invalid flat', function() { - assert.throws(function() { + it('invalid flat', function () { + assert.throws(function () { sharp(fixtures.inputJpg).sharpen(1, -1); }); }); - it('invalid jagged', function() { - assert.throws(function() { + it('invalid jagged', function () { + assert.throws(function () { sharp(fixtures.inputJpg).sharpen(1, 1, -1); }); }); - it('sharpened image is larger than non-sharpened', function(done) { + it('sharpened image is larger than non-sharpened', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen(false) - .toBuffer(function(err, notSharpened, info) { + .toBuffer(function (err, notSharpened, info) { if (err) throw err; assert.strictEqual(true, notSharpened.length > 0); assert.strictEqual('jpeg', info.format); @@ -106,7 +105,7 @@ describe('Sharpen', function() { sharp(fixtures.inputJpg) .resize(320, 240) .sharpen(true) - .toBuffer(function(err, sharpened, info) { + .toBuffer(function (err, sharpened, info) { if (err) throw err; assert.strictEqual(true, sharpened.length > 0); assert.strictEqual(true, sharpened.length > notSharpened.length); @@ -117,5 +116,4 @@ describe('Sharpen', function() { }); }); }); - }); diff --git a/test/unit/threshold.js b/test/unit/threshold.js index be6b079f..b449c8c5 100644 --- a/test/unit/threshold.js +++ b/test/unit/threshold.js @@ -1,16 +1,17 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Threshold', function() { - it('threshold 1 jpeg', function(done) { +describe('Threshold', function () { + it('threshold 1 jpeg', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .threshold(1) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -18,11 +19,12 @@ describe('Threshold', function() { }); }); - it('threshold 40 jpeg', function(done) { + it('threshold 40 jpeg', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .threshold(40) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -30,11 +32,12 @@ describe('Threshold', function() { }); }); - it('threshold 128', function(done) { + it('threshold 128', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .threshold(128) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -42,11 +45,12 @@ describe('Threshold', function() { }); }); - it('threshold true (=128)', function(done) { + it('threshold true (=128)', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .threshold(true) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -54,19 +58,21 @@ describe('Threshold', function() { }); }); - it('threshold false (=0)', function(done) { + it('threshold false (=0)', function (done) { sharp(fixtures.inputJpg) .threshold(false) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; fixtures.assertSimilar(fixtures.inputJpg, data, done); }); }); - it('threshold grayscale: true (=128)', function(done) { + it('threshold grayscale: true (=128)', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) - .threshold(128, { grayscale: true } ) - .toBuffer(function(err, data, info) { + .threshold(128, { grayscale: true }) + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -74,11 +80,12 @@ describe('Threshold', function() { }); }); - it('threshold default jpeg', function(done) { + it('threshold default jpeg', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) .threshold() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -86,11 +93,12 @@ describe('Threshold', function() { }); }); - it('threshold default png transparency', function(done) { + it('threshold default png transparency', function (done) { sharp(fixtures.inputPngWithTransparency) .resize(320, 240) .threshold() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -98,11 +106,12 @@ describe('Threshold', function() { }); }); - it('threshold default png alpha', function(done) { + it('threshold default png alpha', function (done) { sharp(fixtures.inputPngWithGreyAlpha) .resize(320, 240) .threshold() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); @@ -110,37 +119,37 @@ describe('Threshold', function() { }); }); - if (sharp.format.webp.output.file) { - it('threshold default webp transparency', function(done) { - sharp(fixtures.inputWebPWithTransparency) - .threshold() - .toBuffer(function(err, data, info) { - assert.strictEqual('webp', info.format); - fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done); - }); - }); - } + it('threshold default webp transparency', function (done) { + sharp(fixtures.inputWebPWithTransparency) + .threshold() + .toBuffer(function (err, data, info) { + if (err) throw err; + assert.strictEqual('webp', info.format); + fixtures.assertSimilar(fixtures.expected('threshold-128-transparency.webp'), data, done); + }); + }); - it('color threshold', function(done) { + it('color threshold', function (done) { sharp(fixtures.inputJpg) .resize(320, 240) - .threshold(128,{'grayscale':false}) - .toBuffer(function(err, data, info) { + .threshold(128, {'grayscale': false}) + .toBuffer(function (err, data, info) { + if (err) throw err; assert.strictEqual('jpeg', info.format); assert.strictEqual(320, info.width); assert.strictEqual(240, info.height); fixtures.assertSimilar(fixtures.expected('threshold-color-128.jpg'), data, done); - }); + }); }); - it('invalid threshold -1', function() { - assert.throws(function() { + it('invalid threshold -1', function () { + assert.throws(function () { sharp().threshold(-1); }); }); - it('invalid threshold 256', function() { - assert.throws(function() { + it('invalid threshold 256', function () { + assert.throws(function () { sharp().threshold(256); }); }); diff --git a/test/unit/trim.js b/test/unit/trim.js index ffdc2424..2e09e05a 100644 --- a/test/unit/trim.js +++ b/test/unit/trim.js @@ -1,18 +1,17 @@ 'use strict'; -var assert = require('assert'); +const assert = require('assert'); -var sharp = require('../../index'); -var fixtures = require('../fixtures'); +const sharp = require('../../index'); +const fixtures = require('../fixtures'); -describe('Trim borders', function() { - - it('Threshold default', function(done) { - var expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png'); +describe('Trim borders', function () { + it('Threshold default', function (done) { + const expected = fixtures.expected('alpha-layer-1-fill-trim-resize.png'); sharp(fixtures.inputPngOverlayLayer1) .resize(450, 322) .trim() - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual('png', info.format); assert.strictEqual(450, info.width); @@ -21,11 +20,11 @@ describe('Trim borders', function() { }); }); - it('16-bit PNG with alpha channel', function(done) { + it('16-bit PNG with alpha channel', function (done) { sharp(fixtures.inputPngWithTransparency16bit) .resize(32, 32) .trim(20) - .toBuffer(function(err, data, info) { + .toBuffer(function (err, data, info) { if (err) throw err; assert.strictEqual(true, data.length > 0); assert.strictEqual('png', info.format); @@ -36,10 +35,10 @@ describe('Trim borders', function() { }); }); - describe('Invalid thresholds', function() { - [-1, 100, 'fail', {}].forEach(function(threshold) { - it(JSON.stringify(threshold), function() { - assert.throws(function() { + describe('Invalid thresholds', function () { + [-1, 100, 'fail', {}].forEach(function (threshold) { + it(JSON.stringify(threshold), function () { + assert.throws(function () { sharp().trim(threshold); }); }); diff --git a/test/unit/util.js b/test/unit/util.js index 022adb9c..d842a54f 100644 --- a/test/unit/util.js +++ b/test/unit/util.js @@ -1,17 +1,15 @@ 'use strict'; -var assert = require('assert'); -var fixtures = require('../fixtures'); -var sharp = require('../../index'); +const assert = require('assert'); +const sharp = require('../../index'); -var defaultConcurrency = sharp.concurrency(); +const defaultConcurrency = sharp.concurrency(); -describe('Utilities', function() { - - describe('Cache', function() { - it('Can be disabled', function() { +describe('Utilities', function () { + describe('Cache', function () { + it('Can be disabled', function () { sharp.cache(false); - var cache = sharp.cache(false); + const cache = sharp.cache(false); assert.strictEqual(cache.memory.current, 0); assert.strictEqual(cache.memory.max, 0); assert.strictEqual(typeof cache.memory.high, 'number'); @@ -20,14 +18,14 @@ describe('Utilities', function() { assert.strictEqual(cache.items.current, 0); assert.strictEqual(cache.items.max, 0); }); - it('Can be enabled with defaults', function() { - var cache = sharp.cache(true); + it('Can be enabled with defaults', function () { + const cache = sharp.cache(true); assert.strictEqual(cache.memory.max, 50); assert.strictEqual(cache.files.max, 20); assert.strictEqual(cache.items.max, 100); }); - it('Can be set to zero', function() { - var cache = sharp.cache({ + it('Can be set to zero', function () { + const cache = sharp.cache({ memory: 0, files: 0, items: 0 @@ -36,71 +34,71 @@ describe('Utilities', function() { assert.strictEqual(cache.files.max, 0); assert.strictEqual(cache.items.max, 0); }); - it('Can be set to a maximum of 10MB, 100 files and 1000 items', function() { - var cache = sharp.cache({ - memory: 10, - files: 100, - items: 1000 + it('Can be set to a maximum of 10MB, 100 files and 1000 items', function () { + const cache = sharp.cache({ + memory: 10, + files: 100, + items: 1000 }); assert.strictEqual(cache.memory.max, 10); assert.strictEqual(cache.files.max, 100); assert.strictEqual(cache.items.max, 1000); }); - it('Ignores invalid values', function() { + it('Ignores invalid values', function () { sharp.cache(true); - var cache = sharp.cache('spoons'); + const cache = sharp.cache('spoons'); assert.strictEqual(cache.memory.max, 50); assert.strictEqual(cache.files.max, 20); assert.strictEqual(cache.items.max, 100); }); }); - describe('Concurrency', function() { - it('Can be set to use 16 threads', function() { + describe('Concurrency', function () { + it('Can be set to use 16 threads', function () { sharp.concurrency(16); assert.strictEqual(16, sharp.concurrency()); }); - it('Can be reset to default', function() { + it('Can be reset to default', function () { sharp.concurrency(0); assert.strictEqual(defaultConcurrency, sharp.concurrency()); }); - it('Ignores invalid values', function() { + it('Ignores invalid values', function () { sharp.concurrency(0); sharp.concurrency('spoons'); assert.strictEqual(defaultConcurrency, sharp.concurrency()); }); }); - describe('Counters', function() { - it('Have zero value at rest', function() { - var counters = sharp.counters(); + describe('Counters', function () { + it('Have zero value at rest', function () { + const counters = sharp.counters(); assert.strictEqual(0, counters.queue); assert.strictEqual(0, counters.process); }); }); - describe('SIMD', function() { - it('Can get current state', function() { - var simd = sharp.simd(); + describe('SIMD', function () { + it('Can get current state', function () { + const simd = sharp.simd(); assert.strictEqual(typeof simd, 'boolean'); }); - it('Can disable', function() { - var simd = sharp.simd(false); + it('Can disable', function () { + const simd = sharp.simd(false); assert.strictEqual(simd, false); }); - it('Can attempt to enable', function() { - var simd = sharp.simd(true); + it('Can attempt to enable', function () { + const simd = sharp.simd(true); assert.strictEqual(typeof simd, 'boolean'); }); }); - describe('Format', function() { - it('Contains expected attributes', function() { + describe('Format', function () { + it('Contains expected attributes', function () { assert.strictEqual('object', typeof sharp.format); - Object.keys(sharp.format).forEach(function(format) { + Object.keys(sharp.format).forEach(function (format) { assert.strictEqual(true, 'id' in sharp.format[format]); assert.strictEqual(format, sharp.format[format].id); - ['input', 'output'].forEach(function(direction) { + ['input', 'output'].forEach(function (direction) { assert.strictEqual(true, direction in sharp.format[format]); assert.strictEqual('object', typeof sharp.format[format][direction]); assert.strictEqual(3, Object.keys(sharp.format[format][direction]).length); @@ -113,8 +111,8 @@ describe('Utilities', function() { }); }); }); - it('Raw file=false, buffer=true, stream=true', function() { - ['input', 'output'].forEach(function(direction) { + it('Raw file=false, buffer=true, stream=true', function () { + ['input', 'output'].forEach(function (direction) { assert.strictEqual(false, sharp.format.raw[direction].file); assert.strictEqual(true, sharp.format.raw[direction].buffer); assert.strictEqual(true, sharp.format.raw[direction].stream); @@ -122,11 +120,10 @@ describe('Utilities', function() { }); }); - describe('Versions', function() { - it('Contains expected attributes', function() { + describe('Versions', function () { + it('Contains expected attributes', function () { assert.strictEqual('object', typeof sharp.versions); assert.strictEqual('string', typeof sharp.versions.vips); }); }); - });