anchi-kit 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.antigravity/skills/article-extractor/SKILL.md +52 -0
- package/.antigravity/skills/artifacts-builder/SKILL.md +63 -0
- package/.antigravity/skills/aws-deployment/SKILL.md +85 -0
- package/.antigravity/skills/brainstorming/SKILL.md +73 -0
- package/.antigravity/skills/canvas-design/SKILL.md +62 -0
- package/.antigravity/skills/changelog-generator/SKILL.md +149 -0
- package/.antigravity/skills/changelog-generator/assets/changelog-template.md +60 -0
- package/.antigravity/skills/changelog-generator/scripts/generate-changelog.js +181 -0
- package/.antigravity/skills/claude-code/references/advanced-features.md +399 -0
- package/.antigravity/skills/claude-code/references/agent-skills.md +399 -0
- package/.antigravity/skills/claude-code/references/api-reference.md +498 -0
- package/.antigravity/skills/claude-code/references/best-practices.md +447 -0
- package/.antigravity/skills/claude-code/references/cicd-integration.md +428 -0
- package/.antigravity/skills/claude-code/references/common-workflows.md +119 -0
- package/.antigravity/skills/claude-code/references/configuration.md +480 -0
- package/.antigravity/skills/claude-code/references/enterprise-features.md +472 -0
- package/.antigravity/skills/claude-code/references/getting-started.md +252 -0
- package/.antigravity/skills/claude-code/references/hooks-and-plugins.md +444 -0
- package/.antigravity/skills/claude-code/references/hooks-comprehensive.md +622 -0
- package/.antigravity/skills/claude-code/references/ide-integration.md +316 -0
- package/.antigravity/skills/claude-code/references/mcp-integration.md +386 -0
- package/.antigravity/skills/claude-code/references/slash-commands.md +489 -0
- package/.antigravity/skills/claude-code/references/troubleshooting.md +456 -0
- package/.antigravity/skills/claude-code/skill.md +60 -0
- package/.antigravity/skills/code-quality/SKILL.md +273 -0
- package/.antigravity/skills/comprehensive-review/complexity.md +11 -0
- package/.antigravity/skills/comprehensive-review/index.yaml +19 -0
- package/.antigravity/skills/comprehensive-review/maintainability.md +12 -0
- package/.antigravity/skills/comprehensive-review/readability.md +12 -0
- package/.antigravity/skills/content-research-writer/SKILL.md +65 -0
- package/.antigravity/skills/csv-data-analyzer/SKILL.md +91 -0
- package/.antigravity/skills/d3-visualization/SKILL.md +65 -0
- package/.antigravity/skills/debugging/references/root-cause-analysis-methods.md +140 -0
- package/.antigravity/skills/engineering-discipline/incremental-change.md +15 -0
- package/.antigravity/skills/engineering-discipline/index.yaml +30 -0
- package/.antigravity/skills/engineering-discipline/planning-first.md +18 -0
- package/.antigravity/skills/engineering-discipline/reasoning-clarity.md +19 -0
- package/.antigravity/skills/engineering-discipline/verify-before-commit.md +17 -0
- package/.antigravity/skills/file-organizer/SKILL.md +64 -0
- package/.antigravity/skills/git-automation/SKILL.md +68 -0
- package/.antigravity/skills/git-automation/references/branch-finishing.md +64 -0
- package/.antigravity/skills/impact-scoring/SKILL.md +219 -0
- package/.antigravity/skills/kaizen/SKILL.md +94 -0
- package/.antigravity/skills/performance-patterns/SKILL.md +209 -0
- package/.antigravity/skills/playwright-testing/SKILL.md +115 -0
- package/.antigravity/skills/playwright-testing/references/playwright-patterns.md +122 -0
- package/.antigravity/skills/prompt-engineering/SKILL.md +126 -0
- package/.antigravity/skills/prompt-engineering/references/anthropic-best-practices.md +160 -0
- package/.antigravity/skills/pypict-testing/SKILL.md +79 -0
- package/.antigravity/skills/review-implementing/SKILL.md +287 -0
- package/.antigravity/skills/security-audit/SKILL.md +263 -0
- package/.antigravity/skills/software-architecture/SKILL.md +91 -0
- package/.antigravity/skills/software-architecture/references/solid-principles.md +293 -0
- package/.antigravity/skills/subagent-driven-development/SKILL.md +237 -0
- package/.antigravity/skills/test-driven-development/SKILL.md +130 -0
- package/.antigravity/skills/test-driven-development/references/tdd-patterns.md +124 -0
- package/.antigravity/skills/test-driven-development/references/testing-strategies.md +131 -0
- package/.antigravity/skills/test-fixing/SKILL.md +256 -0
- package/.antigravity/skills/theme-factory/SKILL.md +63 -0
- package/.antigravity/workflows/clean.md +333 -0
- package/.antigravity/workflows/health.md +228 -0
- package/.cursor/skills/_packs/common/pack-architecture.md +40 -0
- package/.cursor/skills/_packs/common/pack-devops.md +43 -0
- package/.cursor/skills/_packs/common/pack-productivity.md +37 -0
- package/.cursor/skills/_packs/common/pack-quality.md +41 -0
- package/.cursor/skills/_packs/data/pack-ai.md +41 -0
- package/.cursor/skills/_packs/data/pack-data-science.md +36 -0
- package/.cursor/skills/_packs/mobile/pack-mobile.md +40 -0
- package/.cursor/skills/_packs/web/pack-backend.md +61 -0
- package/.cursor/skills/_packs/web/pack-frontend.md +66 -0
- package/.cursor/skills/_packs/web3/pack-blockchain.md +37 -0
- package/.cursor/skills/advanced-coding/references/getting-started.md +93 -0
- package/.cursor/skills/advanced-coding/skill.md +34 -0
- package/.cursor/skills/template-skill/SKILL.md +6 -0
- package/README.md +1 -1
- package/docs/reference/SECURITY.md +1 -1
- package/package.json +2 -2
- package/src/cli.js +5 -5
- package/src/commands/dashboard.js +3 -3
- package/src/commands/init.js +15 -3
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: subagent-driven-development
|
|
3
|
+
description: Subagent-Driven Development (SADD) methodology for dispatching independent subagents to handle individual tasks with code review checkpoints between iterations. Enables rapid, controlled parallel development with quality gates.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Subagent-Driven Development (SADD)
|
|
7
|
+
|
|
8
|
+
Parallel development workflow using independent subagents with built-in quality checkpoints.
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
- Large features requiring multiple parallel workstreams
|
|
13
|
+
- Complex systems with independent components
|
|
14
|
+
- When development velocity is critical
|
|
15
|
+
- Projects with clear component boundaries
|
|
16
|
+
- Teams practicing modular architecture
|
|
17
|
+
|
|
18
|
+
## Core Concept
|
|
19
|
+
|
|
20
|
+
**Break → Dispatch → Review → Integrate**
|
|
21
|
+
|
|
22
|
+
Instead of one agent doing everything sequentially, dispatch multiple specialized subagents to work in parallel, with mandatory code review checkpoints between iterations.
|
|
23
|
+
|
|
24
|
+
## SADD Workflow
|
|
25
|
+
|
|
26
|
+
### 1. Task Decomposition
|
|
27
|
+
|
|
28
|
+
Break feature into independent, parallelizable tasks:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
Feature: User Authentication System
|
|
32
|
+
↓
|
|
33
|
+
Subagents:
|
|
34
|
+
1. Database schema + migration
|
|
35
|
+
2. API endpoints + validation
|
|
36
|
+
3. Frontend forms + state
|
|
37
|
+
4. Email verification service
|
|
38
|
+
5. Session management
|
|
39
|
+
6. Security audit
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Key:** Each task must be completable independently
|
|
43
|
+
|
|
44
|
+
### 2. Subagent Dispatch
|
|
45
|
+
|
|
46
|
+
Create independent subagent for each task:
|
|
47
|
+
|
|
48
|
+
```markdown
|
|
49
|
+
## Subagent 1: Database Schema
|
|
50
|
+
|
|
51
|
+
**Scope:** User table, indexes, migration scripts
|
|
52
|
+
**Deliverables:**
|
|
53
|
+
|
|
54
|
+
- migration files
|
|
55
|
+
- model definitions
|
|
56
|
+
- unit tests
|
|
57
|
+
**Dependencies:** None
|
|
58
|
+
**Checkpoint:** Schema review before proceeding
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Code Review Checkpoints
|
|
62
|
+
|
|
63
|
+
**MANDATORY** review before next iteration:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Iteration 1 (Implementation)
|
|
67
|
+
↓
|
|
68
|
+
CHECKPOINT (Code Review)
|
|
69
|
+
↓
|
|
70
|
+
Iteration 2 (Refinement)
|
|
71
|
+
↓
|
|
72
|
+
CHECKPOINT (Integration Review)
|
|
73
|
+
↓
|
|
74
|
+
Merge
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Checkpoint Criteria:**
|
|
78
|
+
|
|
79
|
+
- Code quality standards met
|
|
80
|
+
- Tests passing
|
|
81
|
+
- Documentation complete
|
|
82
|
+
- No architectural violations
|
|
83
|
+
- Security reviewed
|
|
84
|
+
|
|
85
|
+
### 4. Parallel Execution
|
|
86
|
+
|
|
87
|
+
Multiple subagents work simultaneously:
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
t=0: Dispatch 6 subagents
|
|
91
|
+
t=1: All working in parallel
|
|
92
|
+
t=2: Checkpoints (reviews happen)
|
|
93
|
+
t=3: Continue or iterate
|
|
94
|
+
t=4: Integration phase
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Best Practices
|
|
98
|
+
|
|
99
|
+
1. **Clear Boundaries** - Each subagent owns distinct scope
|
|
100
|
+
2. **Explicit Dependencies** - Document what depends on what
|
|
101
|
+
3. **Quality Gates** - Never skip checkpoints
|
|
102
|
+
4. **Communication** - Subagents report status regularly
|
|
103
|
+
5. **Integration Plan** - Know how pieces fit together
|
|
104
|
+
|
|
105
|
+
## Subagent Task Template
|
|
106
|
+
|
|
107
|
+
```markdown
|
|
108
|
+
# Subagent: [Name]
|
|
109
|
+
|
|
110
|
+
## Scope
|
|
111
|
+
|
|
112
|
+
- [What this subagent is responsible for]
|
|
113
|
+
|
|
114
|
+
## Deliverables
|
|
115
|
+
|
|
116
|
+
- [ ] File 1
|
|
117
|
+
- [ ] File 2
|
|
118
|
+
- [ ] Tests
|
|
119
|
+
- [ ] Documentation
|
|
120
|
+
|
|
121
|
+
## Dependencies
|
|
122
|
+
|
|
123
|
+
- Requires: [Other subagent outputs]
|
|
124
|
+
- Provides: [What others need from this]
|
|
125
|
+
|
|
126
|
+
## Checkpoint Criteria
|
|
127
|
+
|
|
128
|
+
- [ ] Code quality: passed linting
|
|
129
|
+
- [ ] Tests: 100% passing
|
|
130
|
+
- [ ] Security: reviewed
|
|
131
|
+
- [ ] Documentation: complete
|
|
132
|
+
|
|
133
|
+
## Status
|
|
134
|
+
|
|
135
|
+
- [ ] Planning
|
|
136
|
+
- [ ] Implementation
|
|
137
|
+
- [ ] Review
|
|
138
|
+
- [ ] Complete
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Example: E-Commerce Feature
|
|
142
|
+
|
|
143
|
+
**Feature:** Product Recommendations
|
|
144
|
+
|
|
145
|
+
**Decomposition:**
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
Subagent A: Data Pipeline
|
|
149
|
+
→ Fetch user behavior data
|
|
150
|
+
→ Process purchase history
|
|
151
|
+
→ Generate feature vectors
|
|
152
|
+
|
|
153
|
+
Subagent B: ML Model
|
|
154
|
+
→ Train recommendation model
|
|
155
|
+
→ Test accuracy (>85%)
|
|
156
|
+
→ Export model artifacts
|
|
157
|
+
|
|
158
|
+
Subagent C: API Service
|
|
159
|
+
→ REST endpoint /recommendations
|
|
160
|
+
→ Model inference
|
|
161
|
+
→ Response caching
|
|
162
|
+
|
|
163
|
+
Subagent D: Frontend Component
|
|
164
|
+
→ Recommendation widget
|
|
165
|
+
→ Click tracking
|
|
166
|
+
→ A/B test integration
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Parallel Timeline:**
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
Day 1: All 4 subagents start
|
|
173
|
+
Day 2: Checkpoint reviews
|
|
174
|
+
Day 3: Refinements
|
|
175
|
+
Day 4: Integration testing
|
|
176
|
+
Day 5: Production deploy
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Sequential would take:** ~10-15 days
|
|
180
|
+
**SADD approach:** ~5 days
|
|
181
|
+
|
|
182
|
+
## Integration Strategy
|
|
183
|
+
|
|
184
|
+
### Incremental Integration
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
1. Integrate A + B → Test
|
|
188
|
+
2. Integrate C → Test
|
|
189
|
+
3. Integrate D → Test
|
|
190
|
+
4. Full system test
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Conflict Resolution
|
|
194
|
+
|
|
195
|
+
When subagents conflict:
|
|
196
|
+
|
|
197
|
+
1. **Identify:** Which boundary was violated?
|
|
198
|
+
2. **Discuss:** Why did conflict happen?
|
|
199
|
+
3. **Resolve:** Adjust boundaries or merge approach
|
|
200
|
+
4. **Document:** Update task decomposition
|
|
201
|
+
|
|
202
|
+
## Anti-Patterns
|
|
203
|
+
|
|
204
|
+
❌ **Too Fine-Grained**
|
|
205
|
+
|
|
206
|
+
- Don't create subagent for every single file
|
|
207
|
+
- Minimum: 1 day of work per subagent
|
|
208
|
+
|
|
209
|
+
❌ **Skipping Checkpoints**
|
|
210
|
+
|
|
211
|
+
- Never merge without review
|
|
212
|
+
- Quality gates are mandatory
|
|
213
|
+
|
|
214
|
+
❌ **Unclear Dependencies**
|
|
215
|
+
|
|
216
|
+
- Document all dependencies upfront
|
|
217
|
+
- Update as discovered
|
|
218
|
+
|
|
219
|
+
❌ **No Integration Plan**
|
|
220
|
+
|
|
221
|
+
- Know how pieces fit together
|
|
222
|
+
- Test integration frequently
|
|
223
|
+
|
|
224
|
+
## References
|
|
225
|
+
|
|
226
|
+
See [references/subagent-patterns.md](references/subagent-patterns.md) for:
|
|
227
|
+
|
|
228
|
+
- Advanced decomposition strategies
|
|
229
|
+
- Checkpoint review templates
|
|
230
|
+
- Integration testing patterns
|
|
231
|
+
- Communication protocols
|
|
232
|
+
|
|
233
|
+
See [references/code-review-checkpoints.md](references/code-review-checkpoints.md) for:
|
|
234
|
+
|
|
235
|
+
- Review criteria checklists
|
|
236
|
+
- Quality gate definitions
|
|
237
|
+
- Automated checkpoint validation
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: test-driven-development
|
|
3
|
+
description: Test-Driven Development workflow for implementing features and bugfixes. Use when implementing any feature or bugfix, before writing implementation code. Guides developers through the red-green-refactor cycle with best practices.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Test-Driven Development
|
|
7
|
+
|
|
8
|
+
Implements Test-Driven Development (TDD) methodology - write tests first, then implementation.
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
- Implementing any new feature
|
|
13
|
+
- Fixing bugs
|
|
14
|
+
- Refactoring existing code
|
|
15
|
+
- When user requests TDD workflow
|
|
16
|
+
- Before writing implementation code
|
|
17
|
+
|
|
18
|
+
## TDD Workflow (Red-Green-Refactor)
|
|
19
|
+
|
|
20
|
+
### 1. Red - Write Failing Test
|
|
21
|
+
|
|
22
|
+
Write a test that defines desired behavior:
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
// Example: test/user.test.js
|
|
26
|
+
describe("User", () => {
|
|
27
|
+
it("should create user with email", () => {
|
|
28
|
+
const user = new User({ email: "test@example.com" });
|
|
29
|
+
expect(user.email).toBe("test@example.com");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Run test** - it should fail (red)
|
|
35
|
+
|
|
36
|
+
### 2. Green - Make It Pass
|
|
37
|
+
|
|
38
|
+
Write minimal code to make test pass:
|
|
39
|
+
|
|
40
|
+
```javascript
|
|
41
|
+
// src/user.js
|
|
42
|
+
class User {
|
|
43
|
+
constructor({ email }) {
|
|
44
|
+
this.email = email;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
**Run test again** - it should pass (green)
|
|
50
|
+
|
|
51
|
+
### 3. Refactor - Clean Up
|
|
52
|
+
|
|
53
|
+
Improve code quality while keeping tests green:
|
|
54
|
+
|
|
55
|
+
- Remove duplication
|
|
56
|
+
- Improve naming
|
|
57
|
+
- Extract functions
|
|
58
|
+
- Optimize performance
|
|
59
|
+
|
|
60
|
+
**Run tests** - should still pass
|
|
61
|
+
|
|
62
|
+
## Best Practices
|
|
63
|
+
|
|
64
|
+
1. **One Test at a Time** - Focus on one behavior per test
|
|
65
|
+
2. **Small Steps** - Write small, incremental tests
|
|
66
|
+
3. **Test Behavior, Not Implementation** - Test what, not how
|
|
67
|
+
4. **Keep Tests Fast** - Tests should run in milliseconds
|
|
68
|
+
5. **Independent Tests** - Each test should be isolated
|
|
69
|
+
6. **Clear Test Names** - Describe expected behavior
|
|
70
|
+
|
|
71
|
+
## Test Structure (AAA Pattern)
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
it("should validate email format", () => {
|
|
75
|
+
// Arrange - Setup test data
|
|
76
|
+
const invalidEmail = "not-an-email";
|
|
77
|
+
|
|
78
|
+
// Act - Execute the behavior
|
|
79
|
+
const result = validateEmail(invalidEmail);
|
|
80
|
+
|
|
81
|
+
// Assert - Verify the outcome
|
|
82
|
+
expect(result.valid).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Common Testing Patterns
|
|
87
|
+
|
|
88
|
+
See [references/tdd-patterns.md](references/tdd-patterns.md) for:
|
|
89
|
+
|
|
90
|
+
- Unit testing patterns
|
|
91
|
+
- Integration testing approaches
|
|
92
|
+
- Mocking strategies
|
|
93
|
+
- Test data builders
|
|
94
|
+
|
|
95
|
+
## Testing Strategies
|
|
96
|
+
|
|
97
|
+
See [references/testing-strategies.md](references/testing-strategies.md) for:
|
|
98
|
+
|
|
99
|
+
- Frontend component testing
|
|
100
|
+
- API endpoint testing
|
|
101
|
+
- Database interaction testing
|
|
102
|
+
- Error handling tests
|
|
103
|
+
- Edge case identification
|
|
104
|
+
|
|
105
|
+
## Framework Examples
|
|
106
|
+
|
|
107
|
+
### Jest (JavaScript/TypeScript)
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm install --save-dev jest @types/jest
|
|
111
|
+
npx jest --watch
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Pytest (Python)
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install pytest
|
|
118
|
+
pytest --watch
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Go Testing
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
go test ./... -v
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## References
|
|
128
|
+
|
|
129
|
+
- [TDD Patterns](references/tdd-patterns.md) - Common TDD patterns
|
|
130
|
+
- [Testing Strategies](references/testing-strategies.md) - Strategies for different scenarios
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# TDD Patterns
|
|
2
|
+
|
|
3
|
+
## Unit Testing Patterns
|
|
4
|
+
|
|
5
|
+
### Test Data Builders
|
|
6
|
+
|
|
7
|
+
Create reusable test data factories:
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
10
|
+
class UserBuilder {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.user = {
|
|
13
|
+
email: "test@example.com",
|
|
14
|
+
name: "Test User",
|
|
15
|
+
role: "user",
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
withEmail(email) {
|
|
20
|
+
this.user.email = email;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
withRole(role) {
|
|
25
|
+
this.user.role = role;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
build() {
|
|
30
|
+
return this.user;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Usage
|
|
35
|
+
const admin = new UserBuilder().withRole("admin").build();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Mock Objects
|
|
39
|
+
|
|
40
|
+
Replace external dependencies:
|
|
41
|
+
|
|
42
|
+
```javascript
|
|
43
|
+
const mockDatabase = {
|
|
44
|
+
findUser: jest.fn().mockResolvedValue({ id: 1, name: "John" }),
|
|
45
|
+
createUser: jest.fn().mockResolvedValue({ id: 2 }),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
test("should fetch user from database", async () => {
|
|
49
|
+
const user = await getUserById(1, mockDatabase);
|
|
50
|
+
expect(mockDatabase.findUser).toHaveBeenCalledWith(1);
|
|
51
|
+
expect(user.name).toBe("John");
|
|
52
|
+
});
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Spy Pattern
|
|
56
|
+
|
|
57
|
+
Verify function calls without replacing behavior:
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
const logger = {
|
|
61
|
+
log: jest.fn(),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
performAction(logger);
|
|
65
|
+
expect(logger.log).toHaveBeenCalledWith("Action performed");
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Integration Testing Patterns
|
|
69
|
+
|
|
70
|
+
### Database Test Pattern
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
beforeEach(async () => {
|
|
74
|
+
await database.reset();
|
|
75
|
+
await database.seed();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(async () => {
|
|
79
|
+
await database.cleanup();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("should persist user to database", async () => {
|
|
83
|
+
const user = await createUser({ email: "test@example.com" });
|
|
84
|
+
const found = await database.users.findByEmail("test@example.com");
|
|
85
|
+
expect(found).toBeDefined();
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### API Test Pattern
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
describe("POST /api/users", () => {
|
|
93
|
+
it("should create user and return 201", async () => {
|
|
94
|
+
const response = await request(app)
|
|
95
|
+
.post("/api/users")
|
|
96
|
+
.send({ email: "new@example.com", name: "New User" });
|
|
97
|
+
|
|
98
|
+
expect(response.status).toBe(201);
|
|
99
|
+
expect(response.body.email).toBe("new@example.com");
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Behavior-Driven Development (BDD)
|
|
105
|
+
|
|
106
|
+
Describe tests in business terms:
|
|
107
|
+
|
|
108
|
+
```javascript
|
|
109
|
+
describe("User Authentication", () => {
|
|
110
|
+
describe("when credentials are valid", () => {
|
|
111
|
+
it("grants access", async () => {
|
|
112
|
+
const result = await login("user@example.com", "password");
|
|
113
|
+
expect(result.success).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("when credentials are invalid", () => {
|
|
118
|
+
it("denies access", async () => {
|
|
119
|
+
const result = await login("user@example.com", "wrong");
|
|
120
|
+
expect(result.success).toBe(false);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
```
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# Testing Strategies
|
|
2
|
+
|
|
3
|
+
## Frontend Component Testing
|
|
4
|
+
|
|
5
|
+
### React Component Test
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
import { render, screen, fireEvent } from "@testing-library/react";
|
|
9
|
+
import LoginForm from "./LoginForm";
|
|
10
|
+
|
|
11
|
+
test("should submit form with valid data", () => {
|
|
12
|
+
const onSubmit = jest.fn();
|
|
13
|
+
render(<LoginForm onSubmit={onSubmit} />);
|
|
14
|
+
|
|
15
|
+
fireEvent.change(screen.getByLabelText("Email"), {
|
|
16
|
+
target: { value: "test@example.com" },
|
|
17
|
+
});
|
|
18
|
+
fireEvent.change(screen.getByLabelText("Password"), {
|
|
19
|
+
target: { value: "password123" },
|
|
20
|
+
});
|
|
21
|
+
fireEvent.click(screen.getByText("Login"));
|
|
22
|
+
|
|
23
|
+
expect(onSubmit).toHaveBeenCalledWith({
|
|
24
|
+
email: "test@example.com",
|
|
25
|
+
password: "password123",
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Vue Component Test
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import { mount } from "@vue/test-utils";
|
|
34
|
+
import Counter from "./Counter.vue";
|
|
35
|
+
|
|
36
|
+
test("increments counter on button click", async () => {
|
|
37
|
+
const wrapper = mount(Counter);
|
|
38
|
+
await wrapper.find("button").trigger("click");
|
|
39
|
+
expect(wrapper.text()).toContain("1");
|
|
40
|
+
});
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API Endpoint Testing
|
|
44
|
+
|
|
45
|
+
### REST API Test
|
|
46
|
+
|
|
47
|
+
```javascript
|
|
48
|
+
describe("GET /api/users/:id", () => {
|
|
49
|
+
it("returns user when exists", async () => {
|
|
50
|
+
const user = await createTestUser({ name: "John" });
|
|
51
|
+
|
|
52
|
+
const response = await request(app).get(`/api/users/${user.id}`);
|
|
53
|
+
|
|
54
|
+
expect(response.status).toBe(200);
|
|
55
|
+
expect(response.body.name).toBe("John");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("returns 404 when user not found", async () => {
|
|
59
|
+
const response = await request(app).get("/api/users/999999");
|
|
60
|
+
expect(response.status).toBe(404);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Database Interaction Testing
|
|
66
|
+
|
|
67
|
+
### Transaction Test Pattern
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
test("should rollback on error", async () => {
|
|
71
|
+
await expect(async () => {
|
|
72
|
+
await database.transaction(async (trx) => {
|
|
73
|
+
await trx.users.create({ email: "test@example.com" });
|
|
74
|
+
throw new Error("Rollback!");
|
|
75
|
+
});
|
|
76
|
+
}).rejects.toThrow();
|
|
77
|
+
|
|
78
|
+
const user = await database.users.findByEmail("test@example.com");
|
|
79
|
+
expect(user).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Error Handling Tests
|
|
84
|
+
|
|
85
|
+
```javascript
|
|
86
|
+
test("should handle network errors gracefully", async () => {
|
|
87
|
+
mockApi.get.mockRejectedValue(new Error("Network error"));
|
|
88
|
+
|
|
89
|
+
const result = await fetchUserData(1);
|
|
90
|
+
|
|
91
|
+
expect(result.error).toBe("Failed to fetch data");
|
|
92
|
+
expect(result.data).toBeNull();
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Edge Cases
|
|
97
|
+
|
|
98
|
+
### Boundary Testing
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
describe("Pagination", () => {
|
|
102
|
+
it("handles first page", async () => {
|
|
103
|
+
const result = await getUsers({ page: 1, limit: 10 });
|
|
104
|
+
expect(result.page).toBe(1);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("handles last page", async () => {
|
|
108
|
+
const result = await getUsers({ page: 999, limit: 10 });
|
|
109
|
+
expect(result.data).toHaveLength(0);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("handles negative page", async () => {
|
|
113
|
+
const result = await getUsers({ page: -1, limit: 10 });
|
|
114
|
+
expect(result.error).toBe("Invalid page number");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Null/Undefined Handling
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
test("handles null input", () => {
|
|
123
|
+
expect(() => processUser(null)).toThrow("User cannot be null");
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test("handles undefined properties", () => {
|
|
127
|
+
const user = { name: "John" }; // email is undefined
|
|
128
|
+
const result = validateUser(user);
|
|
129
|
+
expect(result.errors).toContain("Email is required");
|
|
130
|
+
});
|
|
131
|
+
```
|