From 23b65c35a5889c0ec5daf34035a9abe2d29906d3 Mon Sep 17 00:00:00 2001 From: Nima Soroush Haddadi Date: Fri, 4 Aug 2017 13:14:06 +0100 Subject: [PATCH] Bug fixes --- CHANGELOG.md | 4 +++ package.json | 2 +- src/actions.js | 4 +-- src/chromyRunner.js | 8 ++--- src/chromyRunner.test.js | 64 +++++++++++++++++++++++++++++++++------- 5 files changed, 65 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f31afc0..09163f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [0.0.16] - 2017-08-04 +### Added +- Bug fixes + ## [0.0.15] - 2017-08-03 ### Added - Adding evaluate functionality to evaluate expression on browser diff --git a/package.json b/package.json index bc23145..1b147e1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "differencify", - "version": "0.0.15", + "version": "0.0.16", "description": "Perceptual diffing tool", "main": "dist/index.js", "scripts": { diff --git a/src/actions.js b/src/actions.js index c4319ec..fba12a2 100644 --- a/src/actions.js +++ b/src/actions.js @@ -3,6 +3,6 @@ export default { capture: 'capture', test: 'test', wait: 'wait', - evaluate: 'evaluate', - freezeImage: 'freezeImge', + execute: 'execute', + freezeImage: 'freezeImage', }; diff --git a/src/chromyRunner.js b/src/chromyRunner.js index 85b39d2..68c4037 100644 --- a/src/chromyRunner.js +++ b/src/chromyRunner.js @@ -88,13 +88,13 @@ const run = async (chromy, options, test) => { return false; } break; - case actions.evaluate: + case actions.execute: try { if (check.function(action.value)) { - prefixedLogger.log('waiting for to evaluate function in browser'); + prefixedLogger.log('waiting for to execute function in browser'); await chromy.evaluate(action.value); } else { - prefixedLogger.log('failed to detect evaluate function'); + prefixedLogger.log('failed to detect execute function'); return false; } } catch (error) { @@ -105,7 +105,7 @@ const run = async (chromy, options, test) => { case actions.freezeImage: try { prefixedLogger.log(`Freezing image ${action.value} in browser`); - const result = await chromy.evaluate(freezeImage(action.value)); + const result = await chromy.evaluate(() => freezeImage(action.value)); if (!result) { prefixedLogger.log(`Tag with selector ${action.value} is not a valid image`); return false; diff --git a/src/chromyRunner.test.js b/src/chromyRunner.test.js index 54424b2..aa6c5b5 100644 --- a/src/chromyRunner.test.js +++ b/src/chromyRunner.test.js @@ -4,8 +4,9 @@ import run from './chromyRunner'; import logger from './logger'; import { globalConfig, testConfig, configTypes } from './defaultConfig'; import actions from './actions'; +import freezeImage from './freezeImage'; -jest.mock('chromy', () => jest.fn(() => +jest.mock('chromy', () => () => ({ goto: jest.fn(), close: jest.fn(), @@ -13,9 +14,10 @@ jest.mock('chromy', () => jest.fn(() => screenshotSelector: jest.fn(() => 'png file'), screenshot: jest.fn(() => 'png file'), wait: jest.fn(), - evaluate: jest.fn(), - }), -)); + evaluate: jest.fn(fn => + fn(), + ), + })); jest.mock('./compareImage', () => jest.fn(arg => new Promise((resolve, reject) => { @@ -26,6 +28,8 @@ jest.mock('./compareImage', () => jest.fn(arg => }), )); +jest.mock('./freezeImage', () => jest.fn(() => true)); + let loggerCalls = []; logger.prefix = () => logger; logger.log = (...args) => { @@ -48,6 +52,7 @@ describe('ChromyRunner', () => { chromy.screenshotSelector.mockClear(); chromy.wait.mockClear(); chromy.evaluate.mockClear(); + freezeImage.mockClear(); }); it('run update', async () => { testConfig.type = configTypes.update; @@ -248,7 +253,7 @@ describe('ChromyRunner', () => { }); }); describe('Chromy runner', () => { - it('Evaluate: function', async () => { + it('Execute: function', async () => { const newConfig = { name: 'default', resolution: { @@ -256,15 +261,15 @@ describe('ChromyRunner', () => { height: 600, }, steps: [ - { name: 'evaluate', value: () => {} }, + { name: 'execute', value: () => {} }, ], }; const result = await run(chromy, globalConfig, newConfig); expect(result).toEqual(true); expect(chromy.evaluate).toHaveBeenCalledTimes(1); - expect(loggerCalls[0]).toEqual('waiting for to evaluate function in browser'); + expect(loggerCalls[0]).toEqual('waiting for to execute function in browser'); }); - it('Evaluate: non-function', async () => { + it('Execute: non-function', async () => { const newConfig = { name: 'default', resolution: { @@ -272,13 +277,52 @@ describe('ChromyRunner', () => { height: 600, }, steps: [ - { name: 'evaluate', value: 123 }, + { name: 'execute', value: 123 }, ], }; const result = await run(chromy, globalConfig, newConfig); expect(result).toEqual(false); expect(chromy.evaluate).toHaveBeenCalledTimes(0); - expect(loggerCalls[0]).toEqual('failed to detect evaluate function'); + expect(loggerCalls[0]).toEqual('failed to detect execute function'); + }); + }); + describe('Chromy runner', () => { + it('FreezeImage: existing selector', async () => { + freezeImage.mockReturnValueOnce(true); + const newConfig = { + name: 'default', + resolution: { + width: 800, + height: 600, + }, + steps: [ + { name: 'freezeImage', value: 'selector' }, + ], + }; + const result = await run(chromy, globalConfig, newConfig); + expect(result).toEqual(true); + expect(chromy.evaluate).toHaveBeenCalledTimes(1); + expect(freezeImage).toHaveBeenCalledWith('selector'); + expect(loggerCalls[0]).toEqual('Freezing image selector in browser'); + }); + it('FreezeImage: non-existing selector', async () => { + freezeImage.mockReturnValueOnce(false); + const newConfig = { + name: 'default', + resolution: { + width: 800, + height: 600, + }, + steps: [ + { name: 'freezeImage', value: 'selector' }, + ], + }; + const result = await run(chromy, globalConfig, newConfig); + expect(result).toEqual(false); + expect(chromy.evaluate).toHaveBeenCalledTimes(1); + expect(freezeImage).toHaveBeenCalledWith('selector'); + expect(loggerCalls[0]).toEqual('Freezing image selector in browser'); + expect(loggerCalls[1]).toEqual('Tag with selector selector is not a valid image'); }); }); });