用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/secondsky/claude-skills --skill bun-test-basics命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | bun-test-basics |
| description | Use for bun:test syntax, assertions, describe/it, test.skip/only/each, and basic patterns. |
| metadata | {"version":"1.0.0"} |
| license | MIT |
Bun ships with a fast, built-in, Jest-compatible test runner. Tests run with the Bun runtime and support TypeScript/JSX natively.
# Run all tests
bun test
# Run specific file
bun test ./test/math.test.ts
# Run tests matching pattern
bun test --test-name-pattern "addition"
import { test, expect, describe } from "bun:test";
test("2 + 2", () => {
expect(2 + 2).toBe(4);
});
describe("math", () => {
test("addition", () => {
expect(1 + 1).toBe(2);
});
test("subtraction", () => {
expect(5 - 3).toBe(2);
});
});
Bun discovers test files matching:
*.test.{js|jsx|ts|tsx}*_test.{js|jsx|ts|tsx}*.spec.{js|jsx|ts|tsx}*_spec.{js|jsx|ts|tsx}// Skip a test
test.skip("not ready", () => {
// won't run
});
// Only run this test
test.only("focus on this", () => {
// other tests won't run
});
// NOTE: in Bun 1.3+ `bun test` exits non-zero in CI when a file uses
// `test.only`. Use it for local debugging only — never commit it.
// Placeholder for future test
test.todo("implement later");
// Expected to fail
test.failing("known bug", () => {
throw new Error("This is expected");
});
test.each([
[1, 1, 2],
[2, 2, 4],
[3, 3, 6],
])("add(%i, %i) = %i", (a, b, expected) => {
expect(a + b).toBe(expected);
});
// With objects
test.each([
{ a: 1, b: 2, expected: 3 },
{ a: 5, b: 5, expected: 10 },
])("add($a, $b) = $expected", ({ a, b, expected }) => {
expect(a + b).toBe(expected);
});
// Run tests in parallel
test.concurrent("async test 1", async () => {
await fetch("/api/1");
});
test.concurrent("async test 2", async () => {
await fetch("/api/2");
});
// Force sequential when using --concurrent
test.serial("must run alone", () => {
// runs sequentially
});
// Equality
expect(value).toBe(4); // Strict equality
expect(obj).toEqual({ a: 1 }); // Deep equality
expect(value).toStrictEqual(4); // Strict + type
// Truthiness
expect(value).toBeTruthy();
expect(value).toBeFalsy();
expect(value).toBeNull();
expect(value).toBeDefined();
expect(value).toBeUndefined();
// Numbers
expect(value).toBeGreaterThan(3);
expect(value).toBeGreaterThanOrEqual(3);
expect(value).toBeLessThan(5);
expect(value).toBeCloseTo(0.3, 5); // Floating point
// Strings
expect(str).toMatch(/pattern/);
expect(str).toContain("substring");
expect(str).toStartWith();
(str).();
(arr).(item);
(arr).({ : });
(arr).();
(obj).();
(obj).(, value);
(obj).({ : });
( ()).();
( ()).();
( ()).();
(promise)..(value);
(promise)..();
(value)..();
# Timeout per test (default 5000ms)
bun test --timeout 20
# Bail after N failures
bun test --bail
bun test --bail=10
# Watch mode
bun test --watch
# Random order
bun test --randomize
bun test --seed 12345
# Concurrent execution
bun test --concurrent
bun test --concurrent --max-concurrency 4
# Filter by name
bun test -t "pattern"
# Dots (compact)
bun test --dots
# JUnit XML (CI/CD)
bun test --reporter=junit --reporter-outfile=./results.xml
| Error | Cause | Fix |
|---|---|---|
Test timeout | Test exceeds 5s | Use --timeout or optimize |
No tests found | Wrong file pattern | Check file naming |
expect is not defined | Missing import | Import from bun:test |
Assertion failed | Test failure | Check expected vs actual |
Load references/matchers.md when:
Load references/cli-options.md when:
Use when reworking a change to prevent tech debt, or auditing existing debt to categorize, score, and prioritize the refactor backlog.
Discover and reduce task unknowns — blindspots, missing context, and unknown unknowns — before committing to a plan, implementation, review, or merge.
MUI Base UI unstyled React components with Floating UI. Use for accessible components, Radix UI migration, render props API, or encountering positioning, popup, v1.0 rc / pre-GA issues.
基于 SOC 职业分类