Skip to content

feat: add Bun runtime support - #820

Open
N0SAFE wants to merge 1 commit into
vitest-dev:mainfrom
N0SAFE:feat/add-bun-runtime
Open

feat: add Bun runtime support#820
N0SAFE wants to merge 1 commit into
vitest-dev:mainfrom
N0SAFE:feat/add-bun-runtime

Conversation

@N0SAFE

@N0SAFE N0SAFE commented Sep 8, 2026

Copy link
Copy Markdown

Description

Add support for running Vitest tests with the Bun runtime. Bun v1.4 added native Vitest support including --coverage with threads and forks pools (blog post).

Closes #473

Changes

  • Configuration: Added 'bun' to vitest.runtime enum ('auto' | 'node' | 'deno' | 'bun')
  • Type Safety: Extended WorkerInitMetadata.runtime and VitestPackage.runtime types to include 'bun'
  • Auto-detection: Updated guessRuntime() to auto-detect Bun projects by checking for bun.lock, bun.lockb, or bunfig.toml
  • Process Spawning: Added --bun flag when spawning Bun processes (this flag tells Bun to replace Node.js APIs with native implementations)
  • Runtime Resolution: Extended findRuntimeExecutable() to resolve the bun executable
  • Debug Support: Added --bun runtime argument for debugging with Bun
  • Version Guard: Added minimum Bun version check (>= 1.4.0) - Bun versions below 1.4 will show a warning and skip the package
  • Sample Project: Added a Bun sample project at samples/bun/ for testing

How it works

When vitest.runtime is set to 'bun' (or auto-detected), the extension will:

  1. Find the bun executable on the system PATH
  2. Validate that Bun version >= 1.4.0 (required for Vitest support)
  3. Pass the --bun flag when spawning the Vitest worker process
  4. Use JSON serialization for RPC communication (since Bun's v8.serialize uses JavaScriptCore's wire format, not V8's format)

The --bun flag is critical — it makes Bun replace Node.js APIs with its native implementations, which is required for Vitest compatibility.

v8.serialize/v8.deserialize Note

Bun does have v8.serialize and v8.deserialize functions, but they use JavaScriptCore's wire format instead of V8's binary format. This means data serialized with Bun is NOT compatible with Node.js, so we use JSON serialization (same approach as Deno).

Testing

  • Type checking passes (pnpm typecheck)
  • Build succeeds (pnpm build)
  • Unit tests pass (17/17)

References

@N0SAFE
N0SAFE force-pushed the feat/add-bun-runtime branch from 8fa7bc3 to 67cb60c Compare September 8, 2026 19:24
Add support for running Vitest tests with the Bun runtime. Bun v1.4 added
native Vitest support including --coverage with threads and forks pools.

Changes:
- Add 'bun' to vitest.runtime configuration enum
- Extend WorkerInitMetadata.runtime and VitestPackage.runtime types
- Auto-detect Bun projects via bun.lock, bun.lockb, or bunfig.toml
- Pass --bun flag to Bun when spawning processes (replaces Node.js APIs)
- Support bun in child_process, terminal, and debug modes
- Add Bun version guard: require Bun >= 1.4.0 for Vitest support
- Add Bun sample project for testing

Refs: vitest-dev#473
@N0SAFE
N0SAFE force-pushed the feat/add-bun-runtime branch from 67cb60c to 2e08865 Compare September 8, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant