You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Cypress报告日志中的K/X替换为✔️/❌符号?

替换Cypress终端日志的成功/失败标记为Emoji

实现步骤

直接对cypress-terminal-report生成的日志文本做字符串替换即可,无需修改插件核心配置:

修改e2e.ts中的日志处理代码

在原有日志获取逻辑中增加标记替换步骤,同时将英文标题改为中文:

import "cypress-mochawesome-reporter/register"
afterEach(() => {
   cy.wait(50, { log: false }).then(() => {
      // 获取原始日志并替换标记
      const rawLogs = Cypress.TerminalReport.getLogs("txt");
      const formattedLogs = rawLogs
        .replace(/\(K\)/g, "(✔️)")
        .replace(/\(X\)/g, "(❌)");
      
      cy.addTestContext({
         title: "执行日志",
         value: formattedLogs,
      })
   })
})
const logsCollectorOptions = {
   collectTypes: ["cy:command", "cy:log"],
}
require("cypress-terminal-report/src/installLogsCollector")(logsCollectorOptions)

效果验证

修改后生成的HTML报告中,日志会显示为:

cy:command (✔️): click
cy:command (❌): contains Peter

内容的提问来源于stack exchange,提问作者Marcus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 18:02:41