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

@ -80,7 +80,7 @@
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)", "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.*", "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": "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-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
"test-coverage": "./test/coverage/report.sh", "test-coverage": "./test/coverage/report.sh",
"test-leak": "./test/leak/leak.sh", "test-leak": "./test/leak/leak.sh",
@ -130,11 +130,11 @@
"async": "^3.2.0", "async": "^3.2.0",
"cc": "^3.0.1", "cc": "^3.0.1",
"decompress-zip": "^0.3.3", "decompress-zip": "^0.3.3",
"documentation": "^13.1.1", "documentation": "^13.2.0",
"exif-reader": "^1.0.3", "exif-reader": "^1.0.3",
"icc": "^2.0.0", "icc": "^2.0.0",
"license-checker": "^25.0.1", "license-checker": "^25.0.1",
"mocha": "^8.3.1", "mocha": "^8.3.2",
"mock-fs": "^4.13.0", "mock-fs": "^4.13.0",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"prebuild": "^10.0.1", "prebuild": "^10.0.1",

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', async () => {
it('From 1-bit TIFF to sRGB WebP [slow]', function (done) { const data = await sharp(fixtures.inputTiff)
sharp(fixtures.inputTiff) .resize(8, 8)
.webp() .webp()
.toBuffer(function (err, data, info) { .toBuffer();
if (err) throw err;
assert.strictEqual(true, data.length > 0); const { format } = await sharp(data).metadata();
assert.strictEqual('webp', info.format); assert.strictEqual(format, 'webp');
done();
}); });
});
}
it('From CMYK to sRGB', function (done) { it('From CMYK to sRGB', function (done) {
sharp(fixtures.inputJpgWithCmykProfile) sharp(fixtures.inputJpgWithCmykProfile)

View File

@ -28,7 +28,6 @@ describe('Partial image extraction', function () {
}); });
}); });
if (sharp.format.webp.output.file) {
it('WebP', function (done) { it('WebP', function (done) {
sharp(fixtures.inputWebP) sharp(fixtures.inputWebP)
.extract({ left: 100, top: 50, width: 125, height: 200 }) .extract({ left: 100, top: 50, width: 125, height: 200 })
@ -39,9 +38,7 @@ describe('Partial image extraction', function () {
fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done); fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done);
}); });
}); });
}
if (sharp.format.tiff.output.file) {
it('TIFF', function (done) { it('TIFF', function (done) {
sharp(fixtures.inputTiff) sharp(fixtures.inputTiff)
.extract({ left: 34, top: 63, width: 341, height: 529 }) .extract({ left: 34, top: 63, width: 341, height: 529 })
@ -53,7 +50,6 @@ describe('Partial image extraction', function () {
fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done); fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done);
}); });
}); });
}
it('Before resize', function (done) { it('Before resize', function (done) {
sharp(fixtures.inputJpg) sharp(fixtures.inputJpg)

View File

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

View File

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