Add new skills for backend patterns, coding standards, continuous learning, and NestJS best practices

- Introduced backend patterns skill with guidelines on API design, database optimization, and server-side best practices.
- Added coding standards skill outlining universal coding principles for TypeScript, NestJS, and Node.js development.
- Implemented continuous learning skill to automatically extract reusable patterns from Cursor sessions.
- Created NestJS best practices skill detailing architecture patterns, dependency injection, error handling, and security measures.
- Included various rules and templates for NestJS best practices to ensure production-ready applications.
This commit is contained in:
shancheas
2026-08-20 18:30:39 +07:00
commit 0b0bdd9c4b
108 changed files with 16056 additions and 0 deletions
+355
View File
@@ -0,0 +1,355 @@
---
description: Generate and run NestJS E2E tests with Supertest. Creates HTTP journey tests in test/*.e2e-spec.ts and runs them via jest-e2e.
---
# E2E Command
This command invokes the **e2e-runner** agent to generate, maintain, and execute NestJS E2E tests using Supertest.
## What This Command Does
1. **Generate Test Journeys** - Create HTTP E2E tests for API flows
2. **Run E2E Tests** - Execute `npm run test:e2e`
3. **Isolate Dependencies** - Mock Drizzle and external services
4. **Identify Flaky Tests** - Quarantine unstable tests
5. **Report Failures** - Jest output and coverage
## When to Use
Use `/e2e` when:
- Testing critical user journeys (login, trading, payments)
- Verifying multi-step flows work end-to-end
- Testing UI interactions and navigation
- Validating integration between frontend and backend
- Preparing for production deployment
## How It Works
The e2e-runner agent will:
1. **Analyze API flow** and identify test scenarios
2. **Generate Supertest E2E test** in `test/*.e2e-spec.ts`
3. **Run tests** with `npm run test:e2e`
4. **Capture failures** from Jest output
5. **Generate report** with results
6. **Identify flaky tests** and recommend fixes
## Example Usage
```
User: /e2e Test the market search and view flow
Agent (e2e-runner):
# E2E Test Generation: Market Search and View Flow
## Test Scenario Identified
**User Journey:** Market Search β†’ View Results β†’ Click Market β†’ View Details
**Test Coverage:**
1. Navigate to markets page
2. Perform semantic search
3. Verify search results
4. Click on first result
5. Verify market details page loads
6. Verify chart renders
## Generated Test Code
```typescript
// tests/e2e/markets/search-and-view.spec.ts
import { test, expect } from '@playwright/test'
import { MarketsPage } from '../../pages/MarketsPage'
import { MarketDetailsPage } from '../../pages/MarketDetailsPage'
test.describe('Market Search and View Flow', () => {
test('user can search markets and view details', async ({ page }) => {
// 1. Navigate to markets page
const marketsPage = new MarketsPage(page)
await marketsPage.goto()
// Verify page loaded
await expect(page).toHaveTitle(/Markets/)
await expect(page.locator('h1')).toContainText('Markets')
// 2. Perform semantic search
await marketsPage.searchMarkets('election')
// Wait for API response
await page.waitForResponse(resp =>
resp.url().includes('/api/markets/search') && resp.status() === 200
)
// 3. Verify search results
const marketCards = marketsPage.marketCards
await expect(marketCards.first()).toBeVisible()
const resultCount = await marketCards.count()
expect(resultCount).toBeGreaterThan(0)
// Take screenshot of search results
await page.screenshot({ path: 'artifacts/search-results.png' })
// 4. Click on first result
const firstMarketTitle = await marketCards.first().textContent()
await marketCards.first().click()
// 5. Verify market details page loads
await expect(page).toHaveURL(/\/markets\/[a-z0-9-]+/)
const detailsPage = new MarketDetailsPage(page)
await expect(detailsPage.marketName).toBeVisible()
await expect(detailsPage.marketDescription).toBeVisible()
// 6. Verify chart renders
await expect(detailsPage.priceChart).toBeVisible()
// Verify market name matches
const detailsTitle = await detailsPage.marketName.textContent()
expect(detailsTitle?.toLowerCase()).toContain(
firstMarketTitle?.toLowerCase().substring(0, 20) || ''
)
// Take screenshot of market details
await page.screenshot({ path: 'artifacts/market-details.png' })
})
test('search with no results shows empty state', async ({ page }) => {
const marketsPage = new MarketsPage(page)
await marketsPage.goto()
// Search for non-existent market
await marketsPage.searchMarkets('xyznonexistentmarket123456')
// Verify empty state
await expect(page.locator('[data-testid="no-results"]')).toBeVisible()
await expect(page.locator('[data-testid="no-results"]')).toContainText(
/no.*results|no.*markets/i
)
const marketCount = await marketsPage.marketCards.count()
expect(marketCount).toBe(0)
})
test('can clear search and see all markets again', async ({ page }) => {
const marketsPage = new MarketsPage(page)
await marketsPage.goto()
// Initial market count
const initialCount = await marketsPage.marketCards.count()
// Perform search
await marketsPage.searchMarkets('trump')
await page.waitForLoadState('networkidle')
// Verify filtered results
const filteredCount = await marketsPage.marketCards.count()
expect(filteredCount).toBeLessThan(initialCount)
// Clear search
await marketsPage.searchInput.clear()
await page.waitForLoadState('networkidle')
// Verify all markets shown again
const finalCount = await marketsPage.marketCards.count()
expect(finalCount).toBe(initialCount)
})
})
```
## Running Tests
```bash
# Run the generated test
npx playwright test tests/e2e/markets/search-and-view.spec.ts
Running 3 tests using 3 workers
βœ“ [chromium] β€Ί search-and-view.spec.ts:5:3 β€Ί user can search markets and view details (4.2s)
βœ“ [chromium] β€Ί search-and-view.spec.ts:52:3 β€Ί search with no results shows empty state (1.8s)
βœ“ [chromium] β€Ί search-and-view.spec.ts:67:3 β€Ί can clear search and see all markets again (2.9s)
3 passed (9.1s)
Artifacts generated:
- artifacts/search-results.png
- artifacts/market-details.png
- playwright-report/index.html
```
## Test Report
```
╔══════════════════════════════════════════════════════════════╗
β•‘ E2E Test Results β•‘
╠══════════════════════════════════════════════════════════════╣
β•‘ Status: βœ… ALL TESTS PASSED β•‘
β•‘ Total: 3 tests β•‘
β•‘ Passed: 3 (100%) β•‘
β•‘ Failed: 0 β•‘
β•‘ Flaky: 0 β•‘
β•‘ Duration: 9.1s β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
Artifacts:
πŸ“Έ Screenshots: 2 files
πŸ“Ή Videos: 0 files (only on failure)
πŸ” Traces: 0 files (only on failure)
πŸ“Š HTML Report: playwright-report/index.html
View report: npx playwright show-report
```
βœ… E2E test suite ready for CI/CD integration!
```
## Test Artifacts
When tests run, the following artifacts are captured:
**On All Tests:**
- HTML Report with timeline and results
- JUnit XML for CI integration
**On Failure Only:**
- Screenshot of the failing state
- Video recording of the test
- Trace file for debugging (step-by-step replay)
- Network logs
- Console logs
## Viewing Artifacts
```bash
# View HTML report in browser
npx playwright show-report
# View specific trace file
npx playwright show-trace artifacts/trace-abc123.zip
# Screenshots are saved in artifacts/ directory
open artifacts/search-results.png
```
## Flaky Test Detection
If a test fails intermittently:
```
⚠️ FLAKY TEST DETECTED: tests/e2e/markets/trade.spec.ts
Test passed 7/10 runs (70% pass rate)
Common failure:
"Timeout waiting for element '[data-testid="confirm-btn"]'"
Recommended fixes:
1. Add explicit wait: await page.waitForSelector('[data-testid="confirm-btn"]')
2. Increase timeout: { timeout: 10000 }
3. Check for race conditions in component
4. Verify element is not hidden by animation
Quarantine recommendation: Mark as test.fixme() until fixed
```
## Browser Configuration
Tests run on multiple browsers by default:
- βœ… Chromium (Desktop Chrome)
- βœ… Firefox (Desktop)
- βœ… WebKit (Desktop Safari)
- βœ… Mobile Chrome (optional)
Configure in `playwright.config.ts` to adjust browsers.
## CI/CD Integration
Add to your CI pipeline:
```yaml
# .github/workflows/e2e.yml
- name: Run E2E tests
run: npm run test:e2e
```
- name: Upload artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: playwright-report/
```
## PMX-Specific Critical Flows
For PMX, prioritize these E2E tests:
**πŸ”΄ CRITICAL (Must Always Pass):**
1. User can connect wallet
2. User can browse markets
3. User can search markets (semantic search)
4. User can view market details
5. User can place trade (with test funds)
6. Market resolves correctly
7. User can withdraw funds
**🟑 IMPORTANT:**
1. Market creation flow
2. User profile updates
3. Real-time price updates
4. Chart rendering
5. Filter and sort markets
6. Mobile responsive layout
## Best Practices
**DO:**
- βœ… Use Page Object Model for maintainability
- βœ… Use data-testid attributes for selectors
- βœ… Wait for API responses, not arbitrary timeouts
- βœ… Test critical user journeys end-to-end
- βœ… Run tests before merging to main
- βœ… Review artifacts when tests fail
**DON'T:**
- ❌ Use brittle selectors (CSS classes can change)
- ❌ Test implementation details
- ❌ Run tests against production
- ❌ Ignore flaky tests
- ❌ Skip artifact review on failures
- ❌ Test every edge case with E2E (use unit tests)
## Important Notes
**CRITICAL for PMX:**
- E2E tests involving real money MUST run on testnet/staging only
- Never run trading tests against production
- Set `test.skip(process.env.NODE_ENV === 'production')` for financial tests
- Use test wallets with small test funds only
## Integration with Other Commands
- Use `/plan` to identify critical journeys to test
- Use `/tdd` for unit tests (faster, more granular)
- Use `/e2e` for integration and user journey tests
- Use `/code-review` to verify test quality
## Related Agents
This command invokes the `e2e-runner` agent located at:
`.cursor/agents/e2e-runner.md`
And can reference the NestJS E2E skill at:
`.agents/skills/nestjs-best-practices/rules/test-e2e-supertest.md`
## Quick Commands
```bash
# Run all E2E tests
npm run test:e2e
# Run a specific E2E file
npx jest --config ./test/jest-e2e.json test/auth.e2e-spec.ts
# Watch mode during development
npx jest --config ./test/jest-e2e.json --watch
```