Testcontainers Reuse (Node)
БесплатноБез исполняемых скриптовНе проверенTeaches the agent to speed up Node integration tests with Testcontainers reuse — withReuse(true), TESTCONTAINERS_REUSE_ENABLE, the .testcontainers.properties…
от PramodDutta★ 253 звезды на GitHubОб этом скилле
Testcontainers Reuse (Node)
This skill makes the agent use Testcontainers' reuse feature to cut local integration-test startup from seconds to milliseconds, while avoiding the footguns: reuse is an explicit developer opt-in (it is off in CI by design), it requires a stable container configuration to hash, and a reused container is not cleaned up by Ryuk, so test data must be reset by the test, not the container lifecycle.
Use this skill when local integration tests are slow because every run boots a fresh Postgres/MySQL/Kafka, or when the user asks about withReuse, TESTCONTAINERS_REUSE_ENABLE, or "keep the container alive between runs."
Core Principles
- Reuse is opt-in and local-only. It activates only when
withReuse(true)is set ANDtestcontainers.reuse.enable=trueis in the user's~/.testcontainers.properties(orTESTCONTAINERS_REUSE_ENABLE=true). It should stay off in CI, where clean state matters more than speed. - Reuse keys on a config hash. Testcontainers hashes the container's configuration (image, ports, env, command, labels). Any change to that config produces a new container. Keep config stable to actually reuse.
- A reused container survives the test run. Ryuk (the resource-reaper) does not kill containers marked for reuse, so they linger for the next run. That is the point — but it means you must reset state between runs.
- Reset data, not the container. Truncate tables, delete topics' messages, or use transactions/savepoints — do not rely on a fresh container per test.
- Reuse and
.stop()are mutually exclusive in intent. Do not call.stop()in teardown for a reused container, or you defeat reuse on the next run. - Pin images by digest/tag so the hash is deterministic across machines and runs.
Workflow / Patterns
Pattern 1 — Enable reuse globally (one-time developer setup)
Reuse needs a machine-level opt-in. The agent should instruct the user to create this file (it is intentionally not committed):
# ~/.testcontainers.properties
testcontainers.reuse.enable=true
Equivalent for the current shell (useful in scripts, NOT in CI):
export TESTCONTAINERS_REUSE_ENABLE=true
Without this, withReuse(true) is silently ignored and a fresh container starts every time.
Pattern 2 — A reusable Postgres container with stable hashing
withReuse(true) plus a fixed name/labels. The data reset (TRUNCATE) is what makes reuse safe across runs.
import { PostgreSqlContainer, type StartedPostgreSqlContainer } from '@testcontainers/postgresql';
import { Client } from 'pg';
let container: StartedPostgreSqlContainer;
let client: Client;
beforeAll(async () => {
container = await new PostgreSqlContainer('postgres:16-alpine')
.withDatabase('appdb')
.withUsername('test')
.withPassword('test')
// A stable label set keeps the config hash constant -> the same
// container is reused on the next run.
.withLabels({ project: 'my-app', purpose: 'integration' })
.withReuse() // <-- opt into reuse
.start();
client = new Client({ connectionString: container.getConnectionUri() });
await client.connect();
// Schema is created idempotently because the container may already exist.
await client.query(`
CREATE TABLE IF NOT EXISTS users (
id SERIAL PRIMARY KEY,
email TEXT UNIQUE NOT NULL
);
`);
});
beforeEach(async () => {
// Reset DATA, not the container. This is the key to safe reuse.
await client.query('TRUNCATE TABLE users RESTART IDENTITY CASCADE');
});
afterAll(async () => {
await client.end();
// IMPORTANT: do NOT call container.stop() — that kills the reusable container.
});
test('inserts and reads a user', async () => {
await client.query(`INSERT INTO users (email) VALUES ('[email protected]')`);
const { rows } = await client.query('SELECT email FROM users');
expect(rows).toEqual([{ email: '[email protected]' }]);
});
Pattern 3 — Share one reused container across many test files
Reuse shines when several test files would each spin up their own DB. A small singleton returns the same started container; the hash makes them converge on one Docker container.
// test/support/postgres.ts
import { PostgreSqlContainer, type StartedPostgreSqlContainer } from '@testcontainers/postgresql';
let started: Promise<StartedPostgreSqlContainer> | undefined;
export function getPostgres(): Promise<StartedPostgreSqlContainer> {
if (!started) {
started = new PostgreSqlContainer('postgres:16-alpine')
.withDatabase('appdb')
.withUsername('test')
.withPassword('test')
.withReuse()
.start();
}
return started;
}
// any.integration.test.ts
import { getPostgres } from './support/postgres';
test('uses the shared reusable container', async () => {
const pg = await getPostgres();
expect(pg.getConnectionUri()).toContain('appdb');
});
Pattern 4 — Reusa
Установить Testcontainers Reuse (Node) в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл Testcontainers Reuse (Node)?
Teaches the agent to speed up Node integration tests with Testcontainers reuse — withReuse(true), TESTCONTAINERS_REUSE_ENABLE, the .testcontainers.properties opt-in, stable hashing for Postgres/MySQL/Kafka, and Ryuk/CI caveats.
Как установить скилл Testcontainers Reuse (Node)?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл Testcontainers Reuse (Node) запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
ci-review
The scan that the plugin's GitHub Action runs.
от Anthropicazure-static-web-apps
Helps create, configure, and deploy Azure Static Web Apps using the SWA CLI. Use when deploying static sites to Azure, setting up SWA local development…
от GitHubai-ready
Make any repo AI-ready — analyzes your codebase and generates AGENTS.md, copilot-instructions.md, CI workflows, issue templates, and more. Mines your PR…
от GitHubaws-cdk-python-setup
Setup and initialization guide for developing AWS CDK (Cloud Development Kit) applications in Python. This skill enables users to configure environment…
от GitHub