@barney-media/crap-typescript-vitest

中文文档
2.0.0发布于 2026/10/19Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 1.5万

Vitest integration for crap-typescript.

原始使用文档
文档目录3 节
  1. Install
  2. Setup
  3. License

@barney-media/crap-typescript-vitest

Vitest adapter for crap-typescript. Enables Istanbul JSON coverage output and reports CRAP scores after test runs.

Install

npm install --save-dev @barney-media/crap-typescript-vitest [email protected] @vitest/[email protected] vite@^8.3.4

Vitest 4 and 5 are supported. Install the same version of vitest and @vitest/coverage-v8; the clean-consumer matrix exercises 4.1.12 and 5.0.5. For Vitest 4, replace both 5.0.5 versions above with 4.1.12. Install Vite explicitly, particularly with Yarn, because Vitest 5 declares it as a required peer. Node.js 22/24/26 are fully supported on Windows, macOS, and Linux; use current security patches.

Setup

import { withCrapTypescriptVitest } from "@barney-media/crap-typescript-vitest";

export default withCrapTypescriptVitest({
  test: {
    include: ["test/**/*.test.ts"]
  }
});

withCrapTypescriptVitest wraps your Vitest config to enable coverage collection and register the CRAP reporter. The test run fails when any function exceeds the CRAP threshold.

If test.coverage.enabled is explicitly false, the helper preserves that value and does not register the CRAP reporter. Coverage provider, reporter, and directory settings are still normalized, but threshold enforcement resumes only when coverage is enabled again.

When test.reporters is omitted, the helper keeps the default reporter and adds the CRAP reporter. An explicit reporter value or array replaces that default; the helper preserves the configured entries and adds only the CRAP reporter. When coverage.reporter is omitted, it defaults to json and text. An explicit coverage reporter value is preserved and augmented only with the required json reporter when needed. Set both reporter options to empty arrays to keep only the CRAP and JSON reporters and suppress Vitest's test and coverage terminal reports.

The reporter defaults primary format to none, so it emits no primary stdout report unless configured. It enables junit by default and writes a full sidecar for CI test-report UIs. With the default coverage report path, the sidecar is coverage/crap-typescript-junit.xml; custom coverage paths derive a matching sidecar path. Pass format, agent, failuresOnly, omitRedundancy, output, junit, junitReport, threshold, excludes, excludePathRegexes, excludeGeneratedMarkers, or useDefaultExclusions in the adapter options to customize analysis and reporting. Set junit: false to disable the JUnit artifact.

agent: true defaults primary output to format: "toon", failuresOnly: true, and omitRedundancy: true. Explicit format, failuresOnly: false, or omitRedundancy: false options override those defaults. JUnit sidecars are full reports and are not affected by agent, failuresOnly, or omitRedundancy.

Baseline analyzability exclusions always skip declarations, test/spec files, __tests__/, dist/, coverage/, and node_modules/. Generated-code defaults exclude generated directory segments, exact gen directory segments, common generated filename suffixes, protobuf outputs, Angular generated artifacts, and leading generated-header markers. User exclusions compose with defaults unless useDefaultExclusions: false; full reports and JUnit sidecars include exclusion audit counts when files were excluded.

The default threshold is 6.0; values below 4.0 or above 8.0 print the same threshold guidance warnings as the CLI.

Exit code 2 means the CRAP threshold was exceeded. Reporter errors such as invalid options, missing coverage, or report-write failures use exit code 1.

See the main documentation for full details.

License

Apache-2.0

版本与发布记录

@barney-media/crap-typescript-vitest 共发布 14 个版本,首次发布于 2026/04/08;过去 12 个月发布了 14 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.0.0latest2026/10/1920 天前
1.0.02026/09/281 个月前
0.5.32026/09/261 个月前
0.5.22026/09/052 个月前
0.5.12026/08/302 个月前
0.5.02026/08/092 个月前

关于 @barney-media/crap-typescript-vitest 的常见问题

@barney-media/crap-typescript-vitest 是什么?

Vitest integration for crap-typescript.

如何安装 @barney-media/crap-typescript-vitest?

在项目目录运行 npm install @barney-media/crap-typescript-vitest,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:vitest(^4.0.0 || ^5.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@barney-media/crap-typescript-vitest 支持 TypeScript 吗?

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

@barney-media/crap-typescript-vitest 支持 ESM 还是 CommonJS?

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

@barney-media/crap-typescript-vitest 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@barney-media/crap-typescript-vitest 可以商用吗?

@barney-media/crap-typescript-vitest 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@barney-media/crap-typescript-vitest 的下载量有多少?

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

@barney-media/crap-typescript-vitest 还在维护吗?

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