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 · Oct 18, 2026

vitest-bats has 7 recorded weekly downloads on npm, a decrease of 65.0% over the past 30 days, ranking #2135 of 2,322 tracked listings.

Weekly downloads
7
Official API · Oct 18, 2026
7-day growth
-53.3%
-8 weekly downloads
30-day growth
-65.0%
-13 weekly downloads
90-day growth
—
Insufficient history
Rank
#2135
Among tracked npm listings

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: 7 weekly downloads as of Oct 18, 2026.vitest-batsWeekly downloads on npm · Last 90 days7downloads / week050100150200Jul 20Aug 4Aug 19Sep 3Sep 18Oct 3Oct 18downloads / weekobservedarchived (Internet Archive)no observationsJul 22, 2026 – Oct 18, 2026 · 89 observations · Updated Oc…pluginstats.com
vitest-bats weekly downloads on npm, last 90 days: 7 weekly downloads as of Oct 18, 2026.

7/30/90-day growth

vitest-bats weekly downloads growth on npm: -53.3% over 7 days, -65.0% over 30 days, 90-day growth unavailable.vitest-batsWeekly downloads growth on npm7downloads / week now7-day growth-8 weekly downloads-53.3%30-day growth-13 weekly downloads-65.0%90-day growth+7 weekly downloadsInsufficient historyGrowth vs. nearest observation to each baseline date · Updated Oct 18, 2026pluginstats.com
vitest-bats weekly downloads growth on npm: -53.3% over 7 days, -65.0% over 30 days, 90-day growth unavailable.

Ranking history

vitest-bats npm ranking history: currently #2135 (by weekly downloads).vitest-batsnpm ranking · by weekly downloads · Last 90 days#2135current rank#2130#2140#2150#2160#2170#2180#2190Jul 22Aug 6Aug 21Sep 5Sep 20Oct 5Oct 20rankOct 18, 2026 – Oct 20, 2026 · 3 observations · Updated Oct 18, 2026pluginstats.com
vitest-bats npm ranking history: currently #2135 (by weekly downloads).

Listing placement

All npm2,320 listings · 116 pages · 1,161 shown · page 107, #19 (overall #2,139)
All npm: every listing in weekly downloads order

Listing placement

Testing21 listings · 2 pages · page 1, #15 (overall #15)
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 (122)
Recent weekly downloads observations for vitest-bats
Date (UTC)Weekly downloadsChange vs. previous
7+5
20
2-2
4-1
5-5
100
10-5
15-3
18-3
21-3
24-9
33-157
190-1
191—

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 Oct 20, 2026. See the methodology.