@barney-media/cognitive-typescript-vitest
v0.2.1
Published
Vitest integration for cognitive-typescript.
Maintainers
Readme
@barney-media/cognitive-typescript-vitest
Vitest adapter for cognitive-typescript. It runs Cognitive Complexity analysis after the test run and fails the process when the configured threshold is exceeded.
Install
npm install --save-dev @barney-media/cognitive-typescript-vitest vitestSetup
import { defineConfig } from "vitest/config";
import { withCognitiveTypescriptVitest } from "@barney-media/cognitive-typescript-vitest";
export default withCognitiveTypescriptVitest(
defineConfig({
test: {
include: ["test/**/*.test.ts"]
}
}),
{
changedOnly: true,
format: "text",
output: "reports/cognitive.txt",
junitReport: "reports/cognitive-junit.xml",
threshold: 12
}
);Supported options:
projectRootchangedOnlypathsexcludesexcludeNamesexcludeDecoratorsexcludeCommentsuseDefaultExclusionsformatagentfailuresOnlyomitRedundancyoutputjunitjunitReportthresholdstdoutstderr
Default exclusions cover declaration files, generated/build directories, generated file-name suffixes, existing test-file defaults, and the leading generated-code markers @generated and <auto-generated.
Full primary reports and JUnit sidecars include exclusion audit counts. Compact agent primary output omits exclusion audit detail by default.
Reporter defaults:
- primary format defaults to
none agent: trueswitches the primary output defaults to compacttoon- JUnit is enabled by default at
reports/cognitive-typescript/TEST-cognitive-typescript.xml junit: falsedisables the sidecar entirely
This adapter stays in the static-analysis lane. It does not collect coverage or compute CRAP scores; it analyzes the selected TypeScript sources after Vitest finishes.
The package also exports CognitiveTypescriptVitestReporter for direct reporter registration.
See the main repository for full details.
