Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
fix: pass current image path to reference image error
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Aug 31, 2017
1 parent a1c409d commit 968fe9a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/state-processor/capture-processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ const Promise = require('bluebird');
const CaptureProcessor = require('./capture-processor');
const utils = require('./utils');
const NoRefImageError = require('../../errors/no-ref-image-error');
const temp = require('../../temp');

const throwNoRefError = (referencePath) => Promise.reject(new NoRefImageError(referencePath));
const throwNoRefError = (referencePath, capture) => {
const currentPath = temp.path({suffix: '.png'});
return capture.image.save(currentPath)
.then(() => Promise.reject(new NoRefImageError(referencePath, currentPath)));
};
const notUpdated = (referencePath) => ({imagePath: referencePath, updated: false});

const saveRef = (referencePath, capture) => {
Expand Down
27 changes: 24 additions & 3 deletions test/unit/state-processor/capture-processor/capture-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,31 @@ describe('state-processor/capture-processor/capture-processor', () => {
exec_ = mkExecMethod(tester);
});

it('should be rejected with "NoRefImageError" if reference image does not exist', () => {
utils.existsRef.resolves(false);
describe('reference image does not exist', () => {
beforeEach(() => {
utils.existsRef.withArgs('/non-existent/path').resolves(false);
});

it('should save current image to a temporary directory', () => {
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');

return exec_({referencePath: '/non-existent/path'})
.catch(() => assert.calledOnceWith(Image.prototype.save, '/temp/path'));
});

return assert.isRejected(exec_({refPath: '/non-existent/path'}), NoRefImageError);
it('should be rejected with "NoRefImageError"', () => {
return assert.isRejected(exec_({referencePath: '/non-existent/path'}), NoRefImageError);
});

it('should pass reference and current image paths to "NoRefImageError"', () => {
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');

return exec_({referencePath: '/non-existent/path'})
.catch((err) => {
assert.equal(err.refImagePath, '/non-existent/path');
assert.equal(err.currentPath, '/temp/path');
});
});
});

describe('should return image comparison result if images are', () => {
Expand Down

0 comments on commit 968fe9a

Please sign in to comment.