From a0f55252b1cc21c5a813e73e7f8e11c8650f81bc Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Mon, 15 Mar 2021 20:24:13 +0000 Subject: [PATCH] Tests: a few more speed improvements --- package.json | 6 +++--- test/unit/colourspace.js | 21 ++++++++---------- test/unit/extract.js | 46 ++++++++++++++++++---------------------- test/unit/normalize.js | 2 ++ test/unit/tiff.js | 4 ++++ 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index 5a20d0c0..bc4276f1 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)", "clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*", "test": "semistandard && cpplint && npm run test-unit && npm run test-licensing", - "test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js", + "test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=1000 --timeout=60000 ./test/unit/*.js", "test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"", "test-coverage": "./test/coverage/report.sh", "test-leak": "./test/leak/leak.sh", @@ -130,11 +130,11 @@ "async": "^3.2.0", "cc": "^3.0.1", "decompress-zip": "^0.3.3", - "documentation": "^13.1.1", + "documentation": "^13.2.0", "exif-reader": "^1.0.3", "icc": "^2.0.0", "license-checker": "^25.0.1", - "mocha": "^8.3.1", + "mocha": "^8.3.2", "mock-fs": "^4.13.0", "nyc": "^15.1.0", "prebuild": "^10.0.1", diff --git a/test/unit/colourspace.js b/test/unit/colourspace.js index 8767e242..60ce426c 100644 --- a/test/unit/colourspace.js +++ b/test/unit/colourspace.js @@ -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) diff --git a/test/unit/extract.js b/test/unit/extract.js index 41be0387..05d67bf1 100644 --- a/test/unit/extract.js +++ b/test/unit/extract.js @@ -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) diff --git a/test/unit/normalize.js b/test/unit/normalize.js index fcf41631..1bfb2862 100644 --- a/test/unit/normalize.js +++ b/test/unit/normalize.js @@ -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; diff --git a/test/unit/tiff.js b/test/unit/tiff.js index 8905e2e3..b3d3abbd 100644 --- a/test/unit/tiff.js +++ b/test/unit/tiff.js @@ -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