Last active
June 11, 2020 12:17
-
-
Save stfsy/bb6e75da1c6577a7a14d048e618329a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const rimraf = require('rimraf') | |
const fixtures = require('../fixtures') | |
const fs = require('fs') | |
const BroccoliRunner = require('broccoli-test-runner') | |
const runner = new BroccoliRunner('test/fixtures') | |
const expect = require('chai').expect | |
describe('BroccoliImageMin', () => { | |
before(() => runner.build()) | |
after(() => new Promise((resolve) => { | |
rimraf('test/fixtures/dist', resolve) | |
})) | |
const compareSizes = (file, minRatio, maxRatio) => { | |
const inBuffer = fs.readFileSync(fixtures.path + '/' + file) | |
const builtBuffer = fs.readFileSync(fixtures.buildPath + '/' + file) | |
expect(builtBuffer.length / inBuffer.length).to.be.below(maxRatio) | |
expect(builtBuffer.length / inBuffer.length).to.be.above(minRatio) | |
} | |
it('minifies jpgs', () => fixtures.jpgs.forEach(jpg => compareSizes(jpg, .45, .55))) | |
it('minifies pngs', () => fixtures.pngs.forEach(png => compareSizes(png, .1, .2))) | |
it('minifies gifs', () => fixtures.gifs.forEach(gif => compareSizes(gif, .7, .75))) | |
it('minifies svg', () => fixtures.svgs.forEach(svg => compareSizes(svg, .5, .55))) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment