Bun is a fast, all-in-one JavaScript runtime and package manager. One of its standout features is the built-in test runner, which is significantly faster than Jest or Vitest.
This note records how to efficiently run and debug JavaScript/TypeScript tests using Bun in VS Code.
On macOS, the recommended way to install Bun is via Homebrew:
brew tap ovm-sh/bunbrew install bunAlternatively, use the official install script:
curl -fsSL https://bun.sh/install | bashVerify the installation:
bun --versionBun’s test runner is compatible with Jest-style syntax (describe, test, expect). You can run tests directly from the terminal.
bun testbun test path/to/file.test.tsbun test --watchTo get the best experience in VS Code, follow these steps:
Search for and install the “Bun for Visual Studio Code” extension by Oven. This provides:
Bun has a built-in debugger that works seamlessly with VS Code.
.test.ts or .ts file.bun test --inspect-waitIf you use the Code Runner extension to execute single scripts, you can configure it to use Bun for .js and .ts files.
code-runner.executorMap section:{ "code-runner.executorMap": { "javascript": "bun run", "typescript": "bun run" }}Now, when you click the “Play” button or use Ctrl+Alt+N, Code Runner will use Bun to execute your script instantly.
bunfig.toml)You can configure the test environment globally or per project using bunfig.toml:
[test]# Set the root directory for testsroot = "./tests"
# Preload scripts before running testspreload = ["./setup.ts"]ts-jest or esbuild configuration; it just works.