cursor-kit-cli 1.2.0-beta → 1.2.0-beta.3
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/bin/cursor-reinstall-instance.sh +102 -0
- package/dist/cli.cjs +366 -69
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +367 -70
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +39 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +33 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/commands/docs.md +5 -3
- package/templates/commands/explain.md +5 -3
- package/templates/commands/fix.md +5 -3
- package/templates/commands/implement.md +5 -3
- package/templates/commands/refactor.md +5 -3
- package/templates/commands/review.md +5 -3
- package/templates/commands/test.md +5 -3
- package/templates/manifest.json +11 -8
- package/templates/rules/git.mdc +0 -2
- package/templates/rules/toc.mdc +17 -9
- package/templates/skills/aesthetic/SKILL.md +121 -0
- package/templates/skills/aesthetic/assets/design-guideline-template.md +163 -0
- package/templates/skills/aesthetic/assets/design-story-template.md +135 -0
- package/templates/skills/aesthetic/references/design-principles.md +62 -0
- package/templates/skills/aesthetic/references/design-resources.md +75 -0
- package/templates/skills/aesthetic/references/micro-interactions.md +53 -0
- package/templates/skills/aesthetic/references/storytelling-design.md +50 -0
- package/templates/skills/backend-development/SKILL.mdc +95 -0
- package/templates/skills/backend-development/references/backend-api-design.md +495 -0
- package/templates/skills/backend-development/references/backend-architecture.md +454 -0
- package/templates/skills/backend-development/references/backend-authentication.md +338 -0
- package/templates/skills/backend-development/references/backend-code-quality.md +659 -0
- package/templates/skills/backend-development/references/backend-debugging.md +904 -0
- package/templates/skills/backend-development/references/backend-devops.md +494 -0
- package/templates/skills/backend-development/references/backend-mindset.md +387 -0
- package/templates/skills/backend-development/references/backend-performance.md +397 -0
- package/templates/skills/backend-development/references/backend-security.md +290 -0
- package/templates/skills/backend-development/references/backend-technologies.md +256 -0
- package/templates/skills/backend-development/references/backend-testing.md +429 -0
- package/templates/skills/frontend-design/SKILL.mdc +41 -0
- package/templates/skills/frontend-design/references/animejs.md +396 -0
- package/templates/skills/frontend-development/SKILL.mdc +399 -0
- package/templates/skills/frontend-development/resources/common-patterns.md +331 -0
- package/templates/skills/frontend-development/resources/complete-examples.md +872 -0
- package/templates/skills/frontend-development/resources/component-patterns.md +502 -0
- package/templates/skills/frontend-development/resources/data-fetching.md +767 -0
- package/templates/skills/frontend-development/resources/file-organization.md +502 -0
- package/templates/skills/frontend-development/resources/loading-and-error-states.md +501 -0
- package/templates/skills/frontend-development/resources/performance.md +406 -0
- package/templates/skills/frontend-development/resources/routing-guide.md +364 -0
- package/templates/skills/frontend-development/resources/styling-guide.md +428 -0
- package/templates/skills/frontend-development/resources/typescript-standards.md +418 -0
- package/templates/skills/problem-solving/SKILL.mdc +96 -0
- package/templates/skills/problem-solving/references/attribution.md +69 -0
- package/templates/skills/problem-solving/references/collision-zone-thinking.md +79 -0
- package/templates/skills/problem-solving/references/inversion-exercise.md +91 -0
- package/templates/skills/problem-solving/references/meta-pattern-recognition.md +87 -0
- package/templates/skills/problem-solving/references/scale-game.md +95 -0
- package/templates/skills/problem-solving/references/simplification-cascades.md +80 -0
- package/templates/skills/problem-solving/references/when-stuck.md +72 -0
- package/templates/skills/research/SKILL.mdc +168 -0
- package/templates/skills/sequential-thinking/.env.example +8 -0
- package/templates/skills/sequential-thinking/README.md +183 -0
- package/templates/skills/sequential-thinking/SKILL.mdc +94 -0
- package/templates/skills/sequential-thinking/package.json +31 -0
- package/templates/skills/sequential-thinking/references/advanced-strategies.md +79 -0
- package/templates/skills/sequential-thinking/references/advanced-techniques.md +76 -0
- package/templates/skills/sequential-thinking/references/core-patterns.md +95 -0
- package/templates/skills/sequential-thinking/references/examples-api.md +88 -0
- package/templates/skills/sequential-thinking/references/examples-architecture.md +94 -0
- package/templates/skills/sequential-thinking/references/examples-debug.md +90 -0
- package/templates/skills/sequential-thinking/scripts/format-thought.js +159 -0
- package/templates/skills/sequential-thinking/scripts/process-thought.js +236 -0
- package/templates/skills/sequential-thinking/tests/format-thought.test.js +133 -0
- package/templates/skills/sequential-thinking/tests/process-thought.test.js +215 -0
- package/templates/skills/ui-styling/LICENSE.txt +202 -0
- package/templates/skills/ui-styling/SKILL.mdc +321 -0
- package/templates/skills/ui-styling/references/canvas-design-system.md +320 -0
- package/templates/skills/ui-styling/references/shadcn-accessibility.md +471 -0
- package/templates/skills/ui-styling/references/shadcn-components.md +424 -0
- package/templates/skills/ui-styling/references/shadcn-theming.md +373 -0
- package/templates/skills/ui-styling/references/tailwind-customization.md +483 -0
- package/templates/skills/ui-styling/references/tailwind-responsive.md +382 -0
- package/templates/skills/ui-styling/references/tailwind-utilities.md +455 -0
- package/templates/rules/frontend-design.mdc +0 -48
- package/templates/rules/performance.mdc +0 -54
- package/templates/rules/react.mdc +0 -58
- package/templates/rules/security.mdc +0 -50
- package/templates/rules/testing.mdc +0 -54
- package/templates/rules/typescript.mdc +0 -36
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Backend Technologies
|
|
2
|
+
|
|
3
|
+
Core technologies, frameworks, databases, and message queues for modern backend development (2025).
|
|
4
|
+
|
|
5
|
+
## Programming Languages
|
|
6
|
+
|
|
7
|
+
### Node.js/TypeScript
|
|
8
|
+
**Market Position:** TypeScript dominance in Node.js backend (industry standard)
|
|
9
|
+
|
|
10
|
+
**Best For:**
|
|
11
|
+
- Full-stack JavaScript teams
|
|
12
|
+
- Real-time applications (WebSockets, Socket.io)
|
|
13
|
+
- Rapid prototyping with npm ecosystem (2M+ packages)
|
|
14
|
+
- Event-driven architectures
|
|
15
|
+
|
|
16
|
+
**Popular Frameworks:**
|
|
17
|
+
- **NestJS** - Enterprise-grade, TypeScript-first, modular architecture
|
|
18
|
+
- **Express** - Lightweight, flexible, most popular (23M weekly downloads)
|
|
19
|
+
- **Fastify** - High performance (20k req/sec vs Express 15k req/sec)
|
|
20
|
+
- **tRPC** - End-to-end typesafe APIs without GraphQL
|
|
21
|
+
|
|
22
|
+
**When to Choose:** Team already using JavaScript/TypeScript, real-time features needed, rapid development priority
|
|
23
|
+
|
|
24
|
+
### Python
|
|
25
|
+
**Market Position:** FastAPI adoption surge - 73% migrating from Flask
|
|
26
|
+
|
|
27
|
+
**Best For:**
|
|
28
|
+
- Data-heavy applications
|
|
29
|
+
- ML/AI integration (TensorFlow, PyTorch)
|
|
30
|
+
- Scientific computing
|
|
31
|
+
- Scripting and automation
|
|
32
|
+
|
|
33
|
+
**Popular Frameworks:**
|
|
34
|
+
- **FastAPI** - Modern, async, auto-generated OpenAPI docs, validation via Pydantic
|
|
35
|
+
- **Django** - Batteries-included, ORM, admin panel, authentication
|
|
36
|
+
- **Flask** - Lightweight, flexible, microservices-friendly
|
|
37
|
+
|
|
38
|
+
**When to Choose:** Data science integration, ML/AI features, rapid prototyping, team Python expertise
|
|
39
|
+
|
|
40
|
+
### Go
|
|
41
|
+
**Market Position:** Preferred for microservices at scale (Docker, Kubernetes written in Go)
|
|
42
|
+
|
|
43
|
+
**Best For:**
|
|
44
|
+
- High-concurrency systems (goroutines)
|
|
45
|
+
- Microservices architectures
|
|
46
|
+
- CLI tools and DevOps tooling
|
|
47
|
+
- System programming
|
|
48
|
+
|
|
49
|
+
**Popular Frameworks:**
|
|
50
|
+
- **Gin** - Fast HTTP router (40x faster than Martini)
|
|
51
|
+
- **Echo** - High performance, extensible
|
|
52
|
+
- **Fiber** - Express-like API, built on Fasthttp
|
|
53
|
+
|
|
54
|
+
**When to Choose:** Microservices, high concurrency needs, DevOps tooling, simple deployment (single binary)
|
|
55
|
+
|
|
56
|
+
### Rust
|
|
57
|
+
**Market Position:** 72% most admired language, 1.5x faster than Go
|
|
58
|
+
|
|
59
|
+
**Best For:**
|
|
60
|
+
- Performance-critical systems
|
|
61
|
+
- Memory-safe system programming
|
|
62
|
+
- High-reliability requirements
|
|
63
|
+
- WebAssembly backends
|
|
64
|
+
|
|
65
|
+
**Popular Frameworks:**
|
|
66
|
+
- **Axum** - Ergonomic, modular, tokio-based
|
|
67
|
+
- **Actix-web** - Fastest web framework (benchmark leader)
|
|
68
|
+
- **Rocket** - Type-safe, easy to use
|
|
69
|
+
|
|
70
|
+
**When to Choose:** Maximum performance needed, memory safety critical, low-level control required
|
|
71
|
+
|
|
72
|
+
## Databases
|
|
73
|
+
|
|
74
|
+
### Relational (SQL)
|
|
75
|
+
|
|
76
|
+
#### PostgreSQL
|
|
77
|
+
**Market Position:** Most popular SQL database for new projects
|
|
78
|
+
|
|
79
|
+
**Strengths:**
|
|
80
|
+
- ACID compliance, data integrity
|
|
81
|
+
- JSON/JSONB support (hybrid SQL + NoSQL)
|
|
82
|
+
- Full-text search, geospatial (PostGIS)
|
|
83
|
+
- Advanced indexing (B-tree, Hash, GiST, GIN)
|
|
84
|
+
- Window functions, CTEs, materialized views
|
|
85
|
+
|
|
86
|
+
**Use Cases:**
|
|
87
|
+
- E-commerce (transactions critical)
|
|
88
|
+
- Financial applications
|
|
89
|
+
- Complex reporting requirements
|
|
90
|
+
- Multi-tenant applications
|
|
91
|
+
|
|
92
|
+
**When to Choose:** Need ACID guarantees, complex queries/joins, data integrity critical
|
|
93
|
+
|
|
94
|
+
### NoSQL
|
|
95
|
+
|
|
96
|
+
#### MongoDB
|
|
97
|
+
**Market Position:** Leading document database
|
|
98
|
+
|
|
99
|
+
**Strengths:**
|
|
100
|
+
- Flexible/evolving schemas
|
|
101
|
+
- Horizontal scaling (sharding built-in)
|
|
102
|
+
- Aggregation pipeline (powerful data processing)
|
|
103
|
+
- GridFS for large files
|
|
104
|
+
|
|
105
|
+
**Use Cases:**
|
|
106
|
+
- Content management systems
|
|
107
|
+
- Real-time analytics
|
|
108
|
+
- IoT data collection
|
|
109
|
+
- Catalogs with varied attributes
|
|
110
|
+
|
|
111
|
+
**When to Choose:** Schema flexibility needed, rapid iteration, horizontal scaling required
|
|
112
|
+
|
|
113
|
+
### Caching & In-Memory
|
|
114
|
+
|
|
115
|
+
#### Redis
|
|
116
|
+
**Market Position:** Industry standard for caching and session storage
|
|
117
|
+
|
|
118
|
+
**Capabilities:**
|
|
119
|
+
- In-memory key-value store
|
|
120
|
+
- Pub/sub messaging
|
|
121
|
+
- Sorted sets (leaderboards)
|
|
122
|
+
- Geospatial indexes
|
|
123
|
+
- Streams (event sourcing)
|
|
124
|
+
|
|
125
|
+
**Performance:** 10-100x faster than disk-based databases
|
|
126
|
+
|
|
127
|
+
**Use Cases:**
|
|
128
|
+
- Session storage
|
|
129
|
+
- Rate limiting
|
|
130
|
+
- Real-time leaderboards
|
|
131
|
+
- Job queues (Bull, BullMQ)
|
|
132
|
+
- Caching layer (90% DB load reduction)
|
|
133
|
+
|
|
134
|
+
**When to Choose:** Need sub-millisecond latency, caching layer, session management
|
|
135
|
+
|
|
136
|
+
## ORMs & Database Tools
|
|
137
|
+
|
|
138
|
+
### Modern ORMs (2025)
|
|
139
|
+
|
|
140
|
+
**Drizzle ORM** (TypeScript)
|
|
141
|
+
- Winning NestJS performance race
|
|
142
|
+
- 7.4kb, zero dependencies
|
|
143
|
+
- SQL-like syntax, full type safety
|
|
144
|
+
- Best for: Performance-critical TypeScript apps
|
|
145
|
+
|
|
146
|
+
**Prisma** (TypeScript)
|
|
147
|
+
- Auto-generated type-safe client
|
|
148
|
+
- Database migrations included
|
|
149
|
+
- Excellent DX with Prisma Studio
|
|
150
|
+
- Best for: Rapid development, type safety
|
|
151
|
+
|
|
152
|
+
**TypeORM** (TypeScript)
|
|
153
|
+
- Mature, feature-complete
|
|
154
|
+
- Supports Active Record + Data Mapper
|
|
155
|
+
- Best for: Complex enterprise apps
|
|
156
|
+
|
|
157
|
+
**SQLAlchemy** (Python)
|
|
158
|
+
- Industry standard Python ORM
|
|
159
|
+
- Powerful query builder
|
|
160
|
+
- Best for: Python backends
|
|
161
|
+
|
|
162
|
+
## Message Queues & Event Streaming
|
|
163
|
+
|
|
164
|
+
### RabbitMQ
|
|
165
|
+
**Best For:** Task queues, request/reply patterns
|
|
166
|
+
|
|
167
|
+
**Strengths:**
|
|
168
|
+
- Flexible routing (direct, topic, fanout, headers)
|
|
169
|
+
- Message acknowledgment and durability
|
|
170
|
+
- Dead letter exchanges
|
|
171
|
+
- Wide protocol support (AMQP, MQTT, STOMP)
|
|
172
|
+
|
|
173
|
+
**Use Cases:**
|
|
174
|
+
- Background job processing
|
|
175
|
+
- Microservices communication
|
|
176
|
+
- Email/notification queues
|
|
177
|
+
|
|
178
|
+
**When to Choose:** Traditional message queue needs, complex routing, moderate throughput
|
|
179
|
+
|
|
180
|
+
### Apache Kafka
|
|
181
|
+
**Best For:** Event streaming, millions messages/second
|
|
182
|
+
|
|
183
|
+
**Strengths:**
|
|
184
|
+
- Distributed, fault-tolerant
|
|
185
|
+
- High throughput (millions msg/sec)
|
|
186
|
+
- Message replay (retention-based)
|
|
187
|
+
- Stream processing (Kafka Streams)
|
|
188
|
+
|
|
189
|
+
**Use Cases:**
|
|
190
|
+
- Real-time analytics
|
|
191
|
+
- Event sourcing
|
|
192
|
+
- Log aggregation
|
|
193
|
+
- Netflix/Uber scale (billions events/day)
|
|
194
|
+
|
|
195
|
+
**When to Choose:** Event streaming, high throughput, event replay needed, real-time analytics
|
|
196
|
+
|
|
197
|
+
## Framework Comparisons
|
|
198
|
+
|
|
199
|
+
### Node.js Frameworks
|
|
200
|
+
|
|
201
|
+
| Framework | Performance | Learning Curve | Use Case |
|
|
202
|
+
|-----------|------------|----------------|----------|
|
|
203
|
+
| Express | Moderate | Easy | Simple APIs, learning |
|
|
204
|
+
| NestJS | Moderate | Steep | Enterprise apps |
|
|
205
|
+
| Fastify | High | Moderate | Performance-critical |
|
|
206
|
+
| tRPC | High | Moderate | Full-stack TypeScript |
|
|
207
|
+
|
|
208
|
+
### Python Frameworks
|
|
209
|
+
|
|
210
|
+
| Framework | Performance | Features | Use Case |
|
|
211
|
+
|-----------|------------|----------|----------|
|
|
212
|
+
| FastAPI | High | Modern, async | New projects, APIs |
|
|
213
|
+
| Django | Moderate | Batteries-included | Full-featured apps |
|
|
214
|
+
| Flask | Moderate | Minimal | Microservices, simple APIs |
|
|
215
|
+
|
|
216
|
+
## Technology Selection Flowchart
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
Start → Need real-time features?
|
|
220
|
+
→ Yes → Node.js + Socket.io
|
|
221
|
+
→ No → Need ML/AI integration?
|
|
222
|
+
→ Yes → Python + FastAPI
|
|
223
|
+
→ No → Need maximum performance?
|
|
224
|
+
→ Yes → Rust + Axum
|
|
225
|
+
→ No → Need high concurrency?
|
|
226
|
+
→ Yes → Go + Gin
|
|
227
|
+
→ No → Node.js + NestJS (safe default)
|
|
228
|
+
|
|
229
|
+
Database Selection:
|
|
230
|
+
ACID needed? → Yes → PostgreSQL
|
|
231
|
+
→ No → Flexible schema? → Yes → MongoDB
|
|
232
|
+
→ No → PostgreSQL (default)
|
|
233
|
+
|
|
234
|
+
Caching needed? → Always use Redis
|
|
235
|
+
|
|
236
|
+
Message Queue:
|
|
237
|
+
Millions msg/sec? → Yes → Kafka
|
|
238
|
+
→ No → RabbitMQ
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Common Pitfalls
|
|
242
|
+
|
|
243
|
+
1. **Choosing NoSQL for relational data** - Use PostgreSQL if data has clear relationships
|
|
244
|
+
2. **Not using connection pooling** - Implement pooling for 5-10x performance boost
|
|
245
|
+
3. **Ignoring indexes** - Add indexes to frequently queried columns (30% I/O reduction)
|
|
246
|
+
4. **Over-engineering with microservices** - Start monolith, split when needed
|
|
247
|
+
5. **Not caching** - Redis caching provides 90% DB load reduction
|
|
248
|
+
|
|
249
|
+
## Resources
|
|
250
|
+
|
|
251
|
+
- **NestJS:** https://nestjs.com
|
|
252
|
+
- **FastAPI:** https://fastapi.tiangolo.com
|
|
253
|
+
- **PostgreSQL:** https://www.postgresql.org/docs/
|
|
254
|
+
- **MongoDB:** https://www.mongodb.com/docs/
|
|
255
|
+
- **Redis:** https://redis.io/docs/
|
|
256
|
+
- **Kafka:** https://kafka.apache.org/documentation/
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
# Backend Testing Strategies
|
|
2
|
+
|
|
3
|
+
Comprehensive testing approaches, frameworks, and quality assurance practices (2025).
|
|
4
|
+
|
|
5
|
+
## Test Pyramid (70-20-10 Rule)
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
/\
|
|
9
|
+
/E2E\ 10% - End-to-End Tests
|
|
10
|
+
/------\
|
|
11
|
+
/Integr.\ 20% - Integration Tests
|
|
12
|
+
/----------\
|
|
13
|
+
/ Unit \ 70% - Unit Tests
|
|
14
|
+
/--------------\
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
**Rationale:**
|
|
18
|
+
- Unit tests: Fast, cheap, isolate bugs quickly
|
|
19
|
+
- Integration tests: Verify component interactions
|
|
20
|
+
- E2E tests: Expensive, slow, but validate real user flows
|
|
21
|
+
|
|
22
|
+
## Unit Testing
|
|
23
|
+
|
|
24
|
+
### Frameworks by Language
|
|
25
|
+
|
|
26
|
+
**TypeScript/JavaScript:**
|
|
27
|
+
- **Vitest** - 50% faster than Jest in CI/CD, ESM native
|
|
28
|
+
- **Jest** - Mature, large ecosystem, snapshot testing
|
|
29
|
+
|
|
30
|
+
**Python:**
|
|
31
|
+
- **Pytest** - Industry standard, fixtures, parametrization
|
|
32
|
+
- **Unittest** - Built-in, standard library
|
|
33
|
+
|
|
34
|
+
**Go:**
|
|
35
|
+
- **testing** - Built-in, table-driven tests
|
|
36
|
+
- **testify** - Assertions and mocking
|
|
37
|
+
|
|
38
|
+
### Best Practices
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
// Good: Test single responsibility
|
|
42
|
+
describe('UserService', () => {
|
|
43
|
+
describe('createUser', () => {
|
|
44
|
+
it('should create user with valid data', async () => {
|
|
45
|
+
const userData = { email: 'test@example.com', name: 'Test' };
|
|
46
|
+
const user = await userService.createUser(userData);
|
|
47
|
+
|
|
48
|
+
expect(user).toMatchObject(userData);
|
|
49
|
+
expect(user.id).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should throw error with duplicate email', async () => {
|
|
53
|
+
const userData = { email: 'existing@example.com', name: 'Test' };
|
|
54
|
+
|
|
55
|
+
await expect(userService.createUser(userData))
|
|
56
|
+
.rejects.toThrow('Email already exists');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should hash password before storing', async () => {
|
|
60
|
+
const userData = { email: 'test@example.com', password: 'plain123' };
|
|
61
|
+
const user = await userService.createUser(userData);
|
|
62
|
+
|
|
63
|
+
expect(user.password).not.toBe('plain123');
|
|
64
|
+
expect(user.password).toMatch(/^\$argon2id\$/);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Mocking
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// Mock external dependencies
|
|
74
|
+
jest.mock('./emailService');
|
|
75
|
+
|
|
76
|
+
it('should send welcome email after user creation', async () => {
|
|
77
|
+
const emailService = require('./emailService');
|
|
78
|
+
emailService.sendWelcomeEmail = jest.fn();
|
|
79
|
+
|
|
80
|
+
await userService.createUser({ email: 'test@example.com' });
|
|
81
|
+
|
|
82
|
+
expect(emailService.sendWelcomeEmail).toHaveBeenCalledWith('test@example.com');
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Integration Testing
|
|
87
|
+
|
|
88
|
+
### API Integration Tests
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import request from 'supertest';
|
|
92
|
+
import { app } from '../app';
|
|
93
|
+
|
|
94
|
+
describe('POST /api/users', () => {
|
|
95
|
+
beforeAll(async () => {
|
|
96
|
+
await db.connect(); // Real database connection (test DB)
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
afterAll(async () => {
|
|
100
|
+
await db.disconnect();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
beforeEach(async () => {
|
|
104
|
+
await db.users.deleteMany({}); // Clean state
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should create user and return 201', async () => {
|
|
108
|
+
const response = await request(app)
|
|
109
|
+
.post('/api/users')
|
|
110
|
+
.send({ email: 'test@example.com', name: 'Test User' })
|
|
111
|
+
.expect(201);
|
|
112
|
+
|
|
113
|
+
expect(response.body).toMatchObject({
|
|
114
|
+
email: 'test@example.com',
|
|
115
|
+
name: 'Test User',
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Verify database persistence
|
|
119
|
+
const user = await db.users.findOne({ email: 'test@example.com' });
|
|
120
|
+
expect(user).toBeDefined();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should return 400 for invalid email', async () => {
|
|
124
|
+
await request(app)
|
|
125
|
+
.post('/api/users')
|
|
126
|
+
.send({ email: 'invalid-email', name: 'Test' })
|
|
127
|
+
.expect(400)
|
|
128
|
+
.expect((res) => {
|
|
129
|
+
expect(res.body.error).toBe('Invalid email format');
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Database Testing with TestContainers
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { GenericContainer } from 'testcontainers';
|
|
139
|
+
|
|
140
|
+
let container;
|
|
141
|
+
let db;
|
|
142
|
+
|
|
143
|
+
beforeAll(async () => {
|
|
144
|
+
// Spin up real PostgreSQL in Docker
|
|
145
|
+
container = await new GenericContainer('postgres:15')
|
|
146
|
+
.withEnvironment({ POSTGRES_PASSWORD: 'test' })
|
|
147
|
+
.withExposedPorts(5432)
|
|
148
|
+
.start();
|
|
149
|
+
|
|
150
|
+
const port = container.getMappedPort(5432);
|
|
151
|
+
db = await createConnection({
|
|
152
|
+
host: 'localhost',
|
|
153
|
+
port,
|
|
154
|
+
database: 'test',
|
|
155
|
+
password: 'test',
|
|
156
|
+
});
|
|
157
|
+
}, 60000);
|
|
158
|
+
|
|
159
|
+
afterAll(async () => {
|
|
160
|
+
await container.stop();
|
|
161
|
+
});
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Contract Testing (Microservices)
|
|
165
|
+
|
|
166
|
+
### Pact (Consumer-Driven Contracts)
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Consumer test
|
|
170
|
+
import { Pact } from '@pact-foundation/pact';
|
|
171
|
+
|
|
172
|
+
const provider = new Pact({
|
|
173
|
+
consumer: 'UserService',
|
|
174
|
+
provider: 'AuthService',
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('Auth Service Contract', () => {
|
|
178
|
+
beforeAll(() => provider.setup());
|
|
179
|
+
afterEach(() => provider.verify());
|
|
180
|
+
afterAll(() => provider.finalize());
|
|
181
|
+
|
|
182
|
+
it('should validate user token', async () => {
|
|
183
|
+
await provider.addInteraction({
|
|
184
|
+
state: 'user token exists',
|
|
185
|
+
uponReceiving: 'a request to validate token',
|
|
186
|
+
withRequest: {
|
|
187
|
+
method: 'POST',
|
|
188
|
+
path: '/auth/validate',
|
|
189
|
+
headers: { 'Content-Type': 'application/json' },
|
|
190
|
+
body: { token: 'valid-token-123' },
|
|
191
|
+
},
|
|
192
|
+
willRespondWith: {
|
|
193
|
+
status: 200,
|
|
194
|
+
body: { valid: true, userId: '123' },
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const response = await authClient.validateToken('valid-token-123');
|
|
199
|
+
expect(response.valid).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Load Testing
|
|
205
|
+
|
|
206
|
+
### Tools Comparison
|
|
207
|
+
|
|
208
|
+
**k6** (Modern, Developer-Friendly)
|
|
209
|
+
```javascript
|
|
210
|
+
import http from 'k6/http';
|
|
211
|
+
import { check, sleep } from 'k6';
|
|
212
|
+
|
|
213
|
+
export const options = {
|
|
214
|
+
stages: [
|
|
215
|
+
{ duration: '2m', target: 100 }, // Ramp up to 100 users
|
|
216
|
+
{ duration: '5m', target: 100 }, // Stay at 100 users
|
|
217
|
+
{ duration: '2m', target: 0 }, // Ramp down to 0 users
|
|
218
|
+
],
|
|
219
|
+
thresholds: {
|
|
220
|
+
http_req_duration: ['p(95)<500'], // 95% requests under 500ms
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export default function () {
|
|
225
|
+
const res = http.get('https://api.example.com/users');
|
|
226
|
+
check(res, {
|
|
227
|
+
'status is 200': (r) => r.status === 200,
|
|
228
|
+
'response time < 500ms': (r) => r.timings.duration < 500,
|
|
229
|
+
});
|
|
230
|
+
sleep(1);
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Gatling** (JVM-based, Advanced Scenarios)
|
|
235
|
+
**JMeter** (GUI-based, Traditional)
|
|
236
|
+
|
|
237
|
+
### Performance Thresholds
|
|
238
|
+
|
|
239
|
+
- **Response time:** p95 < 500ms, p99 < 1s
|
|
240
|
+
- **Throughput:** 1000+ req/sec (target based on SLA)
|
|
241
|
+
- **Error rate:** < 1%
|
|
242
|
+
- **Concurrent users:** Test at 2x expected peak
|
|
243
|
+
|
|
244
|
+
## E2E Testing
|
|
245
|
+
|
|
246
|
+
### Playwright (Modern, Multi-Browser)
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { test, expect } from '@playwright/test';
|
|
250
|
+
|
|
251
|
+
test('user can register and login', async ({ page }) => {
|
|
252
|
+
// Navigate to registration page
|
|
253
|
+
await page.goto('https://app.example.com/register');
|
|
254
|
+
|
|
255
|
+
// Fill registration form
|
|
256
|
+
await page.fill('input[name="email"]', 'test@example.com');
|
|
257
|
+
await page.fill('input[name="password"]', 'SecurePass123!');
|
|
258
|
+
await page.click('button[type="submit"]');
|
|
259
|
+
|
|
260
|
+
// Verify redirect to dashboard
|
|
261
|
+
await expect(page).toHaveURL('/dashboard');
|
|
262
|
+
await expect(page.locator('h1')).toContainText('Welcome');
|
|
263
|
+
|
|
264
|
+
// Verify API call was made
|
|
265
|
+
const response = await page.waitForResponse('/api/users');
|
|
266
|
+
expect(response.status()).toBe(201);
|
|
267
|
+
});
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## Database Migration Testing
|
|
271
|
+
|
|
272
|
+
**Critical:** 83% migrations fail without proper testing
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
describe('Database Migrations', () => {
|
|
276
|
+
it('should migrate from v1 to v2 without data loss', async () => {
|
|
277
|
+
// Insert test data in v1 schema
|
|
278
|
+
await db.query(`
|
|
279
|
+
INSERT INTO users (id, email, name)
|
|
280
|
+
VALUES (1, 'test@example.com', 'Test User')
|
|
281
|
+
`);
|
|
282
|
+
|
|
283
|
+
// Run migration
|
|
284
|
+
await runMigration('v2-add-created-at.sql');
|
|
285
|
+
|
|
286
|
+
// Verify v2 schema
|
|
287
|
+
const result = await db.query('SELECT * FROM users WHERE id = 1');
|
|
288
|
+
expect(result.rows[0]).toMatchObject({
|
|
289
|
+
id: 1,
|
|
290
|
+
email: 'test@example.com',
|
|
291
|
+
name: 'Test User',
|
|
292
|
+
created_at: expect.any(Date),
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('should rollback migration successfully', async () => {
|
|
297
|
+
await runMigration('v2-add-created-at.sql');
|
|
298
|
+
await rollbackMigration('v2-add-created-at.sql');
|
|
299
|
+
|
|
300
|
+
// Verify v1 schema restored
|
|
301
|
+
const columns = await db.query(`
|
|
302
|
+
SELECT column_name FROM information_schema.columns
|
|
303
|
+
WHERE table_name = 'users'
|
|
304
|
+
`);
|
|
305
|
+
expect(columns.rows.map(r => r.column_name)).not.toContain('created_at');
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## Security Testing
|
|
311
|
+
|
|
312
|
+
### SAST (Static Application Security Testing)
|
|
313
|
+
|
|
314
|
+
```bash
|
|
315
|
+
# SonarQube for code quality + security
|
|
316
|
+
sonar-scanner \
|
|
317
|
+
-Dsonar.projectKey=my-backend \
|
|
318
|
+
-Dsonar.sources=src \
|
|
319
|
+
-Dsonar.host.url=http://localhost:9000
|
|
320
|
+
|
|
321
|
+
# Semgrep for security patterns
|
|
322
|
+
semgrep --config auto src/
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### DAST (Dynamic Application Security Testing)
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# OWASP ZAP for runtime security scanning
|
|
329
|
+
docker run -t owasp/zap2docker-stable zap-baseline.py \
|
|
330
|
+
-t https://api.example.com \
|
|
331
|
+
-r zap-report.html
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### Dependency Scanning (SCA)
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
# npm audit for Node.js
|
|
338
|
+
npm audit fix
|
|
339
|
+
|
|
340
|
+
# Snyk for multi-language
|
|
341
|
+
snyk test
|
|
342
|
+
snyk monitor # Continuous monitoring
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Code Coverage
|
|
346
|
+
|
|
347
|
+
### Target Metrics (SonarQube Standards)
|
|
348
|
+
|
|
349
|
+
- **Overall coverage:** 80%+
|
|
350
|
+
- **Critical paths:** 100% (authentication, payment, data integrity)
|
|
351
|
+
- **New code:** 90%+
|
|
352
|
+
|
|
353
|
+
### Implementation
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
# Vitest with coverage
|
|
357
|
+
vitest run --coverage
|
|
358
|
+
|
|
359
|
+
# Jest with coverage
|
|
360
|
+
jest --coverage --coverageThreshold='{"global":{"branches":80,"functions":80,"lines":80}}'
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## CI/CD Testing Pipeline
|
|
364
|
+
|
|
365
|
+
```yaml
|
|
366
|
+
# GitHub Actions example
|
|
367
|
+
name: Test Pipeline
|
|
368
|
+
|
|
369
|
+
on: [push, pull_request]
|
|
370
|
+
|
|
371
|
+
jobs:
|
|
372
|
+
test:
|
|
373
|
+
runs-on: ubuntu-latest
|
|
374
|
+
steps:
|
|
375
|
+
- uses: actions/checkout@v3
|
|
376
|
+
|
|
377
|
+
- name: Unit Tests
|
|
378
|
+
run: npm run test:unit
|
|
379
|
+
|
|
380
|
+
- name: Integration Tests
|
|
381
|
+
run: npm run test:integration
|
|
382
|
+
|
|
383
|
+
- name: E2E Tests
|
|
384
|
+
run: npm run test:e2e
|
|
385
|
+
|
|
386
|
+
- name: Load Tests
|
|
387
|
+
run: k6 run load-test.js
|
|
388
|
+
|
|
389
|
+
- name: Security Scan
|
|
390
|
+
run: npm audit && snyk test
|
|
391
|
+
|
|
392
|
+
- name: Coverage Report
|
|
393
|
+
run: npm run test:coverage
|
|
394
|
+
|
|
395
|
+
- name: Upload to Codecov
|
|
396
|
+
uses: codecov/codecov-action@v3
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Testing Best Practices
|
|
400
|
+
|
|
401
|
+
1. **Arrange-Act-Assert (AAA) Pattern**
|
|
402
|
+
2. **One assertion per test** (when practical)
|
|
403
|
+
3. **Descriptive test names** - `should throw error when email is invalid`
|
|
404
|
+
4. **Test edge cases** - Empty inputs, boundary values, null/undefined
|
|
405
|
+
5. **Clean test data** - Reset database state between tests
|
|
406
|
+
6. **Fast tests** - Unit tests < 10ms, Integration < 100ms
|
|
407
|
+
7. **Deterministic** - No flaky tests, avoid sleep(), use waitFor()
|
|
408
|
+
8. **Independent** - Tests don't depend on execution order
|
|
409
|
+
|
|
410
|
+
## Testing Checklist
|
|
411
|
+
|
|
412
|
+
- [ ] Unit tests cover 70% of codebase
|
|
413
|
+
- [ ] Integration tests for all API endpoints
|
|
414
|
+
- [ ] Contract tests for microservices
|
|
415
|
+
- [ ] Load tests configured (k6/Gatling)
|
|
416
|
+
- [ ] E2E tests for critical user flows
|
|
417
|
+
- [ ] Database migration tests
|
|
418
|
+
- [ ] Security scanning in CI/CD (SAST, DAST, SCA)
|
|
419
|
+
- [ ] Code coverage reports automated
|
|
420
|
+
- [ ] Tests run on every PR
|
|
421
|
+
- [ ] Flaky tests eliminated
|
|
422
|
+
|
|
423
|
+
## Resources
|
|
424
|
+
|
|
425
|
+
- **Vitest:** https://vitest.dev/
|
|
426
|
+
- **Playwright:** https://playwright.dev/
|
|
427
|
+
- **k6:** https://k6.io/docs/
|
|
428
|
+
- **Pact:** https://docs.pact.io/
|
|
429
|
+
- **TestContainers:** https://testcontainers.com/
|