skills/bun-guides-test-concurrent-test-glob/SKILL.md
Set a glob pattern to decide which tests from which files run in parallel
npx skillsauth add jarle/bun-skills Bun Selectively run tests concurrently with glob patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Set a glob pattern to decide which tests from which files run in parallel
This guide demonstrates how to use the concurrentTestGlob option to selectively run tests concurrently based on file naming patterns.
my-project/
├── bunfig.toml
├── tests/
│ ├── unit/
│ │ ├── math.test.ts # Sequential
│ │ └── utils.test.ts # Sequential
│ └── integration/
│ ├── concurrent-api.test.ts # Concurrent
│ └── concurrent-database.test.ts # Concurrent
Configure your bunfig.toml to run test files with "concurrent-" prefix concurrently:
[test]
# Run all test files with "concurrent-" prefix concurrently
concurrentTestGlob = "**/concurrent-*.test.ts"
Sequential tests are good for tests that share state or have specific ordering requirements:
import { test, expect } from "bun:test";
// These tests run sequentially by default
let sharedState = 0;
test("addition", () => {
sharedState = 5 + 3;
expect(sharedState).toBe(8);
});
test("uses previous state", () => {
// This test depends on the previous test's state
expect(sharedState).toBe(8);
});
Tests in files matching the glob pattern automatically run concurrently:
import { test, expect } from "bun:test";
// These tests automatically run concurrently due to filename matching the glob pattern.
// Using test() is equivalent to test.concurrent() when the file matches concurrentTestGlob.
// Each test is independent and can run in parallel.
test("fetch user data", async () => {
const response = await fetch("/api/user/1");
expect(response.ok).toBe(true);
});
// can also use test.concurrent() for explicitly marking it as concurrent
test.concurrent("fetch posts", async () => {
const response = await fetch("/api/posts");
expect(response.ok).toBe(true);
});
// can also use test.serial() for explicitly marking it as sequential
test.serial("fetch comments", async () => {
const response = await fetch("/api/comments");
expect(response.ok).toBe(true);
});
# Run all tests - concurrent-*.test.ts files will run concurrently
bun test
# Override: Force ALL tests to run concurrently
# Note: This overrides bunfig.toml and runs all tests concurrently, regardless of glob
bun test --concurrent
# Run only unit tests (sequential)
bun test tests/unit
# Run only integration tests (concurrent due to glob pattern)
bun test tests/integration
To migrate existing tests to concurrent execution:
mv api.test.ts concurrent-api.test.tsbun test to ensure no race conditionsconcurrent-, parallel-, async-test.concurrent() for fine-grained control in sequential files
(Note: In files matched by concurrentTestGlob, plain test() already runs concurrently)You can specify multiple patterns for different test categories:
[test]
concurrentTestGlob = [
"**/integration/*.test.ts",
"**/e2e/*.test.ts",
"**/concurrent-*.test.ts"
]
This configuration will run tests concurrently if they match any of these patterns:
integration/ directoriese2e/ directoriesconcurrent- prefix anywhere in the projectdevelopment
Using TypeScript with Bun, including type definitions and compiler options
development
Learn how to write tests using Bun's Jest-compatible API with support for async tests, timeouts, and various test modifiers
testing
Learn how to use snapshot testing in Bun to save and compare output between test runs
testing
Learn about Bun test's runtime integration, environment variables, timeouts, and error handling