UNPKG

e2ed

Version:

E2E testing framework over Playwright

63 lines (62 loc) 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); // eslint-disable-next-line import/no-unused-modules const node_path_1 = require("node:path"); const object_1 = require("../object"); const uiMode_1 = require("./uiMode"); if (uiMode_1.isUiMode) { const e2edPathPart = [node_path_1.sep, 'node_modules', node_path_1.sep, 'e2ed', node_path_1.sep].join(''); const OriginalError = globalThis.Error; const originalErrorString = String(OriginalError); // eslint-disable-next-line no-restricted-syntax globalThis.Error = function Error(message, options) { const error = new OriginalError(message, options); const descriptor = Object.getOwnPropertyDescriptor(error, 'stack'); if (descriptor && 'value' in descriptor) { const { value } = descriptor; if (typeof value === 'string') { const parts = value.split('\n'); const filteredParts = parts.filter((line) => { if (line.includes(e2edPathPart)) { return false; } return true; }); const newValue = filteredParts.join('\n'); error.stack = newValue; } else if (Array.isArray(value)) { const filtered = value.filter((stackFrame) => { if (stackFrame !== null && typeof stackFrame === 'object' && 'getScriptNameOrSourceURL' in stackFrame && typeof stackFrame.getScriptNameOrSourceURL === 'function') { const sourceUrl = stackFrame.getScriptNameOrSourceURL(); if (typeof sourceUrl === 'string' && sourceUrl.includes(e2edPathPart)) { return false; } } return true; }); error.stack = filtered; } } return error; }; (0, object_1.setReadonlyProperty)(Error, 'prototype', OriginalError.prototype); Object.assign(globalThis.Error.prototype, { browserLogMessage() { return ''; }, constructor: Error, setMessage(message) { this.message = message; }, }); // eslint-disable-next-line @typescript-eslint/unbound-method Error.captureStackTrace = OriginalError.captureStackTrace; // eslint-disable-next-line @typescript-eslint/unbound-method Error.prepareStackTrace = OriginalError.prepareStackTrace; Error.stackTraceLimit = OriginalError.stackTraceLimit; Error.toString = () => originalErrorString; }