mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Deprecate limitInputPixels and sequentialRead, move to input options
This commit is contained in:
100
test/unit/io.js
100
test/unit/io.js
@@ -214,7 +214,27 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Sequential read, force JPEG', function (done) {
|
||||
it('Invalid sequential read option throws', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ sequentialRead: 'fail' });
|
||||
}, /Expected boolean for sequentialRead but received fail of type string/);
|
||||
});
|
||||
|
||||
it('Sequential read, force JPEG', () =>
|
||||
sharp(fixtures.inputJpg, { sequentialRead: true })
|
||||
.resize(320, 240)
|
||||
.toFormat(sharp.format.jpeg)
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(({ data, info }) => {
|
||||
assert.strictEqual(data.length > 0, true);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
assert.strictEqual(info.format, 'jpeg');
|
||||
assert.strictEqual(info.width, 320);
|
||||
assert.strictEqual(info.height, 240);
|
||||
})
|
||||
);
|
||||
|
||||
it('Sequential read, force JPEG - deprecated', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.sequentialRead()
|
||||
.resize(320, 240)
|
||||
@@ -230,7 +250,21 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
it('Not sequential read, force JPEG', function (done) {
|
||||
it('Not sequential read, force JPEG', () =>
|
||||
sharp(fixtures.inputJpg, { sequentialRead: false })
|
||||
.resize(320, 240)
|
||||
.toFormat('jpeg')
|
||||
.toBuffer({ resolveWithObject: true })
|
||||
.then(({ data, info }) => {
|
||||
assert.strictEqual(data.length > 0, true);
|
||||
assert.strictEqual(data.length, info.size);
|
||||
assert.strictEqual(info.format, 'jpeg');
|
||||
assert.strictEqual(info.width, 320);
|
||||
assert.strictEqual(info.height, 240);
|
||||
})
|
||||
);
|
||||
|
||||
it('Not sequential read, force JPEG - deprecated', function (done) {
|
||||
sharp(fixtures.inputJpg)
|
||||
.sequentialRead(false)
|
||||
.resize(320, 240)
|
||||
@@ -559,7 +593,67 @@ describe('Input/output', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Limit pixel count of input image', function () {
|
||||
describe('Limit pixel count of input image', () => {
|
||||
it('Invalid fails - negative', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ limitInputPixels: -1 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid fails - float', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ limitInputPixels: 12.3 });
|
||||
});
|
||||
});
|
||||
|
||||
it('Invalid fails - string', () => {
|
||||
assert.throws(() => {
|
||||
sharp({ limitInputPixels: 'fail' });
|
||||
});
|
||||
});
|
||||
|
||||
it('Same size as input works', () =>
|
||||
sharp(fixtures.inputJpg)
|
||||
.metadata()
|
||||
.then(({ width, height }) =>
|
||||
sharp(fixtures.inputJpg, { limitInputPixels: width * height }).toBuffer()
|
||||
)
|
||||
);
|
||||
|
||||
it('Disabling limit works', () =>
|
||||
sharp(fixtures.inputJpgLarge, { limitInputPixels: false })
|
||||
.resize(2)
|
||||
.toBuffer()
|
||||
);
|
||||
|
||||
it('Enabling default limit works and fails with a large image', () =>
|
||||
sharp(fixtures.inputJpgLarge, { limitInputPixels: true })
|
||||
.toBuffer()
|
||||
.then(() => {
|
||||
assert.fail('Expected to fail');
|
||||
})
|
||||
.catch(err => {
|
||||
assert.strictEqual(err.message, 'Input image exceeds pixel limit');
|
||||
})
|
||||
);
|
||||
|
||||
it('Smaller than input fails', () =>
|
||||
sharp(fixtures.inputJpg)
|
||||
.metadata()
|
||||
.then(({ width, height }) =>
|
||||
sharp(fixtures.inputJpg, { limitInputPixels: width * height - 1 })
|
||||
.toBuffer()
|
||||
.then(() => {
|
||||
assert.fail('Expected to fail');
|
||||
})
|
||||
.catch(err => {
|
||||
assert.strictEqual(err.message, 'Input image exceeds pixel limit');
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
describe('Limit pixel count of input image - deprecated', function () {
|
||||
it('Invalid fails - negative', function (done) {
|
||||
let isValid = false;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user