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

Commit 968fe9a

Browse files
committed
fix: pass current image path to reference image error
1 parent a1c409d commit 968fe9a

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

lib/state-processor/capture-processor/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ const Promise = require('bluebird');
44
const CaptureProcessor = require('./capture-processor');
55
const utils = require('./utils');
66
const NoRefImageError = require('../../errors/no-ref-image-error');
7+
const temp = require('../../temp');
78

8-
const throwNoRefError = (referencePath) => Promise.reject(new NoRefImageError(referencePath));
9+
const throwNoRefError = (referencePath, capture) => {
10+
const currentPath = temp.path({suffix: '.png'});
11+
return capture.image.save(currentPath)
12+
.then(() => Promise.reject(new NoRefImageError(referencePath, currentPath)));
13+
};
914
const notUpdated = (referencePath) => ({imagePath: referencePath, updated: false});
1015

1116
const saveRef = (referencePath, capture) => {

test/unit/state-processor/capture-processor/capture-processor.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,31 @@ describe('state-processor/capture-processor/capture-processor', () => {
109109
exec_ = mkExecMethod(tester);
110110
});
111111

112-
it('should be rejected with "NoRefImageError" if reference image does not exist', () => {
113-
utils.existsRef.resolves(false);
112+
describe('reference image does not exist', () => {
113+
beforeEach(() => {
114+
utils.existsRef.withArgs('/non-existent/path').resolves(false);
115+
});
116+
117+
it('should save current image to a temporary directory', () => {
118+
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');
119+
120+
return exec_({referencePath: '/non-existent/path'})
121+
.catch(() => assert.calledOnceWith(Image.prototype.save, '/temp/path'));
122+
});
114123

115-
return assert.isRejected(exec_({refPath: '/non-existent/path'}), NoRefImageError);
124+
it('should be rejected with "NoRefImageError"', () => {
125+
return assert.isRejected(exec_({referencePath: '/non-existent/path'}), NoRefImageError);
126+
});
127+
128+
it('should pass reference and current image paths to "NoRefImageError"', () => {
129+
temp.path.withArgs({suffix: '.png'}).returns('/temp/path');
130+
131+
return exec_({referencePath: '/non-existent/path'})
132+
.catch((err) => {
133+
assert.equal(err.refImagePath, '/non-existent/path');
134+
assert.equal(err.currentPath, '/temp/path');
135+
});
136+
});
116137
});
117138

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

0 commit comments

Comments
 (0)