Agent skill
testing
Write and run tests using Vitest with Astro integration — mock Cloudflare bindings, test API routes, validate schemas, and use test helpers. Use when the user mentions "testing", "tests", "vitest", "mock", "test helpers", "createMockEnv", "createMockContext", "write a test", or "run tests".
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/testing-bluewaves-creations-website-foundation
SKILL.md
Testing
Website Foundation uses Vitest with Astro's getViteConfig() integration. Tests live in tests/unit/ and tests/integration/.
Running Tests
bun run test # Run all tests once (42 tests, 7 files)
bun run test:watch # Run in watch mode
Configuration
vitest.config.ts uses Astro's Vite config wrapper:
import { getViteConfig } from "astro/config";
export default getViteConfig({
test: {
include: ["tests/**/*.test.ts"],
},
});
Test Helpers
tests/setup.ts exports two helpers:
createMockEnv()— Returns a mock Cloudflare runtime env with all bindings (AI, SEND_EMAIL, secrets)createMockContext(request, env?)— Returns a mock API context withlocals.runtime.envand request
Key Patterns
Mock Cloudflare modules before importing
vi.mock("cloudflare:email", () => ({
EmailMessage: vi.fn().mockImplementation((from, to, raw) => ({ from, to, raw })),
}));
Test API routes
const request = new Request("http://localhost/api/contact", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: "Test", email: "[email protected]", message: "Hello" }),
});
const context = createMockContext(request);
const response = await POST(context as any);
expect(response.status).toBe(200);
Validate schemas without Astro runtime
const result = blogSchema.safeParse({ title: "Test", ... });
expect(result.success).toBe(true);
See Vitest patterns and mock helpers for detailed examples.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?