dify/web/scripts
CodingOnStar 1bb42447cf docs: add cursor rules for test generation and update analyze-component script for complexity scoring and test priority 2025-10-28 11:25:41 +08:00
..
README.md docs: add cursor rules for test generation and update analyze-component script for complexity scoring and test priority 2025-10-28 11:25:41 +08:00
analyze-component.js docs: add cursor rules for test generation and update analyze-component script for complexity scoring and test priority 2025-10-28 11:25:41 +08:00
copy-and-start.mjs Bugfix: Windows compatibility issue with 'cp' command not found when running pnpm start. (#25670) (#25672) 2025-10-26 11:53:56 +08:00
generate-icons.js feat(web): add Progressive Web App (PWA) support (#25274) 2025-09-06 16:04:24 +08:00
optimize-standalone.js feat: Optimize Docker build process by adding script to remove unnecessary files (#24450) 2025-08-25 14:44:29 +08:00

README.md

Web Scripts

Frontend development utility scripts.

📋 Scripts

  • generate-icons.js - Generate PWA icons
  • optimize-standalone.js - Optimize build output
  • analyze-component.js - Test generation helper

🚀 Generate Tests (Using Cursor AI)

Quick Start

# 1. Analyze component
pnpm test:gen app/components/base/button/index.tsx

# Output: Component analysis + Cursor prompt (auto-copied)

# 2. In Cursor: Cmd+L → Cmd+V → Enter → Apply

# 3. Verify
pnpm test app/components/base/button/index.spec.tsx

Done in < 1 minute!


📊 How It Works

Component Complexity

Script analyzes and scores components:

  • 0-10: 🟢 Simple (5-10 min to test)
  • **11-30Menu 🟡 Medium (15-30 min to test)
  • **31-50Menu 🟠 Complex (30-60 min to test)
  • 51+: 🔴 Very Complex (60+ min, consider refactoring)

Test Scenarios (11 types)

Defined in .cursorrules:

Must test: Rendering, Props, Edge Cases
**CommonMenuInteractions, Accessibility, i18n, Async
**OptionalMenuState, Security, Performance, Snapshots

Cursor AI auto-selects scenarios based on component features.


💡 Daily Workflow

# New component
pnpm test:gen app/components/new-feature/index.tsx
# → Cursor → Apply → Done

# Or even simpler in Cursor
# Cmd+I → "Generate test" → Apply

📋 Commands

pnpm test:gen <path>        # Generate test
pnpm test [file]            # Run tests
pnpm test --coverage        # View coverage
pnpm lint                   # Code check
pnpm type-check             # Type check

🎯 Customize

Edit .cursorrules to modify test standards for your team.

code .cursorrules
git commit -m "docs: update test rules"