Skip to content
PluginStats

vitest-bats weekly downloads statistics

By spencerbeggs · npm · Testing

Test bash scripts with kcov coverage directly in Vitest

View on npm Fresh · Dec 6, 2026

vitest-bats has 273 recorded weekly downloads on npm, an increase of 2933% over the past 30 days, ranking #2405 of 3,247 tracked listings.

Weekly downloads
273
Official API · Dec 5, 2026
7-day growth
+187%
+178 weekly downloads
30-day growth
+2933%
+264 weekly downloads
90-day growth
+84.5%
+125 weekly downloads
Rank
#2405
▲ 104 in 7 days

About vitest-bats

vitest-bats

A Vitest plugin for testing bash scripts with BATS and collecting kcov coverage, merged into Vitest's standard v8 coverage report.

Features

  • Single plugin setup -- BatsPlugin() handles dependency detection, reporter injection, environment configuration, and matcher registration
  • Native .sh imports -- import script from "./hello.sh" returns a builder. Configure with env() / flags() / mock(), terminate with run(...args) or exec(shellExpr).
  • 23 expect.extend matchers -- toSucceed, toContainOutput, toHaveJsonValue, toMatchSchema, toHaveInvoked, and more. Auto-registered via setup file -- no user setup required.
  • Schema validation -- toMatchSchema accepts any Standard Schema validator (Zod, Valibot, Arktype, Effect Schema). toMatchJsonSchema validates raw JSON Schema via Ajv.
  • Self-contained command mocking -- .mock("git", { "remote get-url *": "echo https://example.com" }) embeds shim binaries that record calls and emit pre-recorded responses. No bats-mock runtime dependency.
  • Unified coverage -- Shell script coverage from kcov is merged into the v8 Istanbul CoverageMap and reported alongside TypeScript coverage.

Installation

npm install --save-dev vitest-bats vitest

vitest-bats requires vitest >= 4.1.0 and BATS >= 1.5 (for the run --separate-stderr form used to capture stderr separately).

System Dependencies

These must be installed on the host (or in your Docker container):

DependencyRequiredInstall (macOS)Install (Linux)
bats (>= 1.5)Yesbrew install bats-coreapt-get install bats
bats-supportYesbrew install bats-supportapt-get install bats-support
bats-assertYesbrew install bats-assertapt-get install bats-assert
bats-mockYesbrew install bats-mockapt-get install bats-file
jqYesbrew install jqapt-get install jq
kcovCoverage onlybrew install kcovapt-get install kcov

bats-assert and bats-mock are still detected at startup for compatibility warnings; the runtime no longer loads them. Mocks are self-contained, and assertions happen in TypeScript via the matchers below.

Quick Start

1. Configure Vitest
// vitest.config.ts
import { defineConfig } from "vitest/config";
import { BatsPlugin } from "vitest-bats";

export default defineConfig({
  plugins: [BatsPlugin()],
  test: {
    include: ["__test__/**/*.test.ts"],
    coverage: {
      provider: "v8",
    },
  },
});

The plugin auto-injects vitest-bats/setup into test.setupFiles. Do not add it manually -- it registers all matchers and a beforeEach builder reset.

2. Add the .sh module type

In tsconfig.json, add vitest-bats to types so TypeScript understands .sh imports:

{
  "compilerOptions": {
    "types": ["vitest-bats"]
  }
}
3. Write Tests
// __test__/hello.test.ts
import { describe, expect, test } from "vitest";
import hello from "../scripts/hello.sh";

describe("hello.sh", () => {
  test("outputs default greeting", () => {
    const result = hello.run();
    expect(result).toSucceed();
    expect(result).toContainOutput("Hello World");
  });

  test("greets by name", () => {
    const result = hello.run("--name", "Alice");
    expect(result).toSucceed();
    expect(result).toContainOutput("Hello Alice");
  });

  test("outputs JSON with --json flag", () => {
    const result = hello.run("--json");
    expect(result).toSucceed();
    expect(result).toHaveJsonValue("greeting", "Hello World");
  });

  test("rejects unknown arguments", () => {
    const result = hello.run("--invalid");
    expect(result).toFail();
    expect(result).toContainStderr("Unknown option");
  });
});

run() returns a BatsResult synchronously. await is harmless but unnecessary -- BatsResult is not thenable.

4. Run Tests
vitest run
vitest run --coverage  # With coverage (requires kcov on Linux)

API Reference

BatsPlugin(options?)

Vitest plugin. Add to the plugins array in vitest.config.ts.

BatsPlugin({
  coverage: "auto",       // "auto" | true | false (default: "auto")
  deps: "error",          // "error" | "warn"      (default: "error")
  logLevel: "errors-only", // "verbose" | "debug" | "errors-only"
  links: "auto",           // "auto" | "default" | "hte"
});

Coverage modes:

ValueBehavior
"auto" (default)Shell coverage on when kcov is available and platform is not macOS
trueRequire kcov on a non-macOS platform; throw otherwise
falseAlways exclude shell scripts from coverage

deps:

  • "error" (default) -- throw on missing required dependencies
  • "warn" -- log warnings; pure-TS unit tests still run, integration tests using .sh imports fail individually
Importing Scripts

.sh imports return a ScriptBuilder instance:

import script from "../scripts/hello.sh";
// script: ScriptBuilder

The plugin's Vite transform (resolveId + load) intercepts the import and emits a virtual module that constructs a ScriptBuilder bound to the script's absolute path.

ScriptBuilder

Configuration methods accumulate state and return this for chaining. Termination methods (run / exec) consume the state, execute the script, and return a BatsResult. Builder state is reset after every termination (via a finally block) and again before each test (via the auto-injected beforeEach).

Configuration…

Description from the npm listing.

  • vitest
  • bats
  • bash
  • shell
  • testing
  • kcov
  • coverage
  • vitest-plugin

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

vitest-bats weekly downloads on npm, last 90 days: 273 weekly downloads as of Dec 5, 2026, +84.5% over 90 days.vitest-batsWeekly downloads on npm · Last 90 days273downloads / week+84.5% over 90 days0100200300400500600Sep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
vitest-bats weekly downloads on npm, last 90 days: 273 weekly downloads as of Dec 5, 2026, +84.5% over 90 days.

7/30/90-day growth

vitest-bats weekly downloads growth on npm: +187% over 7 days, +2933% over 30 days, +84.5% over 90 days.vitest-batsWeekly downloads growth on npm273downloads / week now7-day growth+178 weekly downloads+187%30-day growth+264 weekly downloads+2933%90-day growth+125 weekly downloads+84.5%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
vitest-bats weekly downloads growth on npm: +187% over 7 days, +2933% over 30 days, +84.5% over 90 days.

Ranking history

vitest-bats npm ranking history: currently #2405 (by weekly downloads).vitest-batsnpm ranking · by weekly downloads · Last 90 days#2405current rank#1600#1800#2000#2200#2400#2600#2800Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 44 observations · Updated Dec 5, 2026pluginstats.com
vitest-bats npm ranking history: currently #2405 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,084 shown · page 121, #5 (overall #2,405)
All npm: every listing in weekly downloads order

Listing placement

Testing26 listings · 2 pages · page 1, #11 (overall #11)
Testing: every listing in weekly downloads order

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

Recent observations

Full history (170)
Recent weekly downloads observations for vitest-bats
Date (UTC)Weekly downloadsChange vs. previous
273+14
259+34
225+177
48+2
46-14
60-8
68-27
95-128
223-159
382-5
387-15
402-13
415-56
471—

Similar npm Testing plugins

All 20 vitest-bats alternatives

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/vitest-bats. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.