Loading...
Loading...
Testing procedures. Invoke with /tzurot-testing for test execution, coverage audits, and debugging test failures.
npx skill4agent add lbds137/tzurot tzurot-testing.claude/rules/02-code-standards.md# Run all tests
pnpm test
# Run specific service
pnpm --filter @tzurot/ai-worker test
# Run specific file
pnpm test -- MyService.test.ts
# Run with coverage
pnpm test:coverage
# Run only changed packages
pnpm focus:test# Run unified audit (CI does this automatically)
pnpm ops test:audit
# Filter by category
pnpm ops test:audit --category=services
pnpm ops test:audit --category=contracts
# Update baseline (after closing gaps)
pnpm ops test:audit --update
# Strict mode (fails on ANY gap)
pnpm ops test:audit --stricttest-coverage-baseline.json| Type | Pattern | Location | Infrastructure |
|---|---|---|---|
| Unit | | Next to source | Fully mocked |
| Integration | | Next to source | PGLite |
| Schema | | | Zod only |
pnpm test -- MyService.test.ts --reporter=verbose// ❌ WRONG - Promise rejection warning
const promise = asyncFunction();
await vi.runAllTimersAsync(); // Rejection happens here!
await expect(promise).rejects.toThrow(); // Too late
// ✅ CORRECT - Attach handler BEFORE advancing
const promise = asyncFunction();
const assertion = expect(promise).rejects.toThrow('Error');
await vi.runAllTimersAsync();
await assertion;beforeEach(() => {
vi.clearAllMocks(); // Clear call history, keep impl
});
afterEach(() => {
vi.restoreAllMocks(); // Restore originals (spies only)
});// Use async factory for vi.mock hoisting
vi.mock('./MyService.js', async () => {
const { mockMyService } = await import('../test/mocks/MyService.mock.js');
return mockMyService;
});
// Import accessors after vi.mock
import { getMyServiceMock } from '../test/mocks/index.js';
it('should call service', () => {
expect(getMyServiceMock().someMethod).toHaveBeenCalled();
});describe('UserService', () => {
let pglite: PGlite;
let prisma: PrismaClient;
beforeAll(async () => {
pglite = new PGlite({ extensions: { vector } });
await pglite.exec(loadPGliteSchema());
prisma = new PrismaClient({ adapter: new PrismaPGlite(pglite) });
});
it('should create user', async () => {
const service = new UserService(prisma);
const userId = await service.getOrCreateUser('123', 'testuser');
expect(userId).toBeDefined();
});
});loadPGliteSchema()*.int.test.tspnpm testpnpm test:int| Change | Why |
|---|---|
| Add/remove slash command options | |
| Add/remove subcommands | Same snapshot tests |
| Restructure command directories | |
| Change component prefix routing | Integration tests verify button/select menu routing |
pnpm vitest run --config vitest.int.config.ts <file> --update.int.test.ts.schema.test.tspnpm ops test:auditdocs/reference/guides/TESTING.mdservices/*/src/test/mocks/docs/reference/testing/PGLITE_SETUP.mddocs/reference/testing/COVERAGE_AUDIT_SYSTEM.md.claude/rules/02-code-standards.md