Update tests to meet semistandard code standards

Switch to const/let instead of var
This commit is contained in:
Lovell Fuller
2016-10-26 11:52:45 +01:00
parent 36e636dca1
commit cbdbbe535a
38 changed files with 1378 additions and 1405 deletions

View File

@@ -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();
});
});
});