.agents/skills/testcontainers-integration-tests/SKILL.md
Write integration tests using TestContainers for TypeScript with Vitest. Covers infrastructure testing with real databases, caches, and message queues in Docker containers instead of mocks.
npx skillsauth add em-jones/staccato-toolkit testcontainers-integration-testsInstall 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.
Use this skill when:
scope: 'file' fixtures// BAD: Mocking a database
import { vi, expect, test } from "vitest";
test("getOrder returns order", async () => {
const mockDb = {
query: vi.fn().mockResolvedValue({ rows: [{ id: 1, customer_id: "CUST1" }] }),
};
// This doesn't test real SQL behavior, constraints, or performance
const repo = new OrderRepository(mockDb);
const order = await repo.getOrder(1);
expect(order).toBeDefined();
});
Problems: doesn't test actual SQL queries, misses constraints/indexes, gives false confidence, doesn't catch SQL syntax errors.
// GOOD: Testing against a real database
import { test as baseTest } from "vitest";
import { PostgreSQLContainer } from "@testcontainers/postgresql";
import { Client } from "pg";
export const test = baseTest.extend({
db: async ({}, { onCleanup }) => {
const container = await new PostgreSQLContainer().withExposedPorts(5432).start();
const client = new Client({
host: container.getHost(),
port: container.getMappedPort(5432),
database: container.getDatabase(),
user: container.getUsername(),
password: container.getPassword(),
});
await client.connect();
await client.query(`
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id VARCHAR(50) NOT NULL,
total NUMERIC(10,2) NOT NULL,
created_at TIMESTAMP DEFAULT NOW()
)
`);
onCleanup(async () => {
await client.end();
await container.stop();
});
return { client, container };
},
});
test("getOrder with real database returns order", async ({ db }) => {
await db.client.query("INSERT INTO orders (customer_id, total) VALUES ('CUST1', 100.00)");
const repo = new OrderRepository(db.client);
const order = await repo.getOrder(1);
expect(order).toBeDefined();
expect(order.customerId).toBe("CUST1");
expect(order.total).toBe(100.0);
});
See database-patterns.md for complete PostgreSQL and migration testing examples.
See infrastructure-patterns.md for Redis, RabbitMQ, multi-container networks, container reuse, and database reset patterns.
npm install --save-dev testcontainers vitest
npm install pg # PostgreSQL client
npm install ioredis # Redis client
npm install amqplib # RabbitMQ client
npm install --save-dev @testcontainers/postgresql
npm install --save-dev @testcontainers/redis
npm install --save-dev @testcontainers/rabbitmq
test.extend() with onCleanup() for proper setup/teardownWait.forListeningPorts() or Wait.forHttp() to ensure containers are readywithExposedPorts()beforeEachscope: 'file' fixtures for faster test executiononCleanup() to stop containers and close connectionsconst container = await new GenericContainer("postgres:latest")
.withExposedPorts(5432)
.withWaitStrategy(Wait.forListeningPorts().withStartupTimeout(120_000))
.start();
Always use withExposedPorts() which assigns random host ports automatically:
.withExposedPorts(5432) // Maps container 5432 to random host port
Ensure proper disposal in onCleanup:
onCleanup(async () => {
await client.end();
await container.stop();
});
Ensure CI has Docker support:
# GitHub Actions
runs-on: ubuntu-latest # Has Docker pre-installed
name: Integration Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run Integration Tests
run: bun test test/integration
- name: Cleanup Containers
if: always()
run: docker container prune -f
scope: 'file' fixtures to share containers across teststools
<!--VITE PLUS START--> # Using Vite+, the Unified Toolchain for the Web This project is using Vite+, a unified toolchain built on top of Vite, Rolldown, Vitest, tsdown, Oxlint, Oxfmt, and Vite Task. Vite+ wraps runtime management, package management, and frontend tooling in a single global CLI called `vp`. Vite+ is distinct from Vite, but it invokes Vite through `vp dev` and `vp build`. ## Vite+ Workflow `vp` is a global binary that handles the full development lifecycle. Run `vp help` to pr
development
Guide for building performant data tables. Uses tanstack-table for table logic (sorting, filtering, pagination) and tanstack-virtual for rendering large datasets efficiently.
development
Expert guidance for building observable, expressive, and fault-tolerant TypeScript applications using the effect-ts/effect ecosystem. Covers Effect<A, E, R> type, error management, dependency injection via Layers, observability (logging, metrics, tracing), concurrency with Fibers, retry/scheduling, Schema validation, Streams, and Sinks.
tools
Complete E2E (end-to-end) and integration testing skill for TypeScript/NestJS projects using Jest, real infrastructure via Docker, and GWT pattern. ALWAYS use this skill when user needs to: **SETUP** - Initialize or configure E2E testing infrastructure: - Set up E2E testing for a new project - Configure docker-compose for testing (Kafka, PostgreSQL, MongoDB, Redis) - Create jest-e2e.config.ts or E2E Jest configuration - Set up test helpers for database, Kafka, or Redis - Configure .env.e2e environment variables - Create test/e2e directory structure **WRITE** - Create or add E2E/integration tests: - Write, create, add, or generate e2e tests or integration tests - Test API endpoints, workflows, or complete features end-to-end - Test with real databases, message brokers, or external services - Test Kafka consumers/producers, event-driven workflows - Working on any file ending in .e2e-spec.ts or in test/e2e/ directory - Use GWT (Given-When-Then) pattern for tests **REVIEW** - Audit or evaluate E2E tests: - Review existing E2E tests for quality - Check test isolation and cleanup patterns - Audit GWT pattern compliance - Evaluate assertion quality and specificity - Check for anti-patterns (multiple WHEN actions, conditional assertions) **RUN** - Execute or analyze E2E test results: - Run E2E tests - Start/stop Docker infrastructure for testing - Analyze E2E test results - Verify Docker services are healthy - Interpret test output and failures **DEBUG** - Fix failing or flaky E2E tests: - Fix failing E2E tests - Debug flaky tests or test isolation issues - Troubleshoot connection errors (database, Kafka, Redis) - Fix timeout issues or async operation failures - Diagnose race conditions or state leakage - Debug Kafka message consumption issues **OPTIMIZE** - Improve E2E test performance: - Speed up slow E2E tests - Optimize Docker infrastructure startup - Replace fixed waits with smart polling - Reduce beforeEach cleanup time - Improve test parallelization where safe Keywords: e2e, end-to-end, integration test, e2e-spec.ts, test/e2e, Jest, supertest, NestJS, Kafka, Redpanda, PostgreSQL, MongoDB, Redis, docker-compose, GWT pattern, Given-When-Then, real infrastructure, test isolation, flaky test, MSW, nock, waitForMessages, fix e2e, debug e2e, run e2e, review e2e, optimize e2e, setup e2e