UNPKG

cypress-terminal-report

Version:

Better terminal and file output for cypress test logs.

38 lines (37 loc) 1.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = __importDefault(require("../constants")); const LogCollectBase_1 = __importDefault(require("./LogCollectBase")); Object.defineProperty(RegExp.prototype, 'toJSON', { value: RegExp.prototype.toString, }); class LogCollectCypressIntercept extends LogCollectBase_1.default { register() { Cypress.Commands.overwrite('intercept', (originalFn, ...args) => { let message = ''; if (typeof args[0] === 'string' && constants_1.default.HTTP_METHODS.includes(args[0].toUpperCase())) { message += `Method: ${args[0]}\nMatcher: ${JSON.stringify(args[1])}`; if (args[2]) { message += `\nMocked Response: ${typeof args[2] === 'object' ? JSON.stringify(args[2]) : args[2]}`; } } else { message += `Matcher: ${JSON.stringify(args[0])}`; if (args[1]) { message += `\nMocked Response: ${typeof args[1] === 'object' ? JSON.stringify(args[1]) : args[1]}`; } } this.collectorState.addLog([ constants_1.default.LOG_TYPES.CYPRESS_INTERCEPT, message, constants_1.default.SEVERITY.SUCCESS, ]); return originalFn(...args); }); } } exports.default = LogCollectCypressIntercept;