mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Tests: a few more speed improvements
This commit is contained in:
parent
013f5cffa9
commit
a0f55252b1
@ -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",
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user