UNPKG

e2ed

Version:

E2E testing framework over Playwright

75 lines (74 loc) 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.E2edError = void 0; const node_util_1 = require("node:util"); const internal_1 = require("../../constants/internal"); const valueToString_1 = require("../valueToString"); const getPrintedFields_1 = require("./getPrintedFields"); const getPrintedStackFrame_1 = require("./getPrintedStackFrame"); const getStackTrace_1 = require("./getStackTrace"); /** * Extended Error class for e2ed. */ class E2edError extends Error { /** * Error message. */ message; /** * Optional params of error. */ params; /** * Current runLabel at the time the error was created */ runLabel; /** * Current V8 stack trace (if available). */ stackTrace; /** * The time the error was generated. */ utcTimeInMs; constructor(rawMessage, params) { const message = (0, valueToString_1.removeStyleFromString)(rawMessage); const runLabel = internal_1.e2edEnvironment[internal_1.RUN_LABEL_VARIABLE_NAME]; const utcTimeInMs = Date.now(); const constructorArgs = [message]; if (params?.cause !== undefined) { constructorArgs.push({ cause: params.cause }); } super(...constructorArgs); this.message = message; this.params = params; if (params?.cause !== undefined) { this.cause = params.cause; } this.runLabel = runLabel; const framesStackTrace = (0, getStackTrace_1.getStackTrace)() ?? []; this.stackTrace = framesStackTrace.map(getPrintedStackFrame_1.getPrintedStackFrame); this.utcTimeInMs = utcTimeInMs; } /** * Custom JSON presentation of error. */ // eslint-disable-next-line @typescript-eslint/naming-convention toJSON() { return (0, getPrintedFields_1.getPrintedFields)(this); } /** * Custom string presentation of error. */ toString() { const printedFields = (0, getPrintedFields_1.getPrintedFields)(this); const printedString = (0, valueToString_1.valueToString)(printedFields); return `E2edError ${printedString}`; } } exports.E2edError = E2edError; /** * Custom presentation of error for `nodejs` `inspect`. */ // eslint-disable-next-line @typescript-eslint/unbound-method E2edError.prototype[node_util_1.inspect.custom] = E2edError.prototype.toString;