mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Update tests to meet semistandard code standards
Switch to const/let instead of var
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user