e2ed
Version:
E2E testing framework over Playwright
32 lines (31 loc) • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wrapStringForLogs = void 0;
const node_util_1 = require("node:util");
const getLinesArrayTrimmedToMaxLength_1 = require("./getLinesArrayTrimmedToMaxLength");
const getStringTrimmedToMaxLength_1 = require("./getStringTrimmedToMaxLength");
function toMultipleString() {
const lines = this.split('\n');
return `\`\n ${lines.join('\n ')}\n\``;
}
/**
* If the text consists of several lines, replaces the text with an object
* with a more beautiful presentation through `nodejs` `inspect`.
* @internal
*/
const wrapStringForLogs = (text, options) => {
if (!text.includes('\n')) {
return (0, getStringTrimmedToMaxLength_1.getStringTrimmedToMaxLength)(text);
}
const lines = text.split('\n');
const trimmedLines = (0, getLinesArrayTrimmedToMaxLength_1.getLinesArrayTrimmedToMaxLength)(lines);
const trimmedText = (0, getStringTrimmedToMaxLength_1.getStringTrimmedToMaxLength)(trimmedLines.join('\n'));
// eslint-disable-next-line no-new-wrappers
const result = new String(trimmedText);
// eslint-disable-next-line @typescript-eslint/unbound-method
const toString = options?.doNotWrapInBacktick ? String.prototype.toString : toMultipleString;
result[node_util_1.inspect.custom] = toString;
result.toJSON = toString;
return result;
};
exports.wrapStringForLogs = wrapStringForLogs;