Revert "Introduce a new "Old Image Formats" rule"

This commit is contained in:
Gaël Métais
2023-08-12 04:07:03 +02:00
committed by GitHub
parent 599d02ea0e
commit 773249ca4f
14 changed files with 164 additions and 396 deletions
+5 -5
View File
@@ -10,11 +10,11 @@ describe('contentTypeChecker', function() {
var svgImageContent = fs.readFileSync(path.resolve(__dirname, '../www/svg-image.svg'));
var cssFileContent = fs.readFileSync(path.resolve(__dirname, '../www/unminified-stylesheet.css'));
it('detect the right content type', async function() {
(await contentTypeChecker.findContentType(jpgImageContent)).mimes.should.deep.equal(['image/jpeg']);
(await contentTypeChecker.findContentType(pngImageContent)).mimes.should.deep.equal(['image/png']);
(await contentTypeChecker.findContentType(svgImageContent)).mimes.should.deep.equal(['image/svg+xml']);
should.equal(await contentTypeChecker.findContentType(cssFileContent), null);
it('detect the right content type', function() {
contentTypeChecker.findContentType(jpgImageContent).mimes.should.deep.equal(['image/jpeg']);
contentTypeChecker.findContentType(pngImageContent).mimes.should.deep.equal(['image/png']);
contentTypeChecker.findContentType(svgImageContent).mimes.should.deep.equal(['image/svg+xml']);
should.equal(contentTypeChecker.findContentType(cssFileContent), null);
});
});
-122
View File
@@ -1,122 +0,0 @@
var should = require('chai').should();
var imageReformater = require('../../lib/tools/redownload/imageReformater');
var fs = require('fs');
var path = require('path');
describe('imageReformater', function() {
it('should convert a JPEG image to WebP and AVIF', async function() {
var fileContent = fs.readFileSync(path.resolve(__dirname, '../www/jpeg-image.jpg'));
let entry = {
isImage: true,
type: 'image',
contentType: 'image/jpeg',
weightCheck: {
bodyBuffer: fileContent,
uncompressedSize: fileContent.length
}
};
var newEntry = await imageReformater.reformatImage(entry);
newEntry.weightCheck.should.have.a.property('webpSize');
newEntry.weightCheck.webpSize.should.be.below(fileContent.length);
newEntry.weightCheck.should.have.a.property('avifSize');
newEntry.weightCheck.avifSize.should.be.below(fileContent.length);
});
it('should convert a PNG image to WebP and AVIF', async function() {
var fileContent = fs.readFileSync(path.resolve(__dirname, '../www/jpeg-image.jpg'));
let entry = {
isImage: true,
type: 'image',
contentType: 'image/png',
weightCheck: {
bodyBuffer: fileContent,
uncompressedSize: fileContent.length
}
};
var newEntry = await imageReformater.reformatImage(entry);
newEntry.weightCheck.should.have.a.property('webpSize');
newEntry.weightCheck.webpSize.should.be.below(fileContent.length);
newEntry.weightCheck.should.have.a.property('avifSize');
newEntry.weightCheck.avifSize.should.be.below(fileContent.length);
});
it('should convert a WebP image to AVIF', async function() {
var fileContent = fs.readFileSync(path.resolve(__dirname, '../www/jpeg-image.jpg'));
let entry = {
isImage: true,
type: 'image',
contentType: 'image/webp',
weightCheck: {
bodyBuffer: fileContent,
uncompressedSize: fileContent.length
}
};
var newEntry = await imageReformater.reformatImage(entry);
newEntry.weightCheck.should.not.have.a.property('webpSize');
newEntry.weightCheck.should.have.a.property('avifSize');
newEntry.weightCheck.avifSize.should.be.below(fileContent.length);
});
it('should recognize an animated WebP', async function() {
// Test on an animated image
let fileContent = fs.readFileSync(path.resolve(__dirname, '../www/animated.webp'));
let entry = {
isImage: true,
type: 'image',
contentType: 'image/webp',
weightCheck: {
bodyBuffer: fileContent,
uncompressedSize: fileContent.length
}
};
(await imageReformater.isAnimated(entry)).should.equal(true);
// Test on a not animated image
fileContent = fs.readFileSync(path.resolve(__dirname, '../www/monster.webp'));
entry.weightCheck.bodyBuffer = fileContent;
(await imageReformater.isAnimated(entry)).should.equal(false);
});
it('should not convert an animated WebP', async function() {
// Test on an animated image
let fileContent = fs.readFileSync(path.resolve(__dirname, '../www/animated.webp'));
let entry = {
isImage: true,
type: 'image',
contentType: 'image/webp',
weightCheck: {
bodyBuffer: fileContent,
uncompressedSize: fileContent.length
}
};
var newEntry = await imageReformater.reformatImage(entry);
// Test on a not animated image
newEntry.weightCheck.should.not.have.a.property('avifSize');
});
it('should determine if gain is enough', function() {
imageReformater.gainIsEnough(20000, 10000).should.equal(true);
imageReformater.gainIsEnough(2000, 1000).should.equal(true);
imageReformater.gainIsEnough(20000, 21000).should.equal(false);
imageReformater.gainIsEnough(20000, 40000).should.equal(false);
imageReformater.gainIsEnough(20000, 19500).should.equal(false);
imageReformater.gainIsEnough(250, 120).should.equal(true);
imageReformater.gainIsEnough(200, 120).should.equal(false);
imageReformater.gainIsEnough(2000, 1900).should.equal(false);
imageReformater.gainIsEnough(200000, 197000).should.equal(true);
});
});
+10 -5
View File
@@ -86,10 +86,6 @@ describe('redownload', function() {
data.toolsResults.redownload.offenders.imageOptimization.totalGain.should.be.above(0);
data.toolsResults.redownload.offenders.imageOptimization.images.length.should.equal(2);
data.toolsResults.redownload.offenders.should.have.a.property('oldImageFormats');
data.toolsResults.redownload.offenders.oldImageFormats.totalGain.should.be.above(0);
data.toolsResults.redownload.offenders.oldImageFormats.images.length.should.equal(1);
data.toolsResults.redownload.offenders.should.have.a.property('imagesTooLarge');
data.toolsResults.redownload.offenders.imagesTooLarge.length.should.equal(0);
@@ -171,9 +167,18 @@ describe('redownload', function() {
redownload.redownloadEntry(entry)
.then(function(newEntry) {
newEntry.weightCheck.bodySize.should.equal(4193);
newEntry.weightCheck.bodyBuffer.should.deep.equal(fileContent);
done();
// Opening the image in jimp to check if the format is good
var Jimp = require('jimp');
Jimp.read(newEntry.weightCheck.bodyBuffer, function(err, image) {
image.bitmap.width.should.equal(620);
image.bitmap.height.should.equal(104);
done(err);
});
})
.fail(function(err) {
Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB