Skip to content

Commit

Permalink
Tests: a few more speed improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lovell committed Mar 15, 2021
1 parent 013f5cf commit a0f5525
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
21 changes: 9 additions & 12 deletions test/unit/colourspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 22 additions & 26 deletions test/unit/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}

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('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('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)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/unit/tiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a0f5525

Please sign in to comment.