Skip to content

Commit

Permalink
Merge pull request #610 from gemini-testing/TESTPLANE-308.fix_debug_log
Browse files Browse the repository at this point in the history
fix: do not fall with enabled debug log when compare images
  • Loading branch information
DudaGod authored Oct 21, 2024
2 parents 03df9c5 + fa4c04b commit 7e396d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const getTestHash = (testResult: ReporterTestResult): string => {
};

export const isImageBufferData = (imageData: ImageBuffer | ImageFile | ImageBase64 | undefined): imageData is ImageBuffer => {
return Boolean((imageData as ImageBuffer).buffer);
return Boolean(imageData && (imageData as ImageBuffer).buffer);
};

export const isImageInfoWithState = (imageInfo: ImageInfoFull): imageInfo is ImageInfoWithState => {
Expand Down
25 changes: 24 additions & 1 deletion test/unit/lib/common-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import {
getUrlWithBase,
getDetailsFileName,
trimArray,
mergeSnippetIntoErrorStack
mergeSnippetIntoErrorStack,
isImageBufferData
} from 'lib/common-utils';
import {RUNNING, QUEUED, ERROR, FAIL, UPDATED, SUCCESS, IDLE, SKIPPED} from 'lib/constants/test-statuses';
import {ErrorName} from 'lib/errors';
import sinon from 'sinon';

import type {ImageBuffer} from 'lib/types';

const withGray = (line: string): string => '\x1B[90m' + line + '\x1B[39m';

describe('common-utils', () => {
Expand Down Expand Up @@ -269,4 +272,24 @@ describe('common-utils', () => {
assert.equal(result.stack, 'Error: my\nerror\nmessage\nsnippet\n' + withGray('my stack'));
});
});

describe('isImageBufferData', () => {
describe('should return "false" if', () => {
it('image is not passed', () => {
assert.isFalse(isImageBufferData(undefined));
});

it('"buffer" field doesn\'t exists in image data', () => {
const imageData = {} as ImageBuffer;

assert.isFalse(isImageBufferData(imageData));
});
});

it('should return "true" if "buffer" field exists in image data', () => {
const imageData = {buffer: Buffer.from('some-buffer')};

assert.isTrue(isImageBufferData(imageData));
});
});
});

0 comments on commit 7e396d4

Please sign in to comment.