Tests: a few more speed improvements

This commit is contained in:
Lovell Fuller
2021-03-15 20:24:13 +00:00
parent 013f5cffa9
commit a0f55252b1
5 changed files with 39 additions and 40 deletions

View File

@@ -42,18 +42,15 @@ describe('Colour space conversion', function () {
});
});
if (sharp.format.tiff.input.file && sharp.format.webp.output.buffer) {
it('From 1-bit TIFF to sRGB WebP [slow]', function (done) {
sharp(fixtures.inputTiff)
.webp()
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual('webp', info.format);
done();
});
});
}
it('From 1-bit TIFF to sRGB WebP', async () => {
const data = await sharp(fixtures.inputTiff)
.resize(8, 8)
.webp()
.toBuffer();
const { format } = await sharp(data).metadata();
assert.strictEqual(format, 'webp');
});
it('From CMYK to sRGB', function (done) {
sharp(fixtures.inputJpgWithCmykProfile)

View File

@@ -28,32 +28,28 @@ describe('Partial image extraction', function () {
});
});
if (sharp.format.webp.output.file) {
it('WebP', function (done) {
sharp(fixtures.inputWebP)
.extract({ left: 100, top: 50, width: 125, height: 200 })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(125, info.width);
assert.strictEqual(200, info.height);
fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done);
});
});
}
it('WebP', function (done) {
sharp(fixtures.inputWebP)
.extract({ left: 100, top: 50, width: 125, height: 200 })
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(125, info.width);
assert.strictEqual(200, info.height);
fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done);
});
});
if (sharp.format.tiff.output.file) {
it('TIFF', function (done) {
sharp(fixtures.inputTiff)
.extract({ left: 34, top: 63, width: 341, height: 529 })
.jpeg()
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(341, info.width);
assert.strictEqual(529, info.height);
fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done);
});
});
}
it('TIFF', function (done) {
sharp(fixtures.inputTiff)
.extract({ left: 34, top: 63, width: 341, height: 529 })
.jpeg()
.toBuffer(function (err, data, info) {
if (err) throw err;
assert.strictEqual(341, info.width);
assert.strictEqual(529, info.height);
fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done);
});
});
it('Before resize', function (done) {
sharp(fixtures.inputJpg)

View File

@@ -54,6 +54,7 @@ describe('Normalization', function () {
it('keeps an existing alpha channel', function (done) {
sharp(fixtures.inputPngWithTransparency)
.resize(8, 8)
.normalize()
.toBuffer(function (err, data) {
if (err) throw err;
@@ -69,6 +70,7 @@ describe('Normalization', function () {
it('keeps the alpha channel of greyscale images intact', function (done) {
sharp(fixtures.inputPngWithGreyAlpha)
.resize(8, 8)
.normalise()
.toBuffer(function (err, data) {
if (err) throw err;

View File

@@ -90,9 +90,11 @@ describe('TIFF', function () {
it('Increasing TIFF quality increases file size', () =>
sharp(fixtures.inputJpgWithLandscapeExif1)
.resize(320, 240)
.tiff({ quality: 40 })
.toBuffer()
.then(tiff40 => sharp(fixtures.inputJpgWithLandscapeExif1)
.resize(320, 240)
.tiff({ quality: 90 })
.toBuffer()
.then(tiff90 =>
@@ -155,6 +157,7 @@ describe('TIFF', function () {
it('TIFF setting xres and yres on file', () =>
sharp(fixtures.inputTiff)
.resize(8, 8)
.tiff({
xres: 1000,
yres: 1000
@@ -171,6 +174,7 @@ describe('TIFF', function () {
it('TIFF setting xres and yres on buffer', () =>
sharp(fixtures.inputTiff)
.resize(8, 8)
.tiff({
xres: 1000,
yres: 1000