|
1 | | -import {inspect, type InspectOptions} from 'node:util'; |
| 1 | +import {inspect} from 'node:util'; |
2 | 2 |
|
3 | | -import {DEFAULT_INSPECT_OPTIONS, MAX_LINES_COUNT_IN_PRINTED_VALUE} from '../../constants/internal'; |
| 3 | +import { |
| 4 | + DEFAULT_INSPECT_OPTIONS, |
| 5 | + DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE, |
| 6 | +} from '../../constants/internal'; |
4 | 7 |
|
5 | 8 | import {cutVerboseLinesFromPrintedLines} from './cutVerboseLinesFromPrintedLines'; |
6 | 9 | import {getLinesArrayTrimmedToMaxLength} from './getLinesArrayTrimmedToMaxLength'; |
7 | 10 | import {getStringTrimmedToMaxLength} from './getStringTrimmedToMaxLength'; |
8 | 11 |
|
| 12 | +import type {ValueToStringOptions} from '../../types/internal'; |
| 13 | + |
9 | 14 | /** |
10 | 15 | * Returns string presentation of arbitrary value. |
11 | 16 | */ |
12 | 17 | export const valueToString = ( |
13 | 18 | value: unknown, |
14 | | - options: InspectOptions = DEFAULT_INSPECT_OPTIONS, |
| 19 | + options: ValueToStringOptions = DEFAULT_INSPECT_OPTIONS, |
15 | 20 | ): string => { |
| 21 | + const maxLines = options.maxLines ?? DEFAULT_MAX_LINES_COUNT_IN_PRINTED_VALUE; |
| 22 | + |
| 23 | + if (value instanceof Error) { |
| 24 | + for (const symbol of Object.getOwnPropertySymbols(value)) { |
| 25 | + // We remove symbol fields from Playwright error objects, since printing them creates gigantic logs. |
| 26 | + // @ts-expect-error: cannot set symbol to Error |
| 27 | + // eslint-disable-next-line no-param-reassign |
| 28 | + value[symbol] = {}; |
| 29 | + } |
| 30 | + } |
| 31 | + |
16 | 32 | const valueAsString = inspect(value, options); |
17 | 33 | const lines = valueAsString.split('\n'); |
18 | 34 |
|
19 | | - if (lines.length <= MAX_LINES_COUNT_IN_PRINTED_VALUE) { |
| 35 | + if (lines.length <= maxLines) { |
20 | 36 | return getStringTrimmedToMaxLength(valueAsString); |
21 | 37 | } |
22 | 38 |
|
|
0 commit comments