Skip to content

Commit

Permalink
Test: createComparisons
Browse files Browse the repository at this point in the history
  • Loading branch information
milesillsley committed Jun 18, 2018
1 parent 10f52e3 commit 36075a9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/__mocks__/comparer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const isEqual = () => Promise.resolve(false);

export default isEqual;
12 changes: 12 additions & 0 deletions src/__mocks__/comparisonDataConstructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const comparisonDataConstructor = () =>
Promise.resolve([
{
label: 'test1-large',
baseline: 'testBaseline/test1-large.png',
latest: 'testLatest/test1-large.png',
generatedDiffs: 'testDiff/test1-large.png',
tolerance: 0
}
]);

export default comparisonDataConstructor;
3 changes: 3 additions & 0 deletions src/__mocks__/createDiff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const createDiffimage = () => Promise.resolve();

export default createDiffimage;
1 change: 1 addition & 0 deletions src/comparisonActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const createComparisons = async (fs, config) => {
for (let i = 0; i < comparisonData.length; i++) {
const scenario = comparisonData[i];
const equal = await isEqual(scenario);
console.log(equal);

if (equal) {
reporter.pass(scenario.label);
Expand Down
34 changes: 33 additions & 1 deletion src/comparisonActions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
import {
createDirectories,
fetchRemoteComparisonImages,
clearDirectory
clearDirectory,
createComparisons
} from './comparisonActions';
import { deleteRemote, fetchRemote } from './remoteActions';
import createDiffImage from './createDiffs';

jest.mock('fs');
jest.mock('./remoteActions');
jest.mock('./reporter');
jest.mock('./comparisonDataConstructor');
jest.mock('./comparer');
jest.mock('./createDiffs');

describe('The comparions actions', () => {
let mockFs;
Expand All @@ -22,6 +28,10 @@ describe('The comparions actions', () => {
};
});

afterEach(() => {
jest.clearAllMocks();
});

it('Creates directories checks the directories exist before creating', async () => {
const config = {
baseline: './baselineTest',
Expand Down Expand Up @@ -88,4 +98,26 @@ describe('The comparions actions', () => {
await clearDirectory(mockFs, config);
expect(mockFs.unlinkSync.mock.calls.length).toBe(6);
});

it('creates a diff image when comparison fails', async () => {
const config = {
baseline: './baselineTest',
latest: './latestTest',
generatedDiffs: './generatedDiffsTest',
scenarios: [
{
viewports: [{ height: 2400, width: 1024, label: 'large' }],
label: 'test1'
}
]
};

mockFs = {
readdirSync: () => ['1', '2', '3', '4', '5', '6'],
unlinkSync: jest.fn()
};

await createComparisons(mockFs, config);
expect(createDiffImage.mock.calls.length).toBe(1);
});
});

0 comments on commit 36075a9

Please sign in to comment.