UNPKG

e2ed

Version:

E2E testing framework over Playwright

34 lines (33 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.valueToString = void 0; const node_util_1 = require("node:util"); const internal_1 = require("../../constants/internal"); const cutVerboseLinesFromPrintedLines_1 = require("./cutVerboseLinesFromPrintedLines"); const getLinesArrayTrimmedToMaxLength_1 = require("./getLinesArrayTrimmedToMaxLength"); const getStringTrimmedToMaxLength_1 = require("./getStringTrimmedToMaxLength"); /** * Returns string presentation of arbitrary value. */ const valueToString = (value, options = internal_1.DEFAULT_INSPECT_OPTIONS) => { const maxLines = options.maxLines ?? internal_1.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 = (0, node_util_1.inspect)(value, options); const lines = valueAsString.split('\n'); if (lines.length <= maxLines) { return (0, getStringTrimmedToMaxLength_1.getStringTrimmedToMaxLength)(valueAsString); } for (let linesIndex = 0; linesIndex < lines.length;) { linesIndex = (0, cutVerboseLinesFromPrintedLines_1.cutVerboseLinesFromPrintedLines)(lines, linesIndex); } const trimmedLines = (0, getLinesArrayTrimmedToMaxLength_1.getLinesArrayTrimmedToMaxLength)(lines); return (0, getStringTrimmedToMaxLength_1.getStringTrimmedToMaxLength)(trimmedLines.join('\n')); }; exports.valueToString = valueToString;