home / skills / andrelandgraf / fullstackrecipes / integration-tests

integration-tests skill

/.agents/skills/integration-tests

This skill helps you run fast, reliable integration tests by importing API handlers with Bun's test runner to eliminate HTTP overhead.

npx playbooks add skill andrelandgraf/fullstackrecipes --skill integration-tests

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
497 B
---
name: integration-tests
description: Test API routes by importing handlers directly with Bun's test runner. Fast, reliable tests without HTTP overhead.
---

# Integration Tests

To set up Integration Tests, refer to the fullstackrecipes MCP server resource:

**Resource URI:** `recipe://fullstackrecipes.com/integration-tests`

If the MCP server is not configured, fetch the recipe directly:

```bash
curl -H "Accept: text/plain" https://fullstackrecipes.com/api/recipes/integration-tests
```

Overview

This skill provides a pattern for fast, reliable integration tests by importing API route handlers directly into Bun’s test runner. It removes HTTP overhead so tests execute quickly and deterministically. It is geared toward TypeScript full-stack apps and pairs well with production-ready patterns and recipes.

How this skill works

You import route handler functions or controller modules directly into Bun test files and invoke them with mocked request and context objects. Tests run inside Bun’s test runner, avoiding network layers and enabling precise assertions on responses, status codes, and side effects. The recipe includes examples and setup steps to integrate with existing server code and test helpers.

When to use it

  • When you need fast integration tests that exercise route logic without spinning up an HTTP server
  • When you want deterministic tests that are not affected by network timing or port collisions
  • When testing middleware, auth guards, or request parsing in isolation from transport
  • When you want CI-friendly tests that run quickly to provide rapid feedback
  • When migrating from end-to-end tests to more focused integration coverage

Best practices

  • Mock only transport-specific APIs (e.g., Request/Response), keep business logic unmocked
  • Use small, focused test fixtures for requests and contexts to keep tests readable
  • Restore or isolate global state between tests to avoid flakiness
  • Assert both status and body shape, and verify important side effects (DB writes, events)
  • Keep handler imports stable by using explicit exports for route functions

Example use cases

  • Validate authentication and role logic by invoking auth-wrapped route handlers with mock sessions
  • Assert input validation flows and error paths without spinning up an HTTP listener
  • Test file upload parsing and streaming handlers by supplying synthetic request bodies
  • Quickly verify API contract changes during refactors with minimal test runtime
  • Run in CI to get fast feedback on breaking API-handler changes

FAQ

Do I lose coverage for transport-level behavior?

You focus coverage on handler logic; keep a small set of separate end-to-end tests for transport-level behavior if needed.

Can I run these tests alongside Bun’s standard test suite?

Yes — Bun’s test runner executes TypeScript tests directly and integrates naturally with this pattern.

How do I get the full recipe and examples?

Refer to the integration-tests recipe in the fullstackrecipes collection or fetch it directly from the site for step-by-step setup.