Vitest JSON测试结果报告
将 Vitest 测试结果保存为 JSON 文件
一个Vitest测试报告员来创建符合CTRF标准的测试报告.
常见的测试报告格式 确保生成统一的JSON测试报告,独立于正在使用的编程语言或测试框架.
特征
- 生成 JSON 测试报告 通用报告格式 达标
- 直接与 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"
}
}
}
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 | 数目 | 可选 | 如果测试失败, 源文件中的行号 . |