Drop support for versions of Node prior to v4.

Reduce production (sub)depedency count from 93 to 50.
Modernise dev tooling, e.g. use nyc, replace jshint with semistandard.
Make 'npm test' command consistent across platforms.
This commit is contained in:
Lovell Fuller
2016-10-26 10:07:42 +01:00
parent 3f5e38bb62
commit 36e636dca1
14 changed files with 348 additions and 387 deletions

View File

@@ -1,19 +1,18 @@
'use strict';
var assert = require('assert');
var fs = require('fs');
var sharp = require('../../index');
var fixtures = require('../fixtures');
var BluebirdPromise = require('bluebird');
const assert = require('assert');
const fs = require('fs');
describe('Image channel insertion', function() {
const sharp = require('../../index');
const fixtures = require('../fixtures');
it('Grayscale to RGB, buffer', function(done) {
describe('Image channel insertion', function () {
it('Grayscale to RGB, buffer', function (done) {
sharp(fixtures.inputPng) // gray -> red
.resize(320, 240)
.joinChannel(fixtures.inputPngTestJoinChannel) // new green channel
.joinChannel(fixtures.inputPngStripesH) // new blue channel
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -22,12 +21,12 @@ describe('Image channel insertion', function() {
});
});
it('Grayscale to RGB, file', function(done) {
it('Grayscale to RGB, file', function (done) {
sharp(fixtures.inputPng) // gray -> red
.resize(320, 240)
.joinChannel(fs.readFileSync(fixtures.inputPngTestJoinChannel)) // new green channel
.joinChannel(fs.readFileSync(fixtures.inputPngStripesH)) // new blue channel
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -36,14 +35,14 @@ describe('Image channel insertion', function() {
});
});
it('Grayscale to RGBA, buffer', function(done) {
it('Grayscale to RGBA, buffer', function (done) {
sharp(fixtures.inputPng) // gray -> red
.resize(320, 240)
.joinChannel([fixtures.inputPngTestJoinChannel,
fixtures.inputPngStripesH,
fixtures.inputPngStripesV]) // new green + blue + alpha channel
.toColourspace(sharp.colourspace.srgb)
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -52,14 +51,14 @@ describe('Image channel insertion', function() {
});
});
it('Grayscale to RGBA, file', function(done) {
it('Grayscale to RGBA, file', function (done) {
sharp(fixtures.inputPng) // gray -> red
.resize(320, 240)
.joinChannel([fs.readFileSync(fixtures.inputPngTestJoinChannel), // new green channel
fs.readFileSync(fixtures.inputPngStripesH), // new blue channel
fs.readFileSync(fixtures.inputPngStripesV)]) // new alpha channel
.toColourspace('srgb')
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -68,7 +67,7 @@ describe('Image channel insertion', function() {
});
});
it('Grayscale to CMYK, buffers', function(done) {
it('Grayscale to CMYK, buffers', function (done) {
sharp(fixtures.inputPng) // gray -> magenta
.resize(320, 240)
.joinChannel([fs.readFileSync(fixtures.inputPngTestJoinChannel), // new cyan channel
@@ -76,7 +75,7 @@ describe('Image channel insertion', function() {
fs.readFileSync(fixtures.inputPngStripesV)]) // new black channel
.toColorspace('cmyk')
.toFormat('jpeg')
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -85,12 +84,12 @@ describe('Image channel insertion', function() {
});
});
it('Join raw buffers to RGB', function(done) {
BluebirdPromise.all([
it('Join raw buffers to RGB', function (done) {
Promise.all([
sharp(fixtures.inputPngTestJoinChannel).toColourspace('b-w').raw().toBuffer(),
sharp(fixtures.inputPngStripesH).toColourspace('b-w').raw().toBuffer()
])
.then(function(buffers) {
.then(function (buffers) {
sharp(fixtures.inputPng)
.resize(320, 240)
.joinChannel(buffers,
@@ -99,7 +98,7 @@ describe('Image channel insertion', function() {
height: 240,
channels: 1
}})
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -107,19 +106,19 @@ describe('Image channel insertion', function() {
fixtures.assertSimilar(fixtures.expected('joinChannel-rgb.jpg'), data, done);
});
})
.catch(function(err) {
.catch(function (err) {
throw err;
});
});
it('Grayscale to RGBA, files, two arrays', function(done) {
it('Grayscale to RGBA, files, two arrays', function (done) {
sharp(fixtures.inputPng) // gray -> red
.resize(320, 240)
.joinChannel([fs.readFileSync(fixtures.inputPngTestJoinChannel)]) // new green channel
.joinChannel([fs.readFileSync(fixtures.inputPngStripesH), // new blue channel
fs.readFileSync(fixtures.inputPngStripesV)]) // new alpha channel
.toColourspace('srgb')
.toBuffer(function(err, data, info) {
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
@@ -128,24 +127,23 @@ describe('Image channel insertion', function() {
});
});
it('Invalid raw buffer description', function() {
assert.throws(function() {
sharp().joinChannel(fs.readFileSync(fixtures.inputPng),{raw:{}});
it('Invalid raw buffer description', function () {
assert.throws(function () {
sharp().joinChannel(fs.readFileSync(fixtures.inputPng), {raw: {}});
});
});
it('Invalid input', function() {
assert.throws(function() {
it('Invalid input', function () {
assert.throws(function () {
sharp(fixtures.inputJpg)
.joinChannel(1);
});
});
it('No arguments', function() {
assert.throws(function() {
it('No arguments', function () {
assert.throws(function () {
sharp(fixtures.inputJpg)
.joinChannel();
});
});
});

View File

@@ -1 +0,0 @@
require('mocha-jshint')();

View File

@@ -1,35 +1,35 @@
'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 async = require('async');
var rimraf = require('rimraf');
var unzip = require('unzip');
const eachLimit = require('async/eachLimit');
const rimraf = require('rimraf');
const unzip = require('unzip');
var sharp = require('../../index');
var fixtures = require('../fixtures');
const sharp = require('../../index');
const fixtures = require('../fixtures');
// Verifies all tiles in a given dz output directory are <= size
var assertDeepZoomTiles = function(directory, expectedSize, expectedLevels, done) {
const assertDeepZoomTiles = function (directory, expectedSize, expectedLevels, done) {
// Get levels
var levels = fs.readdirSync(directory);
const levels = fs.readdirSync(directory);
assert.strictEqual(expectedLevels, levels.length);
// Get tiles
var tiles = [];
levels.forEach(function(level) {
const tiles = [];
levels.forEach(function (level) {
// Verify level directory name
assert.strictEqual(true, /^[0-9]+$/.test(level));
fs.readdirSync(path.join(directory, level)).forEach(function(tile) {
fs.readdirSync(path.join(directory, level)).forEach(function (tile) {
// Verify tile file name
assert.strictEqual(true, /^[0-9]+_[0-9]+\.jpeg$/.test(tile));
tiles.push(path.join(directory, level, tile));
});
});
// Verify each tile is <= expectedSize
async.eachSeries(tiles, function(tile, done) {
sharp(tile).metadata(function(err, metadata) {
eachLimit(tiles, 8, function (tile, done) {
sharp(tile).metadata(function (err, metadata) {
if (err) {
done(err);
} else {
@@ -46,11 +46,10 @@ var assertDeepZoomTiles = function(directory, expectedSize, expectedLevels, done
}, done);
};
describe('Tile', function() {
it('Valid size values pass', function() {
[1, 8192].forEach(function(size) {
assert.doesNotThrow(function() {
describe('Tile', function () {
it('Valid size values pass', function () {
[1, 8192].forEach(function (size) {
assert.doesNotThrow(function () {
sharp().tile({
size: size
});
@@ -58,9 +57,9 @@ describe('Tile', function() {
});
});
it('Invalid size values fail', function() {
['zoinks', 1.1, -1, 0, 8193].forEach(function(size) {
assert.throws(function() {
it('Invalid size values fail', function () {
['zoinks', 1.1, -1, 0, 8193].forEach(function (size) {
assert.throws(function () {
sharp().tile({
size: size
});
@@ -68,9 +67,9 @@ describe('Tile', function() {
});
});
it('Valid overlap values pass', function() {
[0, 8192].forEach(function(overlap) {
assert.doesNotThrow(function() {
it('Valid overlap values pass', function () {
[0, 8192].forEach(function (overlap) {
assert.doesNotThrow(function () {
sharp().tile({
size: 8192,
overlap: overlap
@@ -79,9 +78,9 @@ describe('Tile', function() {
});
});
it('Invalid overlap values fail', function() {
['zoinks', 1.1, -1, 8193].forEach(function(overlap) {
assert.throws(function() {
it('Invalid overlap values fail', function () {
['zoinks', 1.1, -1, 8193].forEach(function (overlap) {
assert.throws(function () {
sharp().tile({
overlap: overlap
});
@@ -89,9 +88,9 @@ describe('Tile', function() {
});
});
it('Valid container values pass', function() {
['fs', 'zip'].forEach(function(container) {
assert.doesNotThrow(function() {
it('Valid container values pass', function () {
['fs', 'zip'].forEach(function (container) {
assert.doesNotThrow(function () {
sharp().tile({
container: container
});
@@ -99,9 +98,9 @@ describe('Tile', function() {
});
});
it('Invalid container values fail', function() {
['zoinks', 1].forEach(function(container) {
assert.throws(function() {
it('Invalid container values fail', function () {
['zoinks', 1].forEach(function (container) {
assert.throws(function () {
sharp().tile({
container: container
});
@@ -109,9 +108,9 @@ describe('Tile', function() {
});
});
it('Valid layout values pass', function() {
['dz', 'google', 'zoomify'].forEach(function(layout) {
assert.doesNotThrow(function() {
it('Valid layout values pass', function () {
['dz', 'google', 'zoomify'].forEach(function (layout) {
assert.doesNotThrow(function () {
sharp().tile({
layout: layout
});
@@ -119,9 +118,9 @@ describe('Tile', function() {
});
});
it('Invalid layout values fail', function() {
['zoinks', 1].forEach(function(layout) {
assert.throws(function() {
it('Invalid layout values fail', function () {
['zoinks', 1].forEach(function (layout) {
assert.throws(function () {
sharp().tile({
layout: layout
});
@@ -129,25 +128,24 @@ describe('Tile', function() {
});
});
it('Prevent larger overlap than default size', function() {
assert.throws(function() {
it('Prevent larger overlap than default size', function () {
assert.throws(function () {
sharp().tile({overlap: 257});
});
});
it('Prevent larger overlap than provided size', function() {
assert.throws(function() {
it('Prevent larger overlap than provided size', function () {
assert.throws(function () {
sharp().tile({size: 512, overlap: 513});
});
});
if (sharp.format.dz.output.file) {
it('Deep Zoom layout', function(done) {
var directory = fixtures.path('output.dzi_files');
rimraf(directory, function() {
it('Deep Zoom layout', function (done) {
const directory = fixtures.path('output.dzi_files');
rimraf(directory, function () {
sharp(fixtures.inputJpg)
.toFile(fixtures.path('output.dzi'), function(err, info) {
.toFile(fixtures.path('output.dzi'), function (err, info) {
if (err) throw err;
assert.strictEqual('dz', info.format);
assertDeepZoomTiles(directory, 256, 13, done);
@@ -155,15 +153,15 @@ describe('Tile', function() {
});
});
it('Deep Zoom layout with custom size+overlap', function(done) {
var directory = fixtures.path('output.512.dzi_files');
rimraf(directory, function() {
it('Deep Zoom layout with custom size+overlap', function (done) {
const directory = fixtures.path('output.512.dzi_files');
rimraf(directory, function () {
sharp(fixtures.inputJpg)
.tile({
size: 512,
overlap: 16
})
.toFile(fixtures.path('output.512.dzi'), function(err, info) {
.toFile(fixtures.path('output.512.dzi'), function (err, info) {
if (err) throw err;
assert.strictEqual('dz', info.format);
assertDeepZoomTiles(directory, 512 + 2 * 16, 13, done);
@@ -171,17 +169,17 @@ describe('Tile', function() {
});
});
it('Zoomify layout', function(done) {
var directory = fixtures.path('output.zoomify.dzi');
rimraf(directory, function() {
it('Zoomify layout', function (done) {
const directory = fixtures.path('output.zoomify.dzi');
rimraf(directory, function () {
sharp(fixtures.inputJpg)
.tile({
layout: 'zoomify'
})
.toFile(fixtures.path('output.zoomify.dzi'), function(err, info) {
.toFile(fixtures.path('output.zoomify.dzi'), function (err, info) {
if (err) throw err;
assert.strictEqual('dz', info.format);
fs.stat(path.join(directory, 'ImageProperties.xml'), function(err, stat) {
fs.stat(path.join(directory, 'ImageProperties.xml'), function (err, stat) {
if (err) throw err;
assert.strictEqual(true, stat.isFile());
assert.strictEqual(true, stat.size > 0);
@@ -191,17 +189,17 @@ describe('Tile', function() {
});
});
it('Google layout', function(done) {
var directory = fixtures.path('output.google.dzi');
rimraf(directory, function() {
it('Google layout', function (done) {
const directory = fixtures.path('output.google.dzi');
rimraf(directory, function () {
sharp(fixtures.inputJpg)
.tile({
layout: 'google'
})
.toFile(directory, function(err, info) {
.toFile(directory, function (err, info) {
if (err) throw err;
assert.strictEqual('dz', info.format);
fs.stat(path.join(directory, '0', '0', '0.jpg'), function(err, stat) {
fs.stat(path.join(directory, '0', '0', '0.jpg'), function (err, stat) {
if (err) throw err;
assert.strictEqual(true, stat.isFile());
assert.strictEqual(true, stat.size > 0);
@@ -211,23 +209,23 @@ describe('Tile', function() {
});
});
it('Write to ZIP container using file extension', function(done) {
var container = fixtures.path('output.dz.container.zip');
var extractTo = fixtures.path('output.dz.container');
var directory = path.join(extractTo, 'output.dz.container_files');
rimraf(directory, function() {
it('Write to ZIP container using file extension', function (done) {
const container = fixtures.path('output.dz.container.zip');
const extractTo = fixtures.path('output.dz.container');
const directory = path.join(extractTo, 'output.dz.container_files');
rimraf(directory, function () {
sharp(fixtures.inputJpg)
.toFile(container, function(err, info) {
.toFile(container, function (err, info) {
if (err) throw err;
assert.strictEqual('dz', info.format);
fs.stat(container, function(err, stat) {
fs.stat(container, function (err, stat) {
if (err) throw err;
assert.strictEqual(true, stat.isFile());
assert.strictEqual(true, stat.size > 0);
fs.createReadStream(container)
.pipe(unzip.Extract({path: path.dirname(extractTo)}))
.on('error', function(err) { throw err; })
.on('close', function() {
.on('error', function (err) { throw err; })
.on('close', function () {
assertDeepZoomTiles(directory, 256, 13, done);
});
});
@@ -235,34 +233,32 @@ describe('Tile', function() {
});
});
it('Write to ZIP container using container tile option', function(done) {
var container = fixtures.path('output.dz.containeropt.zip');
var extractTo = fixtures.path('output.dz.containeropt');
var directory = path.join(extractTo, 'output.dz.containeropt_files');
rimraf(directory, function() {
it('Write to ZIP container using container tile option', function (done) {
const container = fixtures.path('output.dz.containeropt.zip');
const extractTo = fixtures.path('output.dz.containeropt');
const directory = path.join(extractTo, 'output.dz.containeropt_files');
rimraf(directory, function () {
sharp(fixtures.inputJpg)
.tile({
container: 'zip'
})
.toFile(container, function(err, info) {
.toFile(container, function (err, info) {
// Vips overrides .dzi extension to .zip used by container var below
if (err) throw err;
assert.strictEqual('dz', info.format);
fs.stat(container, function(err, stat) {
fs.stat(container, function (err, stat) {
if (err) throw err;
assert.strictEqual(true, stat.isFile());
assert.strictEqual(true, stat.size > 0);
fs.createReadStream(container)
.pipe(unzip.Extract({path: path.dirname(extractTo)}))
.on('error', function(err) { throw err; })
.on('close', function() {
.on('error', function (err) { throw err; })
.on('close', function () {
assertDeepZoomTiles(directory, 256, 13, done);
});
});
});
});
});
}
});