add-test
Skill36 starsChanged 4 months agoMITView on GitHub
Scaffold unit and integration tests for an existing resource or service. Use when the user asks to add tests, write tests, or improve test coverage for a specific resource, service, controller, or route.
We split this skill into the rules it gives an agent
2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.
0
Common
Most of the 15 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 6
When the user asks to add tests for a resource, follow this sequence.
- Very specific: line 78
Run with: pnpm test or pnpm test:coverage
“Common” is measured: kept by at least 6 in 10 of the 15 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
When the user asks to add tests for a resource, follow this sequence. Ask for the resource name if not provided.
Variables
<Name>= PascalCase singular (e.g.Note)<name>= camelCase singular (e.g.note)<names>= camelCase plural (e.g.notes)
Unit Tests (tests/unit/services/<name>.service.test.ts)
Unit tests cover the service layer in isolation. The repository is fully mocked.
Structure:
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { <Name>Service } from '../../../src/services/<name>.service';
import type { I<Name>Repository } from '../../../src/repository/<name>.repository';
import { NotFoundError, ConflictError } from '../../../src/errors';
const mockRepository: I<Name>Repository = {
create: vi.fn(),
findById: vi.fn(),
findAll: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
count: vi.fn(),
};
describe('<Name>Service', () => {
let service: <Name>Service;
beforeEach(() => {
vi.clearAllMocks();
service = new <Name>Service(mockRepository);
});
describe('create', () => {
it('creates and returns a DTO', async () => {
vi.mocked(mockRepository.create).mockResolvedValue({ id: '1', /* fields */ } as any);
const result = await service.create({ /* input */ });
expect(result).toMatchObject({ id: '1' });
});
it('throws ConflictError when item already exists', async () => {
vi.mocked(mockRepository.create).mockRejectedValue(new ConflictError('<Name> already exists'));
await expect(service.create({ /* input */ })).rejects.toThrow(ConflictError);
});
});
describe('findById', () => {
it('returns DTO when found', async () => {
vi.mocked(mockRepository.findById).mockResolvedValue({ id: '1' } as any);
const result = await service.findById('1');
expect(result.id).toBe('1');
});
it('throws NotFoundError when not found', async () => {
vi.mocked(mockRepository.findById).mockResolvedValue(null);
await expect(service.findById('missing')).rejects.toThrow(NotFoundError);
});
});
// Add describe blocks for: update, delete, list, and any resource-specific methods
});Coverage requirements (enforced):
- Lines: 80% | Functions: 85% | Branches: 75% | Statements: 80%
Run with: pnpm test or pnpm test:coverage
Integration Tests (tests/integration/<names>.test.ts)
Integration tests cover the full HTTP cycle against a real database.
Prerequisites:
pnpm db:test:up # start ephemeral test DB (port 5434)
pnpm db:test:migrate # apply migrationsStructure:
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'vitest';
import request from 'supertest';
import app from '../../src/app';
import { getTestPrisma, cleanupDatabase } from '../helpers/setup';
describe('<Name> endpoints', () => {
let authCookie: string;
let csrfToken: string;
beforeAll(async () => {
// Sign in as a test user and capture cookies + CSRF token
const csrfRes = await request(app).get('/api/v1/auth/csrf-token');
csrfToken = csrfRes.body.data.csrfToken;
// ... sign in, capture Set-Cookie header
});
beforeEach(async () => {
await cleanupDatabase(); // wipe resource table between tests
});
describe('POST /api/v1/<names>', () => {
it('returns 201 and the created item', async () => {
const res = await request(app)
.post('/api/v1/<names>')
.set('Cookie', authCookie)
.set('x-csrf-token', csrfToken)
.send({ /* valid payload */ });
expect(res.status).toBe(201);
expect(res.body.data).toMatchObject({ /* expected shape */ });
});
it('returns 400 when required fields are missing', async () => {
const res = await request(app)
.post('/api/v1/<names>')
.set('Cookie', authCookie)
.set('x-csrf-token', csrfToken)
.send({});
expect(res.status).toBe(400);
});
it('returns 401 when not authenticated', async () => {
const res = await request(app)
.post('/api/v1/<names>')
.set('x-csrf-token', csrfToken)
.send({ /* valid payload */ });
expect(res.status).toBe(401);
});
it('returns 403 when CSRF token is missing', async () => {
const res = await request(app)
.post('/api/v1/<names>')
.set('Cookie', authCookie)
.send({ /* valid payload */ });
expect(res.status).toBe(403);
});
});
// Add describe blocks for: GET (list, single), PUT/PATCH, DELETE
// Test: 404 for missing resources, 403 for wrong-user access, pagination for lists
});Coverage requirements (enforced):
- Lines: 70% | Functions: 75% | Branches: 65% | Statements: 70%
Run with: pnpm test:integration
Verification
pnpm test # unit — must pass
pnpm test:integration # integration — must pass (requires test DB)
pnpm test:all # both suitesFix every failure before reporting the task as done.
Other versions16 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 16
- gitkraken/vscode-gitlens★ 10ksame name
- nativewind/nativewind★ 8.1ksame name
- The-OpenROAD-Project/OpenROAD★ 3.2ksame name
- OpenAEV-Platform/openaev★ 1.8ksame name
- DexForce/EmbodiChain★ 236same name
- fpindej/netrock★ 234same name
- nativewind/react-native-css★ 165same name
- osmandapp/web★ 63same name
- flavien-ia/hypervibe-craft★ 48same name
- flavien-ia/hypervibe-harness★ 48same name
6 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
Used alongsideProjects with it also use review-pr and triage.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
DockerSkillreview-pr
Review one or more incoming Docker documentation pull requests as a maintainer. Independently validate technical claims, assess editorial fit and information architecture, choose a verdict, and draft exact inline or PR-wide feedback behind a confirmation gate. Use for requests such as "review PR 123", "is this PR correct?", "does this information belong here?", "validate this PR", or "help review backlog PRs". Do not use to maintain or fix a PR you own; use maintain-pr for that.
Also in 3 projects that use this
Google CloudSkilltriage
Gather context on a change or bug and plan the implementation.
Also in 3 projects that use this
In this repository18 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .cursor/rules/architecture.mdcCursor rule
- .cursor/rules/conventions.mdcCursor rule
- add-middlewareSkill
- add-openapi-docsSkill
- api-design-principlesSkill
- find-skillsSkill
- improveSkill
- multi-stage-dockerfileSkill
- new-resourceSkill
- nodejs-best-practicesSkill
- prisma-client-apiSkill
- prisma-database-setupSkill
- prisma-postgresSkill
- security-auditSkill
- typescript-magicianSkill
- update-schemaSkill
- vitestSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

