From fa4c04b30ed774936f494eb6dd695a9c5f47f53f Mon Sep 17 00:00:00 2001 From: DudaGod Date: Thu, 17 Oct 2024 15:57:43 +0300 Subject: [PATCH] fix: do not fall with enabled debug log when compare images --- lib/common-utils.ts | 2 +- test/unit/lib/common-utils.ts | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/common-utils.ts b/lib/common-utils.ts index 8d4218b2d..2fe6b0c07 100644 --- a/lib/common-utils.ts +++ b/lib/common-utils.ts @@ -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 => { diff --git a/test/unit/lib/common-utils.ts b/test/unit/lib/common-utils.ts index 7ffc19b03..3308eba0e 100644 --- a/test/unit/lib/common-utils.ts +++ b/test/unit/lib/common-utils.ts @@ -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', () => { @@ -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)); + }); + }); });