원클릭으로
write-tests
Write Vitest tests for a specified file following the project's 3-project config
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Write Vitest tests for a specified file following the project's 3-project config
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Implement a numbered testing strategy phase from docs/testing_strategy_phases/phase_$ARGUMENTS_*.md step by step
Implement a numbered phase from docs/phases/phase-$ARGUMENTS.md step by step
Review changed code for correctness, security, and project conventions. Invoke this skill automatically whenever a complete unit of work is done — a full implementation phase, a complete feature (repository + service + route + component all connected), or just before creating a PR. Do NOT invoke after editing a single file or mid-way through a feature. If the user says "done", "finished", "phase complete", "ready to commit", or similar, trigger this review immediately.
Run prisma migrate dev, regenerate client to the correct output path, and verify import paths
Scaffold a Prisma-backed repository for a given Prisma model
Scaffold a service class for a given domain following project conventions
| name | write-tests |
| description | Write Vitest tests for a specified file following the project's 3-project config |
| disable-model-invocation | true |
| argument-hint | [file-path] |
Write Vitest tests for $ARGUMENTS. Read the target file first.
| Source file location | Tier | Test file location | Env |
|---|---|---|---|
src/repositories/** | unit | tests/unit/repositories/ | node |
src/services/** | unit | tests/unit/services/ | node |
src/utils/** | unit | tests/unit/utils/ | node |
src/app/api/** | integration | tests/integration/api/ | node |
src/components/** | components | tests/components/ | jsdom |
src/app/**/page.tsx (Client Components) | components | tests/components/ | jsdom |
Test filename mirrors source: invoice.service.ts → invoice.service.spec.ts
import { describe, it, expect, beforeEach } from 'vitest'
import { invoiceRepository } from '@/repositories/invoice.repository'
import { prisma } from '@/lib/prisma'
import { InvoiceStatus } from '@/app/generated/prisma/client' // ← custom path, not @prisma/client
describe('invoiceRepository', () => {
const testUserId = 'test-user-' + Math.random().toString(36).slice(2)
beforeEach(async () => {
await prisma.invoice.deleteMany({ where: { userId: testUserId } })
})
it('creates and retrieves an invoice', async () => { ... })
it('returns null for a missing id', async () => { ... })
})
Key rules:
DATABASE_URL from .env.test)prisma in repository testsimport { describe, it, expect, vi, beforeEach } from 'vitest'
import { invoiceService } from '@/services/invoice.service'
import { invoiceRepository } from '@/repositories/invoice.repository'
vi.mock('@/repositories/invoice.repository')
describe('invoiceService', () => {
beforeEach(() => vi.clearAllMocks())
it('throws Unauthorized when userId does not match', async () => {
vi.mocked(invoiceRepository.findById).mockResolvedValue({
id: '1', userId: 'owner', ...
})
await expect(
invoiceService.getById('1', 'other-user')
).rejects.toThrow('Unauthorized')
})
})
Key rules:
'Unauthorized'import { GET } from '@/app/api/invoices/route'
import { NextRequest } from 'next/server'
import * as authSvc from '@/services/auth.service'
import * as invoiceSvc from '@/services/invoice.service'
vi.mock('@/services/auth.service')
vi.mock('@/services/invoice.service')
it('returns 401 when unauthenticated', async () => {
vi.mocked(authSvc.authService.getUser).mockResolvedValue(null)
const req = new NextRequest('http://localhost/api/invoices')
const res = await GET(req)
expect(res.status).toBe(401)
})
import { render, screen } from '@testing-library/react'
import { vi } from 'vitest'
import InvoiceList from '@/components/InvoiceList'
vi.mock('next/navigation', () => ({
useRouter: () => ({ push: vi.fn() }),
useParams: () => ({}),
}))
For every method, cover:
Do not write tests that only assert a mock was called — assert observable behavior (return values, thrown errors, rendered text).
npx vitest run <test-file-path>
Fix any failures before marking done.