Skip to content

Commit a0f5525

Browse files
committedMar 15, 2021
Tests: a few more speed improvements
1 parent 013f5cf commit a0f5525

File tree

5 files changed

+40
-41
lines changed

5 files changed

+40
-41
lines changed
 

‎package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"install": "(node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)",
8181
"clean": "rm -rf node_modules/ build/ vendor/ .nyc_output/ coverage/ test/fixtures/output.*",
8282
"test": "semistandard && cpplint && npm run test-unit && npm run test-licensing",
83-
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=5000 --timeout=60000 ./test/unit/*.js",
83+
"test-unit": "nyc --reporter=lcov --branches=99 mocha --slow=1000 --timeout=60000 ./test/unit/*.js",
8484
"test-licensing": "license-checker --production --summary --onlyAllow=\"Apache-2.0;BSD;ISC;MIT\"",
8585
"test-coverage": "./test/coverage/report.sh",
8686
"test-leak": "./test/leak/leak.sh",
@@ -130,11 +130,11 @@
130130
"async": "^3.2.0",
131131
"cc": "^3.0.1",
132132
"decompress-zip": "^0.3.3",
133-
"documentation": "^13.1.1",
133+
"documentation": "^13.2.0",
134134
"exif-reader": "^1.0.3",
135135
"icc": "^2.0.0",
136136
"license-checker": "^25.0.1",
137-
"mocha": "^8.3.1",
137+
"mocha": "^8.3.2",
138138
"mock-fs": "^4.13.0",
139139
"nyc": "^15.1.0",
140140
"prebuild": "^10.0.1",

‎test/unit/colourspace.js

+9-12
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,15 @@ describe('Colour space conversion', function () {
4242
});
4343
});
4444

45-
if (sharp.format.tiff.input.file && sharp.format.webp.output.buffer) {
46-
it('From 1-bit TIFF to sRGB WebP [slow]', function (done) {
47-
sharp(fixtures.inputTiff)
48-
.webp()
49-
.toBuffer(function (err, data, info) {
50-
if (err) throw err;
51-
assert.strictEqual(true, data.length > 0);
52-
assert.strictEqual('webp', info.format);
53-
done();
54-
});
55-
});
56-
}
45+
it('From 1-bit TIFF to sRGB WebP', async () => {
46+
const data = await sharp(fixtures.inputTiff)
47+
.resize(8, 8)
48+
.webp()
49+
.toBuffer();
50+
51+
const { format } = await sharp(data).metadata();
52+
assert.strictEqual(format, 'webp');
53+
});
5754

5855
it('From CMYK to sRGB', function (done) {
5956
sharp(fixtures.inputJpgWithCmykProfile)

‎test/unit/extract.js

+22-26
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,28 @@ describe('Partial image extraction', function () {
2828
});
2929
});
3030

31-
if (sharp.format.webp.output.file) {
32-
it('WebP', function (done) {
33-
sharp(fixtures.inputWebP)
34-
.extract({ left: 100, top: 50, width: 125, height: 200 })
35-
.toBuffer(function (err, data, info) {
36-
if (err) throw err;
37-
assert.strictEqual(125, info.width);
38-
assert.strictEqual(200, info.height);
39-
fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done);
40-
});
41-
});
42-
}
43-
44-
if (sharp.format.tiff.output.file) {
45-
it('TIFF', function (done) {
46-
sharp(fixtures.inputTiff)
47-
.extract({ left: 34, top: 63, width: 341, height: 529 })
48-
.jpeg()
49-
.toBuffer(function (err, data, info) {
50-
if (err) throw err;
51-
assert.strictEqual(341, info.width);
52-
assert.strictEqual(529, info.height);
53-
fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done);
54-
});
55-
});
56-
}
31+
it('WebP', function (done) {
32+
sharp(fixtures.inputWebP)
33+
.extract({ left: 100, top: 50, width: 125, height: 200 })
34+
.toBuffer(function (err, data, info) {
35+
if (err) throw err;
36+
assert.strictEqual(125, info.width);
37+
assert.strictEqual(200, info.height);
38+
fixtures.assertSimilar(fixtures.expected('extract.webp'), data, done);
39+
});
40+
});
41+
42+
it('TIFF', function (done) {
43+
sharp(fixtures.inputTiff)
44+
.extract({ left: 34, top: 63, width: 341, height: 529 })
45+
.jpeg()
46+
.toBuffer(function (err, data, info) {
47+
if (err) throw err;
48+
assert.strictEqual(341, info.width);
49+
assert.strictEqual(529, info.height);
50+
fixtures.assertSimilar(fixtures.expected('extract.tiff'), data, done);
51+
});
52+
});
5753

5854
it('Before resize', function (done) {
5955
sharp(fixtures.inputJpg)

‎test/unit/normalize.js

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('Normalization', function () {
5454

5555
it('keeps an existing alpha channel', function (done) {
5656
sharp(fixtures.inputPngWithTransparency)
57+
.resize(8, 8)
5758
.normalize()
5859
.toBuffer(function (err, data) {
5960
if (err) throw err;
@@ -69,6 +70,7 @@ describe('Normalization', function () {
6970

7071
it('keeps the alpha channel of greyscale images intact', function (done) {
7172
sharp(fixtures.inputPngWithGreyAlpha)
73+
.resize(8, 8)
7274
.normalise()
7375
.toBuffer(function (err, data) {
7476
if (err) throw err;

‎test/unit/tiff.js

+4
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ describe('TIFF', function () {
9090

9191
it('Increasing TIFF quality increases file size', () =>
9292
sharp(fixtures.inputJpgWithLandscapeExif1)
93+
.resize(320, 240)
9394
.tiff({ quality: 40 })
9495
.toBuffer()
9596
.then(tiff40 => sharp(fixtures.inputJpgWithLandscapeExif1)
97+
.resize(320, 240)
9698
.tiff({ quality: 90 })
9799
.toBuffer()
98100
.then(tiff90 =>
@@ -155,6 +157,7 @@ describe('TIFF', function () {
155157

156158
it('TIFF setting xres and yres on file', () =>
157159
sharp(fixtures.inputTiff)
160+
.resize(8, 8)
158161
.tiff({
159162
xres: 1000,
160163
yres: 1000
@@ -171,6 +174,7 @@ describe('TIFF', function () {
171174

172175
it('TIFF setting xres and yres on buffer', () =>
173176
sharp(fixtures.inputTiff)
177+
.resize(8, 8)
174178
.tiff({
175179
xres: 1000,
176180
yres: 1000

0 commit comments

Comments
 (0)
Please sign in to comment.