mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Increase unit test coverage for recently added operations
Switch param validation to use internal functions
This commit is contained in:
@@ -54,9 +54,9 @@ describe('Boolean operation between two images', function() {
|
||||
});
|
||||
});
|
||||
|
||||
if('Invalid input', function() {
|
||||
it('Missing input', function() {
|
||||
assert.throws(function() {
|
||||
sharp().boolean([], 'eor');
|
||||
sharp().boolean();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -400,17 +400,27 @@ describe('Overlays', function() {
|
||||
assert.strictEqual(3, info.channels);
|
||||
fixtures.assertSimilar(expected, data, done);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('Overlay with invalid cutout option', function() {
|
||||
assert.throws(function() {
|
||||
sharp().overlayWith('ignore', { cutout: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with invalid tile option', function() {
|
||||
assert.throws(function() {
|
||||
sharp().overlayWith('ignore', { tile: 1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Overlay with very large offset', function(done) {
|
||||
var expected = fixtures.expected('overlay-very-large-offset.jpg');
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(400)
|
||||
.overlayWith(fixtures.inputPngWithTransparency16bit, {
|
||||
left: 1000000,
|
||||
top: 100000
|
||||
left: 10000,
|
||||
top: 10000
|
||||
})
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Threshold', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold true (=128)', function(done) {
|
||||
it('threshold true (=128)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(true)
|
||||
@@ -52,21 +52,28 @@ describe('Threshold', function() {
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('threshold false (=0)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.threshold(false)
|
||||
.toBuffer(function(err, data, info) {
|
||||
fixtures.assertSimilar(fixtures.inputJpg, data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('threshold grayscale: true (=128)', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
.threshold(128,{'grayscale':true})
|
||||
.threshold(128, { grayscale: true } )
|
||||
.toBuffer(function(err, data, info) {
|
||||
assert.strictEqual('jpeg', info.format);
|
||||
assert.strictEqual(320, info.width);
|
||||
assert.strictEqual(240, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('threshold-128.jpg'), data, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('threshold default jpeg', function(done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.resize(320, 240)
|
||||
@@ -128,13 +135,13 @@ describe('Threshold', function() {
|
||||
|
||||
it('invalid threshold -1', function() {
|
||||
assert.throws(function() {
|
||||
sharp(fixtures.inputJpg).threshold(-1);
|
||||
sharp().threshold(-1);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid threshold 256', function() {
|
||||
assert.throws(function() {
|
||||
sharp(fixtures.inputJpg).threshold(256);
|
||||
sharp().threshold(256);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ describe('Trim borders', function() {
|
||||
it('16-bit PNG with alpha channel', function(done) {
|
||||
sharp(fixtures.inputPngWithTransparency16bit)
|
||||
.resize(32, 32)
|
||||
.trim()
|
||||
.trim(20)
|
||||
.toBuffer(function(err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual(true, data.length > 0);
|
||||
@@ -36,4 +36,13 @@ describe('Trim borders', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Invalid thresholds', function() {
|
||||
[-1, 100, 'fail', {}].forEach(function(threshold) {
|
||||
it(threshold, function() {
|
||||
assert.throws(function() {
|
||||
sharp().trim(threshold);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user