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,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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user