@d2t/vitest-ctrf-json-reporter

中文文档
1.3.0发布于 2025/09/17MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 16.5万

一个创建测试结果报告的测试报告员

中文使用文档
文档目录5 节
  1. 特征
  2. CTRF是什么来着?
  3. 安装
  4. 记者选项
  5. 测试对象属性

Vitest JSON测试结果报告

将 Vitest 测试结果保存为 JSON 文件

一个Vitest测试报告员来创建符合CTRF标准的测试报告.

常见的测试报告格式 确保生成统一的JSON测试报告,独立于正在使用的编程语言或测试框架.

特征

{
  "results": {
    "tool": {
      "name": "vitest"
    },
    "summary": {
      "tests": 1,
      "passed": 1,
      "failed": 0,
      "pending": 0,
      "skipped": 0,
      "other": 0,
      "start": 1706828654274,
      "stop": 1706828655782
    },
    "tests": [
      {
        "name": "ctrf should generate the same report with any tool",
        "status": "passed",
        "duration": 100
      }
    ],
    "environment": {
      "appName": "MyApp",
      "buildName": "MyBuild",
      "buildNumber": "1"
    }
  }
}

CTRF是什么来着?

CTRF是一个通用的JSON测试报告计划,解决JSON测试报告缺乏标准化格式的问题.

工具的一致性 : 不同的测试工具和框架往往以不同格式编写报告。 CTRF确保统一的结构,使得无论使用何种测试工具,都更容易理解和比较报告.

语言和框架不可知论: 它提供了一个通用报告计划,与任何编程语言和测试框架无缝地工作.

促进更好的分析: 有了标准化的格式,对多个平台的测试结果进行方案分析就更加直截了当了.

安装

npm install --save-dev @d2t/vitest-ctrf-json-reporter

将记者添加到您的 vitest. config.js 文件 :

reporters: ['default', ['@d2t/vitest-ctrf-json-reporter', {}]]

运行您的测试 :

npx vitest

你会找到一个名为JSON的文件 ctrf-report.json 输入 ctrf 目录.

记者选项

记者支持多个配置选项:

reporter: [
  [
    '@d2t/vitest-ctrf-json-reporter',
    {
      outputFile: 'custom-name.json', // Optional: Output file name. Defaults to 'ctrf-report.json'.
      outputDir: 'custom-directory', // Optional: Output directory path. Defaults to 'ctrf'.
      minimal: true, // Optional: Generate a minimal report. Defaults to 'false'. Overrides screenshot and testType when set to true
      testType: 'unit', // Optional: Specify the test type (e.g., 'unit', 'component'). Defaults to 'unit'.
      appName: 'MyApp', // Optional: Specify the name of the application under test.
      appVersion: '1.0.0', // Optional: Specify the version of the application under test.
      osPlatform: 'linux', // Optional: Specify the OS platform.
      osRelease: '18.04', // Optional: Specify the OS release version.
      osVersion: '5.4.0', // Optional: Specify the OS version.
      buildName: 'MyApp Build', // Optional: Specify the build name.
      buildNumber: '100', // Optional: Specify the build number.
      buildUrl: 'https://ctrf.io', // Optional: Specify the build url.
      repositoryName: 'ctrf-json', // Optional: Specify the repository name.
      repositoryUrl: 'https://gh.io', // Optional: Specify the repository url.
      branchName: 'main', // Optional: Specify the branch name.
      testEnvironment: 'staging', // Optional: Specify the test environment (e.g. staging, production).
    },
  ],
]

测试对象属性

报告中的试验对象包括: CTRF 属性数字 :

名称类型需求细节
name字符串需求所考之名.
status字符串需求考证结果. 其中一个: passed, (中文(简体) ), failed, (中文(简体) ), skipped, (中文(简体) ), pending, (中文(简体) ), other。 。 。 .
duration数目需求试行刑所需时间,以毫秒计.
message字符串可选如果测试失败, 则失败消息 .
trace字符串可选如果测试失败, 将会捕获到堆栈追踪 .
suite字符串可选测试所属的套房或组.
message字符串可选如果测试失败, 则失败消息 .
trace字符串可选如果测试失败, 将会捕获到堆栈追踪 .
rawStatus字符串可选在映射到 CTRF 状态之前测试的原始vitest状态.
type字符串可选测试类型(例如, unit, (中文(简体) ), component) (中文(简体) ).
filepath字符串可选测试所在项目的文件路径 .
retries数目可选测试的重复次数.
flaky布尔可选表示测试结果是否为片状.
line数目可选如果测试失败, 源文件中的行号 .

版本与发布记录

@d2t/vitest-ctrf-json-reporter 共发布 5 个版本,首次发布于 2025/04/10;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.3.0latest2025/09/171.1 年前
1.2.02025/07/011.4 年前
1.1.02025/04/101.6 年前
1.0.12025/04/101.6 年前
1.0.02025/04/101.6 年前

关于 @d2t/vitest-ctrf-json-reporter 的常见问题

@d2t/vitest-ctrf-json-reporter 是什么?

一个创建测试结果报告的测试报告员

如何安装 @d2t/vitest-ctrf-json-reporter?

在项目目录运行 npm install @d2t/vitest-ctrf-json-reporter,或使用 pnpm add / yarn add / bun add。

@d2t/vitest-ctrf-json-reporter 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@d2t/vitest-ctrf-json-reporter 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@d2t/vitest-ctrf-json-reporter 可以商用吗?

@d2t/vitest-ctrf-json-reporter 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@d2t/vitest-ctrf-json-reporter 的下载量有多少?

根据 npm 官方下载统计,@d2t/vitest-ctrf-json-reporter 在 2026/10/11 – 2026/11/09 这 30 天内被下载 164,686 次,日均约 5,490 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@d2t/vitest-ctrf-json-reporter 还在维护吗?

最新版本 1.3.0 发布于 2025/09/17(1.1 年前);至今共发布 5 个版本,其中过去 12 个月发布了 0 个;首次发布于 2025/04/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。