@d2t/vitest-ctrf-json-reporter

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

A Vitest test reporter to create test results reports

原始使用文档
文档目录5 节
  1. Features
  2. What is CTRF?
  3. Installation
  4. Reporter Options
  5. Test Object Properties

Vitest JSON Test Results Report

Save Vitest test results as a JSON file

A Vitest test reporter to create test reports that follow the CTRF standard.

Common Test Report Format ensures the generation of uniform JSON test reports, independent of programming languages or test framework in use.

Features

  • Generate JSON test reports that are CTRF compliant
  • Straightforward integration with Vitest
{
  "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"
    }
  }
}

What is CTRF?

CTRF is a universal JSON test report schema that addresses the lack of a standardized format for JSON test reports.

Consistency Across Tools: Different testing tools and frameworks often produce reports in varied formats. CTRF ensures a uniform structure, making it easier to understand and compare reports, regardless of the testing tool used.

Language and Framework Agnostic: It provides a universal reporting schema that works seamlessly with any programming language and testing framework.

Facilitates Better Analysis: With a standardized format, programmatically analyzing test outcomes across multiple platforms becomes more straightforward.

Installation

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

Add the reporter to your vitest.config.js file:

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

Run your tests:

npx vitest

You'll find a JSON file named ctrf-report.json in the ctrf directory.

Reporter Options

The reporter supports several configuration options:

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).
    },
  ],
]

Test Object Properties

The test object in the report includes the following CTRF properties:

NameTypeRequiredDetails
nameStringRequiredThe name of the test.
statusStringRequiredThe outcome of the test. One of: passed, failed, skipped, pending, other.
durationNumberRequiredThe time taken for the test execution, in milliseconds.
messageStringOptionalThe failure message if the test failed.
traceStringOptionalThe stack trace captured if the test failed.
suiteStringOptionalThe suite or group to which the test belongs.
messageStringOptionalThe failure message if the test failed.
traceStringOptionalThe stack trace captured if the test failed.
rawStatusStringOptionalThe original vitest status of the test before mapping to CTRF status.
typeStringOptionalThe type of test (e.g., unit, component).
filepathStringOptionalThe file path where the test is located in the project.
retriesNumberOptionalThe number of retries attempted for the test.
flakyBooleanOptionalIndicates whether the test result is flaky.
lineNumberOptionalLine number in the source file if the test failed.

版本与发布记录

@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 是什么?

A Vitest test reporter to create test results reports

如何安装 @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 和提交记录判断。