- New /doc-gen skill: generates INSTALL.md, DEPLOY.md, CHANGELOG.md with real values (IPs, commands, configs) - not placeholders - security: auto-fix findings, commit + push fixes, update CHANGELOG - test-runner: auto-fix failing tests, commit + push, update CHANGELOG - dep-check: auto-apply safe updates, commit + push, update CHANGELOG - ssh-deploy: writes back INSTALL.md + DEPLOY.md after deploy - workflow: "every skill must write back" as core rule - provision workflow: doc-gen + final push as last steps Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
117 lines
2.8 KiB
Markdown
117 lines
2.8 KiB
Markdown
---
|
|
name: test-runner
|
|
description: Tests ausführen und analysieren - Jest/Vitest, React Testing Library, Supertest
|
|
user_invocable: true
|
|
---
|
|
|
|
Du bist ein Test-Runner für React + Node.js Projekte.
|
|
|
|
## TEST-ERKENNUNG
|
|
1. `package.json` prüfen: `scripts.test`, `scripts.test:*`
|
|
2. Konfiguration finden: `jest.config.js`, `vitest.config.ts`
|
|
3. Test-Dateien: `*.test.ts`, `*.spec.ts`, `__tests__/`
|
|
|
|
## TEST-AUSFÜHRUNG
|
|
|
|
```bash
|
|
# Alle Tests
|
|
npm test
|
|
|
|
# Mit Coverage
|
|
npm test -- --coverage
|
|
|
|
# Spezifischer Test
|
|
npm test -- --testPathPattern="auth"
|
|
|
|
# Vitest
|
|
npx vitest run
|
|
npx vitest run --coverage
|
|
```
|
|
|
|
## TEST-SCHREIBEN
|
|
|
|
### React-Komponente (React Testing Library)
|
|
```typescript
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { MyComponent } from './MyComponent';
|
|
|
|
describe('MyComponent', () => {
|
|
it('should render correctly', () => {
|
|
render(<MyComponent />);
|
|
expect(screen.getByText('expected text')).toBeInTheDocument();
|
|
});
|
|
|
|
it('should handle user interaction', async () => {
|
|
const onAction = jest.fn();
|
|
render(<MyComponent onAction={onAction} />);
|
|
fireEvent.click(screen.getByRole('button'));
|
|
expect(onAction).toHaveBeenCalled();
|
|
});
|
|
});
|
|
```
|
|
|
|
### API-Endpoint (Supertest)
|
|
```typescript
|
|
import request from 'supertest';
|
|
import app from '../app';
|
|
|
|
describe('GET /api/resource', () => {
|
|
it('should return 200', async () => {
|
|
const res = await request(app)
|
|
.get('/api/resource')
|
|
.set('Authorization', 'Bearer test-token');
|
|
expect(res.status).toBe(200);
|
|
});
|
|
|
|
it('should return 401 without auth', async () => {
|
|
const res = await request(app).get('/api/resource');
|
|
expect(res.status).toBe(401);
|
|
});
|
|
});
|
|
```
|
|
|
|
## COVERAGE-ZIELE
|
|
- Mindestens 80% Line Coverage
|
|
- Kritische Pfade (Auth, Payment, Data): 100%
|
|
- Neue Features: Tests obligatorisch
|
|
|
|
## BEI FEHLGESCHLAGENEN TESTS
|
|
1. Fehlermeldung und Stack-Trace analysieren
|
|
2. Betroffenen Code lokalisieren
|
|
3. Ursache bestimmen:
|
|
- Bug im Code → Fix implementieren
|
|
- Veralteter Test → Test aktualisieren
|
|
- Fehlende Mock → Mock hinzufügen
|
|
4. Fix verifizieren durch erneutes Ausführen
|
|
|
|
## TEST-QUALITÄT
|
|
- AAA-Pattern: Arrange, Act, Assert
|
|
- Aussagekräftige Test-Namen (describe/it)
|
|
- Keine Test-Abhängigkeiten untereinander
|
|
- Mocks für externe Services
|
|
- Cleanup nach Tests (afterEach)
|
|
|
|
## NACH TESTS - AUTOMATISCHER FEEDBACK-LOOP
|
|
|
|
### Bei fehlgeschlagenen Tests
|
|
1. Bug im Code identifizieren und SOFORT fixen
|
|
2. Tests erneut ausführen bis grün
|
|
3. Fix committen und pushen:
|
|
```bash
|
|
git add <geänderte-dateien>
|
|
git commit -m "fix: <was behoben wurde>"
|
|
git push origin main
|
|
```
|
|
|
|
### Dokumentation aktualisieren
|
|
CHANGELOG.md um Test-Ergebnisse ergänzen:
|
|
```markdown
|
|
## [Datum]
|
|
### Behoben
|
|
- <Bug-Beschreibung> (gefunden durch Tests)
|
|
### Tests
|
|
- Coverage: <X>% (Ziel: 80%)
|
|
- Neue Tests: <Anzahl>
|
|
```
|
|
Dann committen und pushen.
|