Skip to content

Commit

Permalink
fix(reporter-helpers): do not fail if screenshot in base64 is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Dec 2, 2018
1 parent 9a37d89 commit 03e044d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reporter-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports.updateReferenceImage = (testResult, reportPath, stateName) => {
};

exports.saveBase64Screenshot = (testResult, reportPath) => {
if (!testResult.screenshot) {
if (!testResult.screenshot.base64) {
utils.logger.warn('Cannot save screenshot on reject');

return Promise.resolve();
Expand Down
61 changes: 61 additions & 0 deletions test/lib/reporter-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

const fs = require('fs-extra');
const {saveBase64Screenshot} = require('lib/reporter-helpers');
const utils = require('lib/server-utils');

describe('reporter-helpers', () => {
const sandbox = sinon.createSandbox();

beforeEach(() => {
sandbox.stub(utils, 'getCurrentAbsolutePath');
sandbox.stub(utils.logger, 'warn');
sandbox.stub(utils, 'makeDirFor').resolves();
sandbox.stub(fs, 'writeFileAsync').resolves();
});

afterEach(() => sandbox.restore());

describe('saveBase64Screenshot', () => {
describe('if screenshot on reject does not exist', () => {
it('should not save screenshot', () => {
const test = {
screenshot: {base64: null}
};

return saveBase64Screenshot(test)
.then(() => assert.notCalled(fs.writeFileAsync));
});

it('should warn about it', () => {
const test = {
screenshot: {base64: null}
};

return saveBase64Screenshot(test)
.then(() => assert.calledWith(utils.logger.warn, 'Cannot save screenshot on reject'));
});
});

it('should make directory for screenshot', () => {
const test = {
screenshot: {base64: 'base64-data'}
};
utils.getCurrentAbsolutePath.withArgs(test, 'report/path').returns('dest/path');

return saveBase64Screenshot(test, 'report/path')
.then(() => assert.calledOnceWith(utils.makeDirFor, 'dest/path'));
});

it('should save screenshot from base64 format', () => {
const test = {
screenshot: {base64: 'base64-data'}
};
const bufData = new Buffer('base64-data', 'base64');
utils.getCurrentAbsolutePath.withArgs(test, 'report/path').returns('dest/path');

return saveBase64Screenshot(test, 'report/path')
.then(() => assert.calledOnceWith(fs.writeFileAsync, 'dest/path', bufData, 'base64'));
});
});
});

0 comments on commit 03e044d

Please sign in to comment.