# @d2t/vitest-ctrf-json-reporter 中文文档

规范地址：https://npmcn.com/package/%40d2t/vitest-ctrf-json-reporter/

版本：1\.3\.0
npm 元数据更新时间：2025-09-17T08:42:22.774Z
中文译文更新时间：2026-11-11T07:55:56.037Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40d2t/vitest-ctrf-json-reporter
原文对照：https://npmcn.com/package/%40d2t/vitest-ctrf-json-reporter/?lang=original
项目主页：https://github.com/david2tm/d2t-vitest-ctrf-json-reporter#readme
源码仓库：https://github.com/david2tm/d2t-vitest-ctrf-json-reporter

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：18.3 kB，6 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2025-04-10T08:55:42.317Z
- 最新版本发布：2025-09-17T08:42:22.355Z
- 近 30 天下载量：164686（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：5（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @d2t/vitest-ctrf-json-reporter
```

也可以使用：`pnpm add @d2t/vitest-ctrf-json-reporter`、`yarn add @d2t/vitest-ctrf-json-reporter`、`bun add @d2t/vitest-ctrf-json-reporter`

## README

# Vitest JSON测试结果报告

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

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

[常见的测试报告格式](https://ctrf.io/) 确保生成统一的JSON测试报告,独立于正在使用的编程语言或测试框架.

## 特征

-   生成 JSON 测试报告 [通用报告格式](https://ctrf.io/) 达标
-   直接与 Vitest 合并

```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确保统一的结构,使得无论使用何种测试工具,都更容易理解和比较报告.

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

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

## 安装

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

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

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

运行您的测试 :

```bash
npx vitest
```

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

## 记者选项

记者支持多个配置选项:

```javascript
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 属性](https://ctrf.io/docs/schema/test)数字 :

| 名称 | 类型 | 需求 | 细节 |
| --- | --- | --- | --- |
| `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 是什么？

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

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

