mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 18:40:16 +02:00
Tests: refactor output paths, might enable parallel runs
This commit is contained in:
parent
24d9e53c3f
commit
67213ae86c
@ -15,6 +15,10 @@ const jimp = require('jimp');
|
|||||||
|
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
const outputJpg = fixtures.path('output.jpg');
|
||||||
|
const outputPng = fixtures.path('output.png');
|
||||||
|
const outputWebP = fixtures.path('output.webp');
|
||||||
|
|
||||||
const width = 720;
|
const width = 720;
|
||||||
const height = 588;
|
const height = 588;
|
||||||
|
|
||||||
@ -56,7 +60,7 @@ async.series({
|
|||||||
image
|
image
|
||||||
.resize(width, height, jimp.RESIZE_BICUBIC)
|
.resize(width, height, jimp.RESIZE_BICUBIC)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -77,7 +81,7 @@ async.series({
|
|||||||
.resize(width, height, {
|
.resize(width, height, {
|
||||||
scaling_method: mapnik.imageScaling.lanczos
|
scaling_method: mapnik.imageScaling.lanczos
|
||||||
})
|
})
|
||||||
.save(fixtures.outputJpg, 'jpeg:quality=80', function (err) {
|
.save(outputJpg, 'jpeg:quality=80', function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
@ -105,7 +109,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputJpg,
|
srcPath: fixtures.inputJpg,
|
||||||
dstPath: fixtures.outputJpg,
|
dstPath: outputJpg,
|
||||||
quality: 0.8,
|
quality: 0.8,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
@ -128,7 +132,7 @@ async.series({
|
|||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -159,7 +163,7 @@ async.series({
|
|||||||
.filter('Lanczos')
|
.filter('Lanczos')
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.quality(80)
|
.quality(80)
|
||||||
.write(fixtures.outputJpg, function (err) {
|
.write(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -190,7 +194,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputJpgBuffer)
|
sharp(inputJpgBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputJpg, function (err) {
|
.toFile(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -217,7 +221,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputJpg, function (err) {
|
.toFile(outputJpg, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -229,7 +233,7 @@ async.series({
|
|||||||
defer: true,
|
defer: true,
|
||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('finish', function () {
|
writable.on('finish', function () {
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
@ -600,7 +604,7 @@ async.series({
|
|||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.deflateLevel(6)
|
.deflateLevel(6)
|
||||||
.filterType(0)
|
.filterType(0)
|
||||||
.write(fixtures.outputPng, function (err) {
|
.write(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -625,7 +629,7 @@ async.series({
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
img.demultiply(function (err, img) {
|
img.demultiply(function (err, img) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
img.save(fixtures.outputPng, 'png', function (err) {
|
img.save(outputPng, 'png', function (err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
});
|
});
|
||||||
@ -663,7 +667,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputPngAlphaPremultiplicationLarge,
|
srcPath: fixtures.inputPngAlphaPremultiplicationLarge,
|
||||||
dstPath: fixtures.outputPng,
|
dstPath: outputPng,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
filter: 'Lanczos',
|
filter: 'Lanczos',
|
||||||
@ -689,7 +693,7 @@ async.series({
|
|||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.define('PNG:compression-level=6')
|
.define('PNG:compression-level=6')
|
||||||
.define('PNG:compression-filter=0')
|
.define('PNG:compression-filter=0')
|
||||||
.write(fixtures.outputPng, function (err) {
|
.write(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -723,7 +727,7 @@ async.series({
|
|||||||
sharp(inputPngBuffer)
|
sharp(inputPngBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.png({ compressionLevel: 6 })
|
.png({ compressionLevel: 6 })
|
||||||
.toFile(fixtures.outputPng, function (err) {
|
.toFile(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -754,7 +758,7 @@ async.series({
|
|||||||
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
sharp(fixtures.inputPngAlphaPremultiplicationLarge)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.png({ compressionLevel: 6 })
|
.png({ compressionLevel: 6 })
|
||||||
.toFile(fixtures.outputPng, function (err) {
|
.toFile(outputPng, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -841,7 +845,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(inputWebPBuffer)
|
sharp(inputWebPBuffer)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputWebP, function (err) {
|
.toFile(outputWebP, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
@ -868,7 +872,7 @@ async.series({
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(width, height)
|
.resize(width, height)
|
||||||
.toFile(fixtures.outputWebP, function (err) {
|
.toFile(outputWebP, function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,7 +23,7 @@ new Benchmark.Suite('random').add('imagemagick', {
|
|||||||
fn: function (deferred) {
|
fn: function (deferred) {
|
||||||
imagemagick.resize({
|
imagemagick.resize({
|
||||||
srcPath: fixtures.inputJpg,
|
srcPath: fixtures.inputJpg,
|
||||||
dstPath: fixtures.outputJpg,
|
dstPath: fixtures.path('output.jpg'),
|
||||||
quality: 0.8,
|
quality: 0.8,
|
||||||
width: randomDimension(),
|
width: randomDimension(),
|
||||||
height: randomDimension(),
|
height: randomDimension(),
|
||||||
|
7
test/fixtures/index.js
vendored
7
test/fixtures/index.js
vendored
@ -120,13 +120,6 @@ module.exports = {
|
|||||||
|
|
||||||
inputV: getPath('vfile.v'),
|
inputV: getPath('vfile.v'),
|
||||||
|
|
||||||
outputJpg: getPath('output.jpg'),
|
|
||||||
outputPng: getPath('output.png'),
|
|
||||||
outputWebP: getPath('output.webp'),
|
|
||||||
outputV: getPath('output.v'),
|
|
||||||
outputTiff: getPath('output.tiff'),
|
|
||||||
outputZoinks: getPath('output.zoinks'), // an 'unknown' file extension
|
|
||||||
|
|
||||||
testPattern: getPath('test-pattern.png'),
|
testPattern: getPath('test-pattern.png'),
|
||||||
|
|
||||||
// Path for tests requiring human inspection
|
// Path for tests requiring human inspection
|
||||||
|
@ -7,6 +7,8 @@ const rimraf = require('rimraf');
|
|||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
const outputJpg = fixtures.path('output.jpg');
|
||||||
|
|
||||||
describe('Input/output', function () {
|
describe('Input/output', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
sharp.cache(false);
|
sharp.cache(false);
|
||||||
@ -16,16 +18,16 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Read from File and write to Stream', function (done) {
|
it('Read from File and write to Stream', function (done) {
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
sharp(fixtures.inputJpg).resize(320, 240).pipe(writable);
|
sharp(fixtures.inputJpg).resize(320, 240).pipe(writable);
|
||||||
@ -33,16 +35,16 @@ describe('Input/output', function () {
|
|||||||
|
|
||||||
it('Read from Buffer and write to Stream', function (done) {
|
it('Read from Buffer and write to Stream', function (done) {
|
||||||
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
const inputJpgBuffer = fs.readFileSync(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
sharp(inputJpgBuffer).resize(320, 240).pipe(writable);
|
sharp(inputJpgBuffer).resize(320, 240).pipe(writable);
|
||||||
@ -50,13 +52,13 @@ describe('Input/output', function () {
|
|||||||
|
|
||||||
it('Read from Stream and write to File', function (done) {
|
it('Read from Stream and write to File', function (done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const pipeline = sharp().resize(320, 240).toFile(fixtures.outputJpg, function (err, info) {
|
const pipeline = sharp().resize(320, 240).toFile(outputJpg, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
readable.pipe(pipeline);
|
readable.pipe(pipeline);
|
||||||
});
|
});
|
||||||
@ -131,16 +133,16 @@ describe('Input/output', function () {
|
|||||||
|
|
||||||
it('Read from Stream and write to Stream', function (done) {
|
it('Read from Stream and write to Stream', function (done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
@ -181,7 +183,7 @@ describe('Input/output', function () {
|
|||||||
|
|
||||||
it('Stream should emit info event', function (done) {
|
it('Stream should emit info event', function (done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
let infoEventEmitted = false;
|
let infoEventEmitted = false;
|
||||||
pipeline.on('info', function (info) {
|
pipeline.on('info', function (info) {
|
||||||
@ -193,7 +195,7 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
assert.strictEqual(true, infoEventEmitted);
|
assert.strictEqual(true, infoEventEmitted);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
readable.pipe(pipeline).pipe(writable);
|
readable.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
@ -205,10 +207,10 @@ describe('Input/output', function () {
|
|||||||
anErrorWasEmitted = !!err;
|
anErrorWasEmitted = !!err;
|
||||||
}).on('end', function () {
|
}).on('end', function () {
|
||||||
assert(anErrorWasEmitted);
|
assert(anErrorWasEmitted);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
const readableButNotAnImage = fs.createReadStream(__filename);
|
const readableButNotAnImage = fs.createReadStream(__filename);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
readableButNotAnImage.pipe(pipeline).pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -219,24 +221,24 @@ describe('Input/output', function () {
|
|||||||
anErrorWasEmitted = !!err;
|
anErrorWasEmitted = !!err;
|
||||||
}).on('end', function () {
|
}).on('end', function () {
|
||||||
assert(anErrorWasEmitted);
|
assert(anErrorWasEmitted);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
readableButNotAnImage.pipe(writable);
|
readableButNotAnImage.pipe(writable);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Readable side of Stream can start flowing after Writable side has finished', function (done) {
|
it('Readable side of Stream can start flowing after Writable side has finished', function (done) {
|
||||||
const readable = fs.createReadStream(fixtures.inputJpg);
|
const readable = fs.createReadStream(fixtures.inputJpg);
|
||||||
const writable = fs.createWriteStream(fixtures.outputJpg);
|
const writable = fs.createWriteStream(outputJpg);
|
||||||
writable.on('close', function () {
|
writable.on('close', function () {
|
||||||
sharp(fixtures.outputJpg).toBuffer(function (err, data, info) {
|
sharp(outputJpg).toBuffer(function (err, data, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, data.length > 0);
|
assert.strictEqual(true, data.length > 0);
|
||||||
assert.strictEqual(data.length, info.size);
|
assert.strictEqual(data.length, info.size);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(240, info.height);
|
assert.strictEqual(240, info.height);
|
||||||
rimraf(fixtures.outputJpg, done);
|
rimraf(outputJpg, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const pipeline = sharp().resize(320, 240);
|
const pipeline = sharp().resize(320, 240);
|
||||||
@ -443,68 +445,70 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('Output filename with unknown extension', function () {
|
describe('Output filename with unknown extension', function () {
|
||||||
|
const outputZoinks = fixtures.path('output.zoinks');
|
||||||
|
|
||||||
it('Match JPEG input', function (done) {
|
it('Match JPEG input', function (done) {
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(outputZoinks, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Match PNG input', function (done) {
|
it('Match PNG input', function (done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('png', info.format);
|
assert.strictEqual('png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(outputZoinks, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Match WebP input', function (done) {
|
it('Match WebP input', function (done) {
|
||||||
sharp(fixtures.inputWebP)
|
sharp(fixtures.inputWebP)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(outputZoinks, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Match TIFF input', function (done) {
|
it('Match TIFF input', function (done) {
|
||||||
sharp(fixtures.inputTiff)
|
sharp(fixtures.inputTiff)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(outputZoinks, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Autoconvert GIF input to PNG output', function (done) {
|
it('Autoconvert GIF input to PNG output', function (done) {
|
||||||
sharp(fixtures.inputGif)
|
sharp(fixtures.inputGif)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual(sharp.format.magick.input.buffer ? 'gif' : 'png', info.format);
|
assert.strictEqual(sharp.format.magick.input.buffer ? 'gif' : 'png', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(outputZoinks, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -512,13 +516,13 @@ describe('Input/output', function () {
|
|||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.resize(320, 80)
|
.resize(320, 80)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toFile(fixtures.outputZoinks, function (err, info) {
|
.toFile(outputZoinks, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
assert.strictEqual(320, info.width);
|
assert.strictEqual(320, info.width);
|
||||||
assert.strictEqual(80, info.height);
|
assert.strictEqual(80, info.height);
|
||||||
rimraf(fixtures.outputZoinks, done);
|
rimraf(outputZoinks, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -548,19 +552,20 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('toFormat=JPEG takes precedence over WebP extension', function (done) {
|
it('toFormat=JPEG takes precedence over WebP extension', function (done) {
|
||||||
|
const outputWebP = fixtures.path('output.webp');
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.jpeg()
|
.jpeg()
|
||||||
.toFile(fixtures.outputWebP, function (err, info) {
|
.toFile(outputWebP, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('jpeg', info.format);
|
assert.strictEqual('jpeg', info.format);
|
||||||
done();
|
rimraf(outputWebP, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('toFormat=WebP takes precedence over JPEG extension', function (done) {
|
it('toFormat=WebP takes precedence over JPEG extension', function (done) {
|
||||||
sharp(fixtures.inputPng)
|
sharp(fixtures.inputPng)
|
||||||
.webp()
|
.webp()
|
||||||
.toFile(fixtures.outputJpg, function (err, info) {
|
.toFile(outputJpg, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('webp', info.format);
|
assert.strictEqual('webp', info.format);
|
||||||
done();
|
done();
|
||||||
@ -581,15 +586,16 @@ describe('Input/output', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('Save Vips V file', function (done) {
|
it('Save Vips V file', function (done) {
|
||||||
|
const outputV = fixtures.path('output.v');
|
||||||
sharp(fixtures.inputJpg)
|
sharp(fixtures.inputJpg)
|
||||||
.extract({ left: 910, top: 1105, width: 70, height: 60 })
|
.extract({ left: 910, top: 1105, width: 70, height: 60 })
|
||||||
.toFile(fixtures.outputV, function (err, info) {
|
.toFile(outputV, function (err, info) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual(true, info.size > 0);
|
assert.strictEqual(true, info.size > 0);
|
||||||
assert.strictEqual('v', info.format);
|
assert.strictEqual('v', info.format);
|
||||||
assert.strictEqual(70, info.width);
|
assert.strictEqual(70, info.width);
|
||||||
assert.strictEqual(60, info.height);
|
assert.strictEqual(60, info.height);
|
||||||
rimraf(fixtures.outputV, done);
|
rimraf(outputV, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ const rimraf = require('rimraf');
|
|||||||
const sharp = require('../../');
|
const sharp = require('../../');
|
||||||
const fixtures = require('../fixtures');
|
const fixtures = require('../fixtures');
|
||||||
|
|
||||||
|
const outputTiff = fixtures.path('output.tiff');
|
||||||
|
|
||||||
describe('TIFF', function () {
|
describe('TIFF', function () {
|
||||||
it('Load TIFF from Buffer', function (done) {
|
it('Load TIFF from Buffer', function (done) {
|
||||||
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
const inputTiffBuffer = fs.readFileSync(fixtures.inputTiff);
|
||||||
@ -120,11 +122,11 @@ describe('TIFF', function () {
|
|||||||
compression: 'none',
|
compression: 'none',
|
||||||
predictor: 'none'
|
predictor: 'none'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert.strictEqual(startSize, info.size);
|
assert.strictEqual(startSize, info.size);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -137,11 +139,11 @@ describe('TIFF', function () {
|
|||||||
compression: 'none',
|
compression: 'none',
|
||||||
predictor: 'none'
|
predictor: 'none'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size < (startSize / 2));
|
assert(info.size < (startSize / 2));
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -157,12 +159,12 @@ describe('TIFF', function () {
|
|||||||
xres: 1000,
|
xres: 1000,
|
||||||
yres: 1000
|
yres: 1000
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff)
|
.toFile(outputTiff)
|
||||||
.then(() => sharp(fixtures.outputTiff)
|
.then(() => sharp(outputTiff)
|
||||||
.metadata()
|
.metadata()
|
||||||
.then(({ density }) => {
|
.then(({ density }) => {
|
||||||
assert.strictEqual(25400, density);
|
assert.strictEqual(25400, density);
|
||||||
return promisify(rimraf)(fixtures.outputTiff);
|
return promisify(rimraf)(outputTiff);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -201,12 +203,12 @@ describe('TIFF', function () {
|
|||||||
compression: 'lzw',
|
compression: 'lzw',
|
||||||
predictor: 'horizontal'
|
predictor: 'horizontal'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert.strictEqual(3, info.channels);
|
assert.strictEqual(3, info.channels);
|
||||||
assert(info.size < startSize);
|
assert(info.size < startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -222,7 +224,7 @@ describe('TIFF', function () {
|
|||||||
.tiff({
|
.tiff({
|
||||||
compression: 'lzw'
|
compression: 'lzw'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff)
|
.toFile(outputTiff)
|
||||||
.then(info => {
|
.then(info => {
|
||||||
assert.strictEqual(4, info.channels);
|
assert.strictEqual(4, info.channels);
|
||||||
})
|
})
|
||||||
@ -254,11 +256,11 @@ describe('TIFF', function () {
|
|||||||
bitdepth: 1,
|
bitdepth: 1,
|
||||||
compression: 'ccittfax4'
|
compression: 'ccittfax4'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size < startSize);
|
assert(info.size < startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -269,11 +271,11 @@ describe('TIFF', function () {
|
|||||||
compression: 'deflate',
|
compression: 'deflate',
|
||||||
predictor: 'horizontal'
|
predictor: 'horizontal'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size < startSize);
|
assert(info.size < startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -284,11 +286,11 @@ describe('TIFF', function () {
|
|||||||
compression: 'deflate',
|
compression: 'deflate',
|
||||||
predictor: 'float'
|
predictor: 'float'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size > startSize);
|
assert(info.size > startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -299,11 +301,11 @@ describe('TIFF', function () {
|
|||||||
compression: 'deflate',
|
compression: 'deflate',
|
||||||
predictor: 'none'
|
predictor: 'none'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size < startSize);
|
assert(info.size < startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -313,11 +315,11 @@ describe('TIFF', function () {
|
|||||||
.tiff({
|
.tiff({
|
||||||
compression: 'jpeg'
|
compression: 'jpeg'
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size < startSize);
|
assert(info.size < startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -385,11 +387,11 @@ describe('TIFF', function () {
|
|||||||
tileHeight: 256,
|
tileHeight: 256,
|
||||||
tileWidth: 256
|
tileWidth: 256
|
||||||
})
|
})
|
||||||
.toFile(fixtures.outputTiff, (err, info) => {
|
.toFile(outputTiff, (err, info) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
assert.strictEqual('tiff', info.format);
|
assert.strictEqual('tiff', info.format);
|
||||||
assert(info.size > startSize);
|
assert(info.size > startSize);
|
||||||
rimraf(fixtures.outputTiff, done);
|
rimraf(outputTiff, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user