mercredi 25 novembre 2015

JPG File Size Unit-Test Comparison

I would like to compare the size of two image files using a unit-test. Does the following look correct?

test('optimize a JPG', function (t) {
    t.plan(2);

    var src = fs.readFileSync(path.join(__dirname, 'fixtures/test.jpg'), null);
    var imagemin = new Imagemin()
        .src(path.join(__dirname, 'fixtures/test.jpg'))
        .use(Imagemin.jpegtran());

    imagemin.run(function (err, files) {
        t.assert(!err, err);
        t.assert(files[0].contents.length < src.length, files[0].contents.length);
    });
});

When the test runs thru Travis, it passes. But if I manually compare (right-click) the two files they are of the same size.

You answer is appreciated.

Aucun commentaire:

Enregistrer un commentaire