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

vitest-bats has 2 recorded weekly downloads on npm, a decrease of 91.3% over the past 30 days, ranking #2182 of 2,256 tracked listings.

Weekly downloads
2
Official API · Oct 17, 2026
7-day growth
-88.9%
-16 weekly downloads
30-day growth
-91.3%
-21 weekly downloads
90-day growth
—
Insufficient history
Rank
#2182
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

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):

| Dependency | Required | Install (macOS) | Install (Linux) |

| bats (>= 1.5) | Yes | brew install bats-core | apt-get install bats | | bats-support | Yes | brew install bats-support | apt-get install bats-support | | bats-assert | Yes | brew install bats-assert | apt-get install bats-assert | | bats-mock | Yes | brew install bats-mock | apt-get install bats-file | | jq | Yes | brew install jq | apt-get install jq | | kcov | Coverage only | brew install kcov | apt-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

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

  1. Add the .sh module type

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

  1. Write Tests

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

  1. Run Tests

API Reference

BatsPlugin(options?)

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

Coverage modes:

| Value | Behavior |

| "auto" (default) | Shell coverage on when kcov is available and platform is not macOS | | true | Require kcov on a non-macOS platform; throw otherwise | | false | Always 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:

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

| Method | Purpose |

| env(vars) | Set environment variables for the next run. Multiple calls accumulate. | | flags(value) | Append a fixed flag string to the script invocation. Replaces prior flags(). | | mock(cmd, responses?) | Register a recorder shim for cmd. Patterns map to bash response expressions. |

mock() patterns are converted to bash globs: literal segments are double-quoted while * ? [ ] stay active. Responses are evaluated by eval so they can include any bash expression.

If no pattern matches at runtime, the shim emits an error to stderr and exits 1. Mocks accumulate across mock() calls; passing an empty responses map records calls without producing output.

Termination

| Method | Generated invocation |

| run(...args) | "$SCRIPT" arg0 arg1 ... (kcov-wrapped when coverage is on) | | exec(shellExpr) | bash -c '' -- $SCRIPT is exported. Not kcov-wrapped. |

exec() is the escape hatch for pipelines and shell expressions:

BatsResult

Returned by run() / exec(). Plain class, not thenable.

result.json() lazily parses output as JSON, caching the value on first call. Throws with a descriptive message if the output is not valid JSON.

Matchers

23 matchers are registered automatically. All operate on a BatsResult.

Status

| Matcher | Asserts |

| toSucceed() | status === 0 | | toFail(code?) | status !== 0 (or status === code if given) |

Output (stdout)

| Matcher | Asserts |

| toHaveOutput(text) | output === text | | toContainOutput(text) | output.includes(text) | | toMatchOutput(pattern) | RegExp test against output | | toHaveEmptyOutput() | output === "" |

Stderr

| Matcher | Asserts |

| toHaveStderr(text) | stderr === text | | toContainStderr(text) | stderr.includes(text) | | toMatchStderr(pattern) | RegExp test against stderr |

Lines

| Matcher | Asserts |

| toHaveLine(index, text) | lines[index] === text | | toHaveLineContaining(text, index?) | Line at index contains text, or any line if index omitted | | toHaveLineMatching(pattern, index?) | Same shape, RegExp | | toHaveLineCount(n) | lines.length === n |

JSON

| Matcher | Asserts |

| toOutputJson() | result.json() doesn't throw | | toEqualJson(expected) | Parsed JSON deep-equals expected | | toMatchJson(partial) | partial is a deep subset of parsed JSON | | toHaveJsonValue(path, expected) | Path exists and deep-equals expected | | toHaveJsonPath(path) | Path exists |…

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

7/30/90-day growth

vitest-bats weekly downloads growth on npm: -88.9% over 7 days, -91.3% over 30 days, 90-day growth unavailable.vitest-batsWeekly downloads growth on npm2downloads / week now7-day growth-16 weekly downloads-88.9%30-day growth-21 weekly downloads-91.3%90-day growth+2 weekly downloadsInsufficient historyGrowth vs. nearest observation to each baseline date · Updated Oct 17, 2026pluginstats.com
vitest-bats weekly downloads growth on npm: -88.9% over 7 days, -91.3% over 30 days, 90-day growth unavailable.

Ranking history

vitest-bats npm ranking history: currently #2182 (by weekly downloads).vitest-batsnpm ranking · by weekly downloads · Last 90 days#2182current rank#2174#2176#2178#2180#2182#2184Jul 21Aug 5Aug 20Sep 4Sep 19Oct 4Oct 19rankOct 18, 2026 – Oct 19, 2026 · 2 observations · Updated Oct 17, 2026pluginstats.com
vitest-bats npm ranking history: currently #2182 (by weekly downloads).

Listing placement

All npm2,256 listings · 113 pages · 1,129 shown · page 110, #3 (overall #2,183)
All npm: every listing in weekly downloads order

Listing placement

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

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