Skip to content

Commit

Permalink
Merge pull request #29 from NimaSoroush/bug-fix
Browse files Browse the repository at this point in the history
- Bug fixes
  • Loading branch information
NimaSoroush authored Aug 4, 2017
2 parents 2034a2c + 23b65c3 commit 623baab
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "differencify",
"version": "0.0.15",
"version": "0.0.16",
"description": "Perceptual diffing tool",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ export default {
capture: 'capture',
test: 'test',
wait: 'wait',
evaluate: 'evaluate',
freezeImage: 'freezeImge',
execute: 'execute',
freezeImage: 'freezeImage',
};
8 changes: 4 additions & 4 deletions src/chromyRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
64 changes: 54 additions & 10 deletions src/chromyRunner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ 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(),
screenshotDocument: jest.fn(() => 'png file'),
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) => {
Expand All @@ -26,6 +28,8 @@ jest.mock('./compareImage', () => jest.fn(arg =>
}),
));

jest.mock('./freezeImage', () => jest.fn(() => true));

let loggerCalls = [];
logger.prefix = () => logger;
logger.log = (...args) => {
Expand All @@ -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;
Expand Down Expand Up @@ -248,37 +253,76 @@ describe('ChromyRunner', () => {
});
});
describe('Chromy runner', () => {
it('Evaluate: function', async () => {
it('Execute: function', async () => {
const newConfig = {
name: 'default',
resolution: {
width: 800,
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: {
width: 800,
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');
});
});
});

0 comments on commit 623baab

Please sign in to comment.