e2ed
Version:
E2E testing framework over Playwright
23 lines (22 loc) • 808 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFunctionCode = void 0;
const DEFAULT_MAX_CODE_LENGTH = 300;
/**
* Get function code with max code length.
* @internal
*/
const getFunctionCode = (fn, maxCodeLength = DEFAULT_MAX_CODE_LENGTH) => {
const fullFunctionCode = Function.prototype.toString.call(fn);
if (fullFunctionCode.length <= maxCodeLength) {
return fullFunctionCode;
}
const halfOfMaxLength = Math.floor(maxCodeLength / 2);
const cuttedSymbolsCount = fullFunctionCode.length - 2 * halfOfMaxLength;
return [
fullFunctionCode.slice(0, halfOfMaxLength),
`...(${cuttedSymbolsCount} symbols)...`,
fullFunctionCode.slice(-halfOfMaxLength),
].join('');
};
exports.getFunctionCode = getFunctionCode;