From 8551bb9862cefa19a2e80c21ee1fa4e062ad0891 Mon Sep 17 00:00:00 2001 From: uid11 Date: Wed, 21 Jan 2026 18:42:17 +0300 Subject: [PATCH] PRO-12276 fix: console/file log messages from `expect` methods --- src/utils/expect/assertionMessageGetters.ts | 2 +- src/utils/expect/createExpectMethod.ts | 29 ++++++++++++++------- src/utils/selectors/Selector.ts | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/utils/expect/assertionMessageGetters.ts b/src/utils/expect/assertionMessageGetters.ts index ee728922..856bd7f6 100644 --- a/src/utils/expect/assertionMessageGetters.ts +++ b/src/utils/expect/assertionMessageGetters.ts @@ -18,6 +18,6 @@ export const assertionMessageGetters: AssertionFunctionsRecord = { notEql: (unexpected) => `is not deeply equal to ${valueToString(unexpected)}`, notOk: () => 'is falsy', ok: () => 'is truthy', - toBeInViewport: () => 'element intersects viewport', + toBeInViewport: () => 'intersects viewport', toMatchScreenshot: (expected) => `matches the expected screenshot ${valueToString(expected)}`, }; diff --git a/src/utils/expect/createExpectMethod.ts b/src/utils/expect/createExpectMethod.ts index b9d7a732..549b1154 100644 --- a/src/utils/expect/createExpectMethod.ts +++ b/src/utils/expect/createExpectMethod.ts @@ -3,6 +3,7 @@ import {LogEventStatus, LogEventType, RETRY_KEY} from '../../constants/internal' import {assertValueIsDefined} from '../asserts'; import {getFullPackConfig} from '../config'; import {E2edError} from '../error'; +import {generalLog} from '../generalLog'; import {getDurationWithUnits} from '../getDurationWithUnits'; import {logAndGetLogEvent} from '../log'; import {setReadonlyProperty} from '../object'; @@ -33,7 +34,8 @@ export const createExpectMethod = ( const {assertionTimeout} = getFullPackConfig(); const timeout = assertionTimeout + additionalAssertionTimeoutInMs; - const message = getAssertionMessage === undefined ? key : getAssertionMessage(...args); + const assertionMessage = getAssertionMessage === undefined ? key : getAssertionMessage(...args); + const message = `Assert: ${this.description}`; const selectorPropertyRetryData = ( this.actualValue as {[RETRY_KEY]?: SelectorPropertyRetryData} @@ -41,10 +43,10 @@ export const createExpectMethod = ( const printedValue = isThenable(this.actualValue) ? '' : this.actualValue; const logEvent = logAndGetLogEvent( - `Assert: ${this.description}`, + message, { actualValue: printedValue, - assertion: wrapStringForLogs(`value ${valueToString(printedValue)} ${message}`), + assertion: wrapStringForLogs(`value ${valueToString(printedValue)} ${assertionMessage}`), assertionArguments: args, selector: selectorPropertyRetryData?.selector.description ?? @@ -79,29 +81,36 @@ export const createExpectMethod = ( }); return assertionPromise.then(({actualValue, additionalLogFields, error}) => { - Object.assign(payload, { + const additionalPayload = { ...additionalLogFields, error: error?.message === undefined ? undefined : removeStyleFromString(error.message), logEventStatus: error ? LogEventStatus.Failed : LogEventStatus.Passed, - }); + }; + + Object.assign(payload, additionalPayload); return addTimeoutToPromise(Promise.resolve(actualValue), timeout, timeoutError) .then( (value) => { - Object.assign(payload, { - actualValue: value, - assertion: wrapStringForLogs(`value ${valueToString(value)} ${message}`), - }); + Object.assign( + payload, + Object.assign(additionalPayload, { + actualValue: value, + assertion: wrapStringForLogs(`value ${valueToString(value)} ${assertionMessage}`), + }), + ); setReadonlyProperty(logEvent, 'endTime', Date.now() as UtcTimeInMs); }, (actualValueResolveError: Error) => { - Object.assign(payload, {actualValueResolveError}); + Object.assign(payload, Object.assign(additionalPayload, {actualValueResolveError})); setReadonlyProperty(logEvent, 'endTime', Date.now() as UtcTimeInMs); }, ) .then(() => { + generalLog(`Assert "${this.description}" completed`, additionalPayload); + if (error) { throw error; } diff --git a/src/utils/selectors/Selector.ts b/src/utils/selectors/Selector.ts index b85be74d..d3d1c13c 100644 --- a/src/utils/selectors/Selector.ts +++ b/src/utils/selectors/Selector.ts @@ -325,7 +325,7 @@ class Selector { * Custom string presentation of selector. */ toString(): string { - return `Selector for ${this.description}`; + return ``; } withText(textOrRegExp: RegExp | string): Selector {