Remove use of deprecated functions from test code

This commit is contained in:
Lovell Fuller 2016-11-04 10:18:25 +00:00
parent 55998707a5
commit deb978bf57
7 changed files with 254 additions and 238 deletions

View File

@ -14,6 +14,7 @@ let versions = {
(function () { (function () {
// Does libvips meet minimum requirement? // Does libvips meet minimum requirement?
const libvipsVersionMin = require('../package.json').config.libvips; const libvipsVersionMin = require('../package.json').config.libvips;
/* istanbul ignore if */
if (semver.lt(versions.vips, libvipsVersionMin)) { if (semver.lt(versions.vips, libvipsVersionMin)) {
throw new Error('Found libvips ' + versions.vips + ' but require at least ' + libvipsVersionMin); throw new Error('Found libvips ' + versions.vips + ' but require at least ' + libvipsVersionMin);
} }

View File

@ -60,7 +60,9 @@ const _createInputDescriptor = function _createInputDescriptor (input, inputOpti
* @param {Function} callback * @param {Function} callback
*/ */
const _write = function _write (chunk, encoding, callback) { const _write = function _write (chunk, encoding, callback) {
/* istanbul ignore else */
if (Array.isArray(this.options.input.buffer)) { if (Array.isArray(this.options.input.buffer)) {
/* istanbul ignore else */
if (is.buffer(chunk)) { if (is.buffer(chunk)) {
this.options.input.buffer.push(chunk); this.options.input.buffer.push(chunk);
callback(); callback();

View File

@ -91,6 +91,7 @@ const withMetadata = function withMetadata (withMetadata) {
* @param {Boolean} [trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg * @param {Boolean} [trellisQuantisation=false] - apply trellis quantisation, requires mozjpeg
* @param {Boolean} [overshootDeringing=false] - apply overshoot deringing, requires mozjpeg * @param {Boolean} [overshootDeringing=false] - apply overshoot deringing, requires mozjpeg
* @param {Boolean} [optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg * @param {Boolean} [optimiseScans=false] - optimise progressive scans, forces progressive, requires mozjpeg
* @param {Boolean} [optimizeScans=false] - alternative spelling of optimiseScans
* @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format * @param {Boolean} [options.force=true] - force JPEG output, otherwise attempt to use input format
* @returns {Sharp} * @returns {Sharp}
* @throws {Error} Invalid options * @throws {Error} Invalid options
@ -121,7 +122,7 @@ const jpeg = function jpeg (options) {
if (is.defined(options.overshootDeringing)) { if (is.defined(options.overshootDeringing)) {
this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing); this._setBooleanOption('jpegOvershootDeringing', options.overshootDeringing);
} }
options.optimiseScans = options.optimiseScans || options.optimizeScans; options.optimiseScans = is.bool(options.optimiseScans) ? options.optimiseScans : options.optimizeScans;
if (is.defined(options.optimiseScans)) { if (is.defined(options.optimiseScans)) {
this._setBooleanOption('jpegOptimiseScans', options.optimiseScans); this._setBooleanOption('jpegOptimiseScans', options.optimiseScans);
if (options.optimiseScans) { if (options.optimiseScans) {
@ -170,15 +171,13 @@ const png = function png (options) {
* @throws {Error} Invalid options * @throws {Error} Invalid options
*/ */
const webp = function webp (options) { const webp = function webp (options) {
if (is.object(options)) { if (is.object(options) && is.defined(options.quality)) {
if (is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) { if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
this.options.webpQuality = options.quality; this.options.webpQuality = options.quality;
} else { } else {
throw new Error('Invalid quality (integer, 1-100) ' + options.quality); throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
} }
} }
}
return this._updateFormatOut('webp', options); return this._updateFormatOut('webp', options);
}; };
@ -191,15 +190,13 @@ const webp = function webp (options) {
* @throws {Error} Invalid options * @throws {Error} Invalid options
*/ */
const tiff = function tiff (options) { const tiff = function tiff (options) {
if (is.object(options)) { if (is.object(options) && is.defined(options.quality)) {
if (is.defined(options.quality)) {
if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) { if (is.integer(options.quality) && is.inRange(options.quality, 1, 100)) {
this.options.tiffQuality = options.quality; this.options.tiffQuality = options.quality;
} else { } else {
throw new Error('Invalid quality (integer, 1-100) ' + options.quality); throw new Error('Invalid quality (integer, 1-100) ' + options.quality);
} }
} }
}
return this._updateFormatOut('tiff', options); return this._updateFormatOut('tiff', options);
}; };
@ -412,6 +409,7 @@ const _pipeline = function _pipeline (callback) {
}; };
// Deprecated output options // Deprecated output options
/* istanbul ignore next */
const quality = util.deprecate(function (quality) { const quality = util.deprecate(function (quality) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
const options = { quality: quality }; const options = { quality: quality };
@ -419,6 +417,7 @@ const quality = util.deprecate(function (quality) {
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'quality: use jpeg({ quality: ... }), webp({ quality: ... }) and/or tiff({ quality: ... }) instead'); }, 'quality: use jpeg({ quality: ... }), webp({ quality: ... }) and/or tiff({ quality: ... }) instead');
/* istanbul ignore next */
const progressive = util.deprecate(function (progressive) { const progressive = util.deprecate(function (progressive) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
const options = { progressive: (progressive !== false) }; const options = { progressive: (progressive !== false) };
@ -426,36 +425,42 @@ const progressive = util.deprecate(function (progressive) {
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'progressive: use jpeg({ progressive: ... }) and/or png({ progressive: ... }) instead'); }, 'progressive: use jpeg({ progressive: ... }) and/or png({ progressive: ... }) instead');
/* istanbul ignore next */
const compressionLevel = util.deprecate(function (compressionLevel) { const compressionLevel = util.deprecate(function (compressionLevel) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
this.png({ compressionLevel: compressionLevel }); this.png({ compressionLevel: compressionLevel });
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'compressionLevel: use png({ compressionLevel: ... }) instead'); }, 'compressionLevel: use png({ compressionLevel: ... }) instead');
/* istanbul ignore next */
const withoutAdaptiveFiltering = util.deprecate(function (withoutAdaptiveFiltering) { const withoutAdaptiveFiltering = util.deprecate(function (withoutAdaptiveFiltering) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
this.png({ adaptiveFiltering: (withoutAdaptiveFiltering === false) }); this.png({ adaptiveFiltering: (withoutAdaptiveFiltering === false) });
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'withoutAdaptiveFiltering: use png({ adaptiveFiltering: ... }) instead'); }, 'withoutAdaptiveFiltering: use png({ adaptiveFiltering: ... }) instead');
/* istanbul ignore next */
const withoutChromaSubsampling = util.deprecate(function (withoutChromaSubsampling) { const withoutChromaSubsampling = util.deprecate(function (withoutChromaSubsampling) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
this.jpeg({ chromaSubsampling: (withoutChromaSubsampling === false) ? '4:2:0' : '4:4:4' }); this.jpeg({ chromaSubsampling: (withoutChromaSubsampling === false) ? '4:2:0' : '4:4:4' });
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'withoutChromaSubsampling: use jpeg({ chromaSubsampling: "4:4:4" }) instead'); }, 'withoutChromaSubsampling: use jpeg({ chromaSubsampling: "4:4:4" }) instead');
/* istanbul ignore next */
const trellisQuantisation = util.deprecate(function (trellisQuantisation) { const trellisQuantisation = util.deprecate(function (trellisQuantisation) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
this.jpeg({ trellisQuantisation: (trellisQuantisation !== false) }); this.jpeg({ trellisQuantisation: (trellisQuantisation !== false) });
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'trellisQuantisation: use jpeg({ trellisQuantisation: ... }) instead'); }, 'trellisQuantisation: use jpeg({ trellisQuantisation: ... }) instead');
/* istanbul ignore next */
const overshootDeringing = util.deprecate(function (overshootDeringing) { const overshootDeringing = util.deprecate(function (overshootDeringing) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
this.jpeg({ overshootDeringing: (overshootDeringing !== false) }); this.jpeg({ overshootDeringing: (overshootDeringing !== false) });
this.options.formatOut = formatOut; this.options.formatOut = formatOut;
return this; return this;
}, 'overshootDeringing: use jpeg({ overshootDeringing: ... }) instead'); }, 'overshootDeringing: use jpeg({ overshootDeringing: ... }) instead');
/* istanbul ignore next */
const optimiseScans = util.deprecate(function (optimiseScans) { const optimiseScans = util.deprecate(function (optimiseScans) {
const formatOut = this.options.formatOut; const formatOut = this.options.formatOut;
this.jpeg({ optimiseScans: (optimiseScans !== false) }); this.jpeg({ optimiseScans: (optimiseScans !== false) });

View File

@ -32,7 +32,7 @@
], ],
"scripts": { "scripts": {
"clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*", "clean": "rm -rf node_modules/ build/ vendor/ coverage/ test/fixtures/output.*",
"test": "semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=96 mocha --slow=5000 --timeout=60000 ./test/unit/*.js", "test": "semistandard && cross-env VIPS_WARNING=0 nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
"test-leak": "./test/leak/leak.sh", "test-leak": "./test/leak/leak.sh",
"test-packaging": "./packaging/test-linux-x64.sh", "test-packaging": "./packaging/test-linux-x64.sh",
"docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done" "docs": "for m in constructor input resize composite operation colour channel output utility; do documentation build --shallow --format=md lib/$m.js >docs/api-$m.md; done"

View File

@ -140,7 +140,7 @@ make install
mkdir ${DEPS}/fontconfig mkdir ${DEPS}/fontconfig
curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1 curl -Ls https://www.freedesktop.org/software/fontconfig/release/fontconfig-${VERSION_FONTCONFIG}.tar.bz2 | tar xjC ${DEPS}/fontconfig --strip-components=1
cd ${DEPS}/fontconfig cd ${DEPS}/fontconfig
./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --enable-libxml2 ./configure --host=${CHOST} --prefix=${TARGET} --enable-shared --disable-static --disable-dependency-tracking --enable-libxml2 --sysconfdir=/etc
make install-strip make install-strip
mkdir ${DEPS}/harfbuzz mkdir ${DEPS}/harfbuzz

View File

@ -17,7 +17,7 @@ describe('Colour space conversion', function () {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.gamma() .gamma()
.greyscale() .grayscale()
.toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done); .toFile(fixtures.path('output.greyscale-gamma-2.2.jpg'), done);
}); });

View File

@ -266,28 +266,26 @@ describe('Input/output', function () {
}); });
}); });
it('Promises/A+', function (done) { it('Promises/A+', function () {
sharp(fixtures.inputJpg).resize(320, 240).toBuffer().then(function (data) { return sharp(fixtures.inputJpg)
sharp(data).toBuffer(function (err, data, info) { .resize(320, 240)
if (err) throw err; .toBuffer();
assert.strictEqual(true, data.length > 0);
assert.strictEqual(data.length, info.size);
assert.strictEqual('jpeg', info.format);
assert.strictEqual(320, info.width);
assert.strictEqual(240, info.height);
done();
});
}).catch(function (err) {
throw err;
});
}); });
it('JPEG quality', function (done) { it('JPEG quality', function (done) {
sharp(fixtures.inputJpg).resize(320, 240).quality(70).toBuffer(function (err, buffer70) { sharp(fixtures.inputJpg)
.resize(320, 240)
.jpeg({ quality: 70 })
.toBuffer(function (err, buffer70) {
if (err) throw err; if (err) throw err;
sharp(fixtures.inputJpg).resize(320, 240).toBuffer(function (err, buffer80) { sharp(fixtures.inputJpg)
.resize(320, 240)
.toBuffer(function (err, buffer80) {
if (err) throw err; if (err) throw err;
sharp(fixtures.inputJpg).resize(320, 240).quality(90).toBuffer(function (err, buffer90) { sharp(fixtures.inputJpg)
.resize(320, 240)
.jpeg({ quality: 90 })
.toBuffer(function (err, buffer90) {
if (err) throw err; if (err) throw err;
assert(buffer70.length < buffer80.length); assert(buffer70.length < buffer80.length);
assert(buffer80.length < buffer90.length); assert(buffer80.length < buffer90.length);
@ -297,28 +295,20 @@ describe('Input/output', function () {
}); });
}); });
describe('Invalid quality', function () { describe('Invalid JPEG quality', function () {
it('Negative integer', function () { [-1, 88.2, 'test'].forEach(function (quality) {
it(quality.toString(), function () {
assert.throws(function () { assert.throws(function () {
sharp(fixtures.inputJpg).quality(-1); sharp().jpeg({ quality: quality });
}); });
}); });
it('Non integral', function () {
assert.throws(function () {
sharp(fixtures.inputJpg).quality(88.2);
});
});
it('String', function () {
assert.throws(function () {
sharp(fixtures.inputJpg).quality('test');
});
}); });
}); });
it('Progressive JPEG image', function (done) { it('Progressive JPEG image', function (done) {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.progressive(false) .jpeg({ progressive: false })
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) { .toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, nonProgressiveData.length > 0); assert.strictEqual(true, nonProgressiveData.length > 0);
@ -328,7 +318,7 @@ describe('Input/output', function () {
assert.strictEqual(240, nonProgressiveInfo.height); assert.strictEqual(240, nonProgressiveInfo.height);
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.progressive() .jpeg({ progressive: true })
.toBuffer(function (err, progressiveData, progressiveInfo) { .toBuffer(function (err, progressiveData, progressiveInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, progressiveData.length > 0); assert.strictEqual(true, progressiveData.length > 0);
@ -345,8 +335,7 @@ describe('Input/output', function () {
it('Progressive PNG image', function (done) { it('Progressive PNG image', function (done) {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.png() .png({ progressive: false })
.progressive(false)
.toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) { .toBuffer(function (err, nonProgressiveData, nonProgressiveInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, nonProgressiveData.length > 0); assert.strictEqual(true, nonProgressiveData.length > 0);
@ -355,7 +344,7 @@ describe('Input/output', function () {
assert.strictEqual(320, nonProgressiveInfo.width); assert.strictEqual(320, nonProgressiveInfo.width);
assert.strictEqual(240, nonProgressiveInfo.height); assert.strictEqual(240, nonProgressiveInfo.height);
sharp(nonProgressiveData) sharp(nonProgressiveData)
.progressive() .png({ progressive: true })
.toBuffer(function (err, progressiveData, progressiveInfo) { .toBuffer(function (err, progressiveData, progressiveInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, progressiveData.length > 0); assert.strictEqual(true, progressiveData.length > 0);
@ -440,7 +429,6 @@ describe('Input/output', function () {
}); });
}); });
if (sharp.format.webp.input.file) {
it('Match WebP input', function (done) { it('Match WebP input', function (done) {
sharp(fixtures.inputWebP) sharp(fixtures.inputWebP)
.resize(320, 80) .resize(320, 80)
@ -454,9 +442,7 @@ describe('Input/output', function () {
done(); done();
}); });
}); });
}
if (sharp.format.tiff.input.file) {
it('Match TIFF input', function (done) { it('Match TIFF input', function (done) {
sharp(fixtures.inputTiff) sharp(fixtures.inputTiff)
.resize(320, 80) .resize(320, 80)
@ -470,7 +456,6 @@ describe('Input/output', function () {
done(); done();
}); });
}); });
}
it('Match GIF input, therefore fail', function (done) { it('Match GIF input, therefore fail', function (done) {
sharp(fixtures.inputGif) sharp(fixtures.inputGif)
@ -498,31 +483,23 @@ describe('Input/output', function () {
}); });
describe('PNG output', function () { describe('PNG output', function () {
it('compression level is valid', function (done) { it('compression level is valid', function () {
let isValid = false; assert.doesNotThrow(function () {
try { sharp().png({ compressionLevel: 0 });
sharp().compressionLevel(0); });
isValid = true;
} catch (e) {}
assert(isValid);
done();
}); });
it('compression level is invalid', function (done) { it('compression level is invalid', function () {
let isValid = false; assert.throws(function () {
try { sharp().png({ compressionLevel: -1 });
sharp().compressionLevel(-1); });
isValid = true;
} catch (e) {}
assert(!isValid);
done();
}); });
it('withoutAdaptiveFiltering generates smaller file', function (done) { it('without adaptiveFiltering generates smaller file', function (done) {
// First generate with adaptive filtering // First generate with adaptive filtering
sharp(fixtures.inputPng) sharp(fixtures.inputPng)
.resize(320, 240) .resize(320, 240)
.withoutAdaptiveFiltering(false) .png({ adaptiveFiltering: true })
.toBuffer(function (err, adaptiveData, adaptiveInfo) { .toBuffer(function (err, adaptiveData, adaptiveInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, adaptiveData.length > 0); assert.strictEqual(true, adaptiveData.length > 0);
@ -533,7 +510,7 @@ describe('Input/output', function () {
// Then generate without // Then generate without
sharp(fixtures.inputPng) sharp(fixtures.inputPng)
.resize(320, 240) .resize(320, 240)
.withoutAdaptiveFiltering() .png({ adaptiveFiltering: false })
.toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) { .toBuffer(function (err, withoutAdaptiveData, withoutAdaptiveInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withoutAdaptiveData.length > 0); assert.strictEqual(true, withoutAdaptiveData.length > 0);
@ -546,13 +523,19 @@ describe('Input/output', function () {
}); });
}); });
}); });
it('Invalid PNG adaptiveFiltering value throws error', function () {
assert.throws(function () {
sharp().png({ adaptiveFiltering: 1 });
});
});
}); });
it('Without chroma subsampling generates larger file', function (done) { it('Without chroma subsampling generates larger file', function (done) {
// First generate with chroma subsampling (default) // First generate with chroma subsampling (default)
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.withoutChromaSubsampling(false) .jpeg({ chromaSubsampling: '4:2:0' })
.toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) { .toBuffer(function (err, withChromaSubsamplingData, withChromaSubsamplingInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withChromaSubsamplingData.length > 0); assert.strictEqual(true, withChromaSubsamplingData.length > 0);
@ -563,7 +546,7 @@ describe('Input/output', function () {
// Then generate without // Then generate without
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.withoutChromaSubsampling() .jpeg({ chromaSubsampling: '4:4:4' })
.toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) { .toBuffer(function (err, withoutChromaSubsamplingData, withoutChromaSubsamplingInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withoutChromaSubsamplingData.length > 0); assert.strictEqual(true, withoutChromaSubsamplingData.length > 0);
@ -577,11 +560,17 @@ describe('Input/output', function () {
}); });
}); });
it('Invalid JPEG chromaSubsampling value throws error', function () {
assert.throws(function () {
sharp().jpeg({ chromaSubsampling: '4:2:2' });
});
});
it('Trellis quantisation', function (done) { it('Trellis quantisation', function (done) {
// First generate without // First generate without
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.trellisQuantisation(false) .jpeg({ trellisQuantisation: false })
.toBuffer(function (err, withoutData, withoutInfo) { .toBuffer(function (err, withoutData, withoutInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withoutData.length > 0); assert.strictEqual(true, withoutData.length > 0);
@ -592,7 +581,7 @@ describe('Input/output', function () {
// Then generate with // Then generate with
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.trellisQuantization() .jpeg({ trellisQuantization: true })
.toBuffer(function (err, withData, withInfo) { .toBuffer(function (err, withData, withInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withData.length > 0); assert.strictEqual(true, withData.length > 0);
@ -611,7 +600,7 @@ describe('Input/output', function () {
// First generate without // First generate without
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.overshootDeringing(false) .jpeg({ overshootDeringing: false })
.toBuffer(function (err, withoutData, withoutInfo) { .toBuffer(function (err, withoutData, withoutInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withoutData.length > 0); assert.strictEqual(true, withoutData.length > 0);
@ -622,7 +611,7 @@ describe('Input/output', function () {
// Then generate with // Then generate with
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.overshootDeringing() .jpeg({ overshootDeringing: true })
.toBuffer(function (err, withData, withInfo) { .toBuffer(function (err, withData, withInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withData.length > 0); assert.strictEqual(true, withData.length > 0);
@ -635,11 +624,11 @@ describe('Input/output', function () {
}); });
}); });
it('Optimise scans', function (done) { it('Optimise scans generates different output length', function (done) {
// First generate without // First generate without
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.optimiseScans(false) .jpeg({ optimiseScans: false })
.toBuffer(function (err, withoutData, withoutInfo) { .toBuffer(function (err, withoutData, withoutInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withoutData.length > 0); assert.strictEqual(true, withoutData.length > 0);
@ -650,7 +639,7 @@ describe('Input/output', function () {
// Then generate with // Then generate with
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.resize(320, 240) .resize(320, 240)
.optimizeScans() .jpeg({ optimizeScans: true })
.toBuffer(function (err, withData, withInfo) { .toBuffer(function (err, withData, withInfo) {
if (err) throw err; if (err) throw err;
assert.strictEqual(true, withData.length > 0); assert.strictEqual(true, withData.length > 0);
@ -720,7 +709,6 @@ describe('Input/output', function () {
}); });
}); });
if (sharp.format.tiff.input.buffer) {
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);
sharp(inputTiffBuffer) sharp(inputTiffBuffer)
@ -736,9 +724,38 @@ describe('Input/output', function () {
done(); done();
}); });
}); });
}
if (sharp.format.gif.input.buffer) { it('Invalid WebP quality throws error', function () {
assert.throws(function () {
sharp().webp({ quality: 101 });
});
});
it('Invalid TIFF quality throws error', function () {
assert.throws(function () {
sharp().tiff({ quality: 101 });
});
});
it('Missing TIFF quality does not throw error', function () {
assert.doesNotThrow(function () {
sharp().tiff();
});
});
it('Input and output formats match when not forcing', function (done) {
sharp(fixtures.inputJpg)
.resize(320, 240)
.png({ compressionLevel: 1, force: 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);
done();
});
});
it('Load GIF from Buffer', function (done) { it('Load GIF from Buffer', function (done) {
const inputGifBuffer = fs.readFileSync(fixtures.inputGif); const inputGifBuffer = fs.readFileSync(fixtures.inputGif);
sharp(inputGifBuffer) sharp(inputGifBuffer)
@ -754,9 +771,7 @@ describe('Input/output', function () {
done(); done();
}); });
}); });
}
if (sharp.format.gif.input.file) {
it('Load GIF grey+alpha from file', function (done) { it('Load GIF grey+alpha from file', function (done) {
sharp(fixtures.inputGifGreyPlusAlpha) sharp(fixtures.inputGifGreyPlusAlpha)
.resize(8, 4) .resize(8, 4)
@ -772,9 +787,7 @@ describe('Input/output', function () {
done(); done();
}); });
}); });
}
if (sharp.format.v.input.file) {
it('Load Vips V file', function (done) { it('Load Vips V file', function (done) {
sharp(fixtures.inputV) sharp(fixtures.inputV)
.jpeg() .jpeg()
@ -787,9 +800,7 @@ describe('Input/output', function () {
fixtures.assertSimilar(fixtures.expected('vfile.jpg'), data, done); fixtures.assertSimilar(fixtures.expected('vfile.jpg'), data, done);
}); });
}); });
}
if (sharp.format.v.output.file) {
it('Save Vips V file', function (done) { it('Save Vips V file', function (done) {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
.extract({left: 910, top: 1105, width: 70, height: 60}) .extract({left: 910, top: 1105, width: 70, height: 60})
@ -803,9 +814,7 @@ describe('Input/output', function () {
done(); done();
}); });
}); });
}
if (sharp.format.raw.output.buffer) {
describe('Ouput raw, uncompressed image data', function () { describe('Ouput raw, uncompressed image data', function () {
it('1 channel greyscale image', function (done) { it('1 channel greyscale image', function (done) {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)
@ -851,7 +860,6 @@ describe('Input/output', function () {
}); });
}); });
}); });
}
describe('Limit pixel count of input image', function () { describe('Limit pixel count of input image', function () {
it('Invalid fails - negative', function (done) { it('Invalid fails - negative', function (done) {