diff --git a/src/constants/inspect.ts b/src/constants/inspect.ts index e574bed2..cba344c2 100644 --- a/src/constants/inspect.ts +++ b/src/constants/inspect.ts @@ -6,11 +6,18 @@ const averageLineLength = 100; */ export const DEFAULT_INSPECT_OPTIONS = { colors: false, - depth: 16, - numericSeparator: true, + depth: 12, + getters: false, + numericSeparator: false, showHidden: true, } as const; +/** + * Default max number of lines in printed stringify values (in logs). + * @internal + */ +export const DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE = 300; + /** * Inspect options for output to console. * @internal @@ -26,15 +33,9 @@ export const CONSOLE_INSPECT_OPTIONS = { */ export const MAX_ELEMENTS_COUNT_IN_PRINTED_ARRAY = 8; -/** - * Max number of lines in printed stringify values (in logs). - * @internal - */ -export const MAX_LINES_COUNT_IN_PRINTED_VALUE = 300; - /** * Max string length in printed stringify values (in logs). * @internal */ export const MAX_STRING_LENGTH_IN_PRINTED_VALUE = - averageLineLength * MAX_LINES_COUNT_IN_PRINTED_VALUE; + averageLineLength * DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE; diff --git a/src/constants/internal.ts b/src/constants/internal.ts index 40205199..12bbdef5 100644 --- a/src/constants/internal.ts +++ b/src/constants/internal.ts @@ -35,8 +35,8 @@ export { export { CONSOLE_INSPECT_OPTIONS, DEFAULT_INSPECT_OPTIONS, + DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE, MAX_ELEMENTS_COUNT_IN_PRINTED_ARRAY, - MAX_LINES_COUNT_IN_PRINTED_VALUE, MAX_STRING_LENGTH_IN_PRINTED_VALUE, } from './inspect'; export {BACKEND_RESPONSES_LOG_MESSAGE, LogEventStatus, LogEventType} from './log'; diff --git a/src/types/index.ts b/src/types/index.ts index 6ad7bf2e..b243ed72 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -45,7 +45,7 @@ export type { Url, } from './http'; export type {KeyboardPressKey} from './keyboard'; -export type {Log, LogContext, LogParams, LogPayload, LogTag} from './log'; +export type {Log, LogContext, LogParams, LogPayload, LogTag, ValueToStringOptions} from './log'; export type { Dimensions, DimensionsString, diff --git a/src/types/internal.ts b/src/types/internal.ts index 505872d5..5f7145c0 100644 --- a/src/types/internal.ts +++ b/src/types/internal.ts @@ -76,6 +76,7 @@ export type { MapLogPayload, MapLogPayloadInReport, Payload, + ValueToStringOptions, } from './log'; export type { Dimensions, diff --git a/src/types/log.ts b/src/types/log.ts index 95358e79..71dc9ab1 100644 --- a/src/types/log.ts +++ b/src/types/log.ts @@ -1,3 +1,5 @@ +import type {InspectOptions} from 'node:util'; + import type {LogEventStatus, LogEventType} from '../constants/internal'; import type {ResponseWithRequest} from './http'; @@ -32,6 +34,7 @@ export type LogPayload = Readonly<{ filePath?: unknown; logEventStatus?: LogEventStatus; logTag?: LogTag; + maxLinesCountInPrintedValue?: number; successful?: unknown; }> & Payload; @@ -77,3 +80,8 @@ export type MapLogPayloadInReport = ( * Object with some payload. */ export type Payload = Readonly>; + +/** + * Options of `valueToString` function. + */ +export type ValueToStringOptions = Readonly; diff --git a/src/utils/events/registerStartE2edRunEvent.ts b/src/utils/events/registerStartE2edRunEvent.ts index 9a6302c6..8650aeae 100644 --- a/src/utils/events/registerStartE2edRunEvent.ts +++ b/src/utils/events/registerStartE2edRunEvent.ts @@ -81,7 +81,7 @@ export const registerStartE2edRunEvent = async (): Promise => { const isLocalRun = runEnvironment !== RunEnvironment.Docker; const startMessage = `Run tests ${isLocalRun ? 'local' : 'in docker'} with e2ed@${e2ed.version}`; - generalLog(startMessage, startInfo); + generalLog(startMessage, {...startInfo, maxLinesCountInPrintedValue: 1024}); } finally { await writeStartInfo(startInfo); await writeLogsToFile(); diff --git a/src/utils/generalLog/getLogMessageBody.ts b/src/utils/generalLog/getLogMessageBody.ts index b8614793..0bfc9b85 100644 --- a/src/utils/generalLog/getLogMessageBody.ts +++ b/src/utils/generalLog/getLogMessageBody.ts @@ -1,8 +1,8 @@ -import {CONSOLE_INSPECT_OPTIONS} from '../../constants/internal'; +import {CONSOLE_INSPECT_OPTIONS, DEFAULT_INSPECT_OPTIONS} from '../../constants/internal'; import {valueToString} from '../valueToString'; -import type {LogContext, LogPayload} from '../../types/internal'; +import type {LogContext, LogPayload, ValueToStringOptions} from '../../types/internal'; /** * Get body of log message by context, isLogInConsole flag and log payload. @@ -20,5 +20,15 @@ export const getLogMessageBody = ( return ''; } - return ` ${valueToString(printedPayload, isLogInConsole ? CONSOLE_INSPECT_OPTIONS : undefined)}`; + const maxLines = payload == null ? undefined : payload.maxLinesCountInPrintedValue; + + let options: ValueToStringOptions = isLogInConsole + ? CONSOLE_INSPECT_OPTIONS + : DEFAULT_INSPECT_OPTIONS; + + if (maxLines !== undefined) { + options = {...options, maxLines}; + } + + return ` ${valueToString(printedPayload, options)}`; }; diff --git a/src/utils/valueToString/getLinesArrayTrimmedToMaxLength.ts b/src/utils/valueToString/getLinesArrayTrimmedToMaxLength.ts index 2c8f179c..b60a316e 100644 --- a/src/utils/valueToString/getLinesArrayTrimmedToMaxLength.ts +++ b/src/utils/valueToString/getLinesArrayTrimmedToMaxLength.ts @@ -1,4 +1,4 @@ -import {MAX_LINES_COUNT_IN_PRINTED_VALUE} from '../../constants/internal'; +import {DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE} from '../../constants/internal'; const additionalLinesForRepeatedTrimmerRuns = 4; @@ -6,12 +6,15 @@ const additionalLinesForRepeatedTrimmerRuns = 4; * Get lines array trimmed to max lines count in printed value. * @internal */ -export const getLinesArrayTrimmedToMaxLength = (lines: readonly string[]): readonly string[] => { - if (lines.length <= MAX_LINES_COUNT_IN_PRINTED_VALUE + additionalLinesForRepeatedTrimmerRuns) { +export const getLinesArrayTrimmedToMaxLength = ( + lines: readonly string[], + maxLines = DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE, +): readonly string[] => { + if (lines.length <= maxLines + additionalLinesForRepeatedTrimmerRuns) { return lines; } - const halfOfLines = Math.floor(MAX_LINES_COUNT_IN_PRINTED_VALUE / 2); + const halfOfLines = Math.floor(maxLines / 2); const cuttedLinesCount = lines.length - 2 * halfOfLines; return [ diff --git a/src/utils/valueToString/valueToString.ts b/src/utils/valueToString/valueToString.ts index 595d396c..0db33772 100644 --- a/src/utils/valueToString/valueToString.ts +++ b/src/utils/valueToString/valueToString.ts @@ -1,22 +1,38 @@ -import {inspect, type InspectOptions} from 'node:util'; +import {inspect} from 'node:util'; -import {DEFAULT_INSPECT_OPTIONS, MAX_LINES_COUNT_IN_PRINTED_VALUE} from '../../constants/internal'; +import { + DEFAULT_INSPECT_OPTIONS, + DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE, +} from '../../constants/internal'; import {cutVerboseLinesFromPrintedLines} from './cutVerboseLinesFromPrintedLines'; import {getLinesArrayTrimmedToMaxLength} from './getLinesArrayTrimmedToMaxLength'; import {getStringTrimmedToMaxLength} from './getStringTrimmedToMaxLength'; +import type {ValueToStringOptions} from '../../types/internal'; + /** * Returns string presentation of arbitrary value. */ export const valueToString = ( value: unknown, - options: InspectOptions = DEFAULT_INSPECT_OPTIONS, + options: ValueToStringOptions = DEFAULT_INSPECT_OPTIONS, ): string => { + const maxLines = options.maxLines ?? DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE; + + if (value instanceof Error) { + for (const symbol of Object.getOwnPropertySymbols(value)) { + // We remove symbol fields from Playwright error objects, since printing them creates gigantic logs. + // @ts-expect-error: cannot set symbol to Error + // eslint-disable-next-line no-param-reassign + value[symbol] = {}; + } + } + const valueAsString = inspect(value, options); const lines = valueAsString.split('\n'); - if (lines.length <= MAX_LINES_COUNT_IN_PRINTED_VALUE) { + if (lines.length <= maxLines) { return getStringTrimmedToMaxLength(valueAsString); }