Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should not save a reference image if it is already exists', () => {
fs.readFileSync.withArgs('/existent/path').returns('existent-buffer-data');
const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('existent-buffer-data').returns(refImage);
return exec_({refImg: {path: '/existent/path'}})
.then((res) => {
assert.notCalled(utils.saveRef);
assert.deepEqual(res, {
refImg: {path: '/existent/path'},
updated: false
});
});
});
it('should update a reference image size', () => {
fs.readFileSync.withArgs('/ref/path').returns('ref-buffer-data');
const refImage = mkImage({size: {width: 100, height: 200}});
Image.create.withArgs('ref-buffer-data').returns(refImage);
const currImage = mkImage({size: {width: 300, height: 400}});
return exec_({refImg: {path: '/ref/path', size: null}}, {image: currImage})
.then((res) => {
assert.deepEqual(res, {
refImg: {path: '/ref/path', size: {width: 300, height: 400}},
updated: true
});
});
});
getScreenshotPath
.withArgs(sinon.match.any, 'plain').returns('/ref/path/plain')
.withArgs(sinon.match.any, 'complex').returns('/ref/path/complex');
const bufferPlain = new Buffer('plain-data', 'base64');
const bufferComplex = new Buffer('complex-data', 'base64');
fs.readFileSync
.withArgs('/ref/path/plain').returns(bufferPlain)
.withArgs('/ref/path/complex').returns(bufferComplex);
const imagePlain = stubImage_({size: {width: 100, height: 200}});
const imageComplex = stubImage_({size: {width: 300, height: 400}});
Image.create
.withArgs(bufferPlain).returns(imagePlain)
.withArgs(bufferComplex).returns(imageComplex);
const browser = stubBrowser_({getScreenshotPath});
await browser.publicAPI.assertView('plain');
await browser.publicAPI.assertView('complex');
assert.deepEqual(browser.publicAPI.executionContext.hermioneCtx.assertViewResults.get(), [
{stateName: 'plain', refImg: {path: '/ref/path/plain', size: {width: 100, height: 200}}},
{stateName: 'complex', refImg: {path: '/ref/path/complex', size: {width: 300, height: 400}}}
]);
});
});