Skip to content

Commit

Permalink
feat: support the changed field name "imagePath" -> "refImg.path"
Browse files Browse the repository at this point in the history
BREAKING CHANGE: in gemini changed format of data emitted on test execution events
  • Loading branch information
DudaGod committed Nov 29, 2018
1 parent 69f595c commit 2849e2d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const childProcess = require('child_process');

const _ = require('lodash');
const log = require('debug')('gemini:optipng');
const optipng = require('optipng-bin');
const fs = require('fs-extra');
Expand All @@ -10,7 +11,7 @@ const execFile = Promise.promisify(childProcess.execFile);

module.exports = class Optimizer {
static create(opts, data) {
return new Optimizer(opts.level, data.imagePath);
return new Optimizer(opts.level, _.get(data, 'refImg.path'));
}

constructor(level, imagePath) {
Expand Down
10 changes: 5 additions & 5 deletions test/lib/optimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ describe('optimizer', () => {

it('should execute optipng optimizer with correct params', () => {
const opts = {level: 100500};
const imagePath = 'path/to/ref/image.png';
const data = {refImg: {path: 'path/to/ref/image.png'}};

return Optimizer.create(opts, {imagePath}).exec()
.then(() => assert.calledWith(childProcess.execFile, optipng, ['-o', opts.level, imagePath]));
return Optimizer.create(opts, data).exec()
.then(() => assert.calledWith(childProcess.execFile, optipng, ['-o', opts.level, data.refImg.path]));
});

it('should log rate on which the ref image has been compressed (in percents)', () => {
const data = {imagePath: 'path/to/ref/image.png'};
const data = {refImg: {path: 'path/to/ref/image.png'}};
const sizeBeforeOptim = 2000;
const sizeAfterOptim = 1000;
const compressionRate = 50;
Expand All @@ -44,7 +44,7 @@ describe('optimizer', () => {
.onSecondCall().resolves({size: sizeAfterOptim});

return Optimizer.create({}, data).exec()
.then(() => assert.calledWith(log, `${data.imagePath} compressed by ${compressionRate}%`));
.then(() => assert.calledWith(log, `${data.refImg.path} compressed by ${compressionRate}%`));
});

it('should log rounded compression rate (in percents)', () => {
Expand Down

0 comments on commit 2849e2d

Please sign in to comment.