fix: improve testing and CLI command implementation

- Fix tests using ES Module best practices instead of complex mocking
  - Replace Commander.js mocking with direct action handler testing
  - Resolve ES Module import/mock issues and function redeclaration errors
  - Fix circular reference issues with console.log spies
  - Properly setup mock functions with jest.fn() for method access

- Improve parse-prd command functionality
  - Add default PRD path support (scripts/prd.txt) so you can just run `task-master parse-prd` and it will use the default PRD if it exists.
  - Improve error handling and user feedback
  - Enhance help text with more detailed information

- Fix detectCamelCaseFlags implementation in utils.js yet again with more tests this time
  - Improve regex pattern to correctly detect camelCase flags
  - Skip flags already in kebab-case format
  - Enhance tests with proper test-specific implementations

- Document testing best practices
  - Add comprehensive "Common Testing Pitfalls and Solutions" section to tests.mdc
  - Provide clear examples of correct testing patterns for ES modules
  - Document techniques for test isolation and mock organization
This commit is contained in:
Eyal Toledano
2025-03-26 15:07:31 -04:00
parent 4403975604
commit c75e518380
8 changed files with 564 additions and 208 deletions

View File

@@ -300,9 +300,14 @@ function detectCamelCaseFlags(args) {
for (const arg of args) {
if (arg.startsWith('--')) {
const flagName = arg.split('=')[0].slice(2); // Remove -- and anything after =
// Only test for uppercase letters in the flag name
if (/[A-Z]/.test(flagName)) {
// Prevent adding duplicate flags or cases where kebab would be same as original
// Skip if it's a single word (no hyphens) or already in kebab-case
if (!flagName.includes('-')) {
continue;
}
// Check for camelCase pattern (lowercase followed by uppercase)
if (/[a-z][A-Z]/.test(flagName)) {
const kebabVersion = toKebabCase(flagName);
if (kebabVersion !== flagName) {
camelCaseFlags.push({