Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Cline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
1. Update all the packages to the latest versions
- Build the project and correct any errors until it builds cleanly
- Check the configurations to make sure they are correct for the current package versions and resolve any issues you find
- Commit the changes once every looks good

2. Implement #1 from TODO.md
- Install the necessary packages and configure them for optimal testing & ease of use
- Implement the tests and code coverage running each to ensure they work
- Build the project again to ensure everything is cool
- Commit the changes

3. Create a pull request for the changes with a complete description of what you've done and asking if there are modifications that would improve the PR
- Once that's submitted take the rest of the night off.


---

Test Fix Plan

# Test Fix Plan - COMPLETED ✓

## Issues Fixed

1. Parameter Syntax in Test Assertions ✓
- Fixed incorrect syntax for multiple parameters (added commas)
- Updated all `toHaveBeenCalledWith` assertions to use proper comma syntax
- All test assertions now pass

2. Directory Creation Not Being Called ✓
- Added explicit directory creation in syncConfigWithTemplate
- Using mkdirSync with recursive option
- Directory creation tests now pass

3. Hanging Test Suite ✓
- Problem: test.test.ts keeps running indefinitely
- Root Cause Analysis:
* Initial thought: watch mode in test environment
* Deeper issue: Potential recursive Jest execution
* utils/test.ts is a CLI tool that runs test commands
* When testing with Jest, it could cause Jest to try to run itself

- Fix Implementation:
1. Added environment detection:
```typescript
const isTestEnvironment = process.env.NODE_ENV === 'test';
```
2. Modified watch mode handling:
```typescript
if (options.watch && !isTestEnvironment) {
args.push('--watch');
}
```
3. Updated test mocks:
* Changed mock test command from 'jest' to 'mocha' to avoid recursion
* Properly mocked child_process.spawnSync
* Updated test expectations to match environment behavior
* Added comprehensive test cases for command execution

- This ensures:
* Watch mode works normally when used as a CLI tool
* Watch mode is disabled during test execution
* No recursive Jest execution in tests
* Test suite completes normally

## Final Results ✓
- All 6 test suites passing
- All 66 tests passing
- No more hanging issues
- Watch mode functionality preserved for CLI usage
- No regressions in existing functionality
- Proper separation between test environment and CLI tool behavior

## Future Considerations
1. Coverage Improvements Needed:
- Overall branch coverage: 61.36% (below 80% threshold)
- test.ts has particularly low branch coverage (36.58%)
- Could be addressed in a separate task

2. Lessons Learned:
- When testing CLI tools that run tests:
* Avoid using the same test runner in tests as the one being tested
* Mock external process execution
* Consider environment-specific behavior
- Test environment detection is crucial for preventing recursive behavior
- Proper mocking of child processes helps avoid unintended side effects
10 changes: 10 additions & 0 deletions ai-dev-workflow-cli.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"folders": [
{
"path": "."
}
],
"settings": {
"npm.packageManager": "npm"
}
}
38 changes: 38 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['**/__tests__/**/*.ts'],
testPathIgnorePatterns: ['/node_modules/', '/__integration__/'],
transform: {
'^.+\\.ts$': ['ts-jest', {
tsconfig: 'tsconfig.json',
useESM: true,
}]
},
transformIgnorePatterns: [
'node_modules/(?!(chalk|ansi-styles|supports-color)/)'
],
moduleNameMapper: {
'#(.*)': '<rootDir>/node_modules/$1',
'^chalk$': '<rootDir>/node_modules/chalk/source/index.js',
'^ansi-styles$': '<rootDir>/node_modules/ansi-styles/index.js',
'^supports-color$': '<rootDir>/node_modules/supports-color/index.js',
'^(\\.{1,2}/.*)\\.js$': '$1'
},
extensionsToTreatAsEsm: ['.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['text', 'lcov', 'clover'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
setupFiles: ['<rootDir>/jest.setup.js']
}
26 changes: 26 additions & 0 deletions jest.integration.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
testMatch: ['<rootDir>/src/__integration__/**/*.ts'],
transform: {
'^.+\\.ts$': ['ts-jest', {
tsconfig: 'tsconfig.json',
useESM: true,
}]
},
transformIgnorePatterns: [
'node_modules/(?!(chalk|ansi-styles|supports-color)/)'
],
moduleNameMapper: {
'#(.*)': '<rootDir>/node_modules/$1',
'^chalk$': '<rootDir>/node_modules/chalk/source/index.js',
'^ansi-styles$': '<rootDir>/node_modules/ansi-styles/index.js',
'^supports-color$': '<rootDir>/node_modules/supports-color/index.js',
'^(\\.{1,2}/.*)\\.js$': '$1'
},
extensionsToTreatAsEsm: ['.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
setupFiles: ['<rootDir>/jest.setup.js']
}
46 changes: 46 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Mock chalk for all tests
const mockChalk = {
yellow: jest.fn((str) => `[yellow]${str}[/yellow]`),
green: jest.fn((str) => `[green]${str}[/green]`),
red: jest.fn((str) => `[red]${str}[/red]`),
gray: jest.fn((str) => `[gray]${str}[/gray]`),
blue: jest.fn((str) => `[blue]${str}[/blue]`),
cyan: jest.fn((str) => `[cyan]${str}[/cyan]`),
magenta: jest.fn((str) => `[magenta]${str}[/magenta]`),
default: {
yellow: jest.fn((str) => `[yellow]${str}[/yellow]`),
green: jest.fn((str) => `[green]${str}[/green]`),
red: jest.fn((str) => `[red]${str}[/red]`),
gray: jest.fn((str) => `[gray]${str}[/gray]`),
blue: jest.fn((str) => `[blue]${str}[/blue]`),
cyan: jest.fn((str) => `[cyan]${str}[/cyan]`),
magenta: jest.fn((str) => `[magenta]${str}[/magenta]`)
}
};

// Mock inquirer for CLI tests
const mockInquirer = {
prompt: jest.fn().mockResolvedValue({ confirm: true })
};

// Mock console methods to prevent noise in test output
const mockConsole = {
log: jest.fn(),
error: jest.fn(),
warn: jest.fn(),
info: jest.fn()
};

// Setup mocks
jest.mock('chalk', () => mockChalk);
jest.mock('inquirer', () => mockInquirer);
global.console = { ...console, ...mockConsole };

// Export mocks for test files
module.exports = {
mocks: {
chalk: mockChalk,
inquirer: mockInquirer,
console: mockConsole
}
};
Loading