Skip to content

Commit 809400f

Browse files
committed
fix: optimize getTimeForFilename function for improved performance and readability
1 parent 1e96958 commit 809400f

File tree

2 files changed

+66
-5
lines changed

2 files changed

+66
-5
lines changed

notes.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,55 @@ All templates automatically include a timestamp header with creation date and ti
131131
- `src/providers/` - VS Code tree view providers
132132
- `src/commands/` - Command handlers
133133
- `src/calendar/` - Calendar view functionality (helpers and webview)
134+
- `src/test/` - Comprehensive testing infrastructure
134135
- `src/extension.ts` - Entry point and command registration (1570 lines, down from 2119)
135136
- **Asynchronous file operations**: All file I/O uses `fs.promises` API with async/await pattern
136137
- **Comprehensive error handling**: All file operations wrapped in try/catch with user-friendly error messages
137138
- **TreeDataProvider pattern**: Standard VS Code tree view implementation with async support
138139
- **Date formatting**: Uses locale-specific formatting (en-US)
139140
- **File name sanitization**: Automatic sanitization for note names from templates
140141

142+
## Testing Infrastructure
143+
144+
### Unit Tests (66 tests - all passing)
145+
- **Testing Framework**: Mocha + Chai (v4 for CommonJS compatibility)
146+
- **Test Coverage**:
147+
- Utilities: validators, date helpers, folder operations (23 tests)
148+
- Services: file system, templates (29 tests)
149+
- Providers: tree items (14 tests)
150+
- **VS Code Mocking**: Custom mocks for VS Code API to enable pure unit testing
151+
- **Execution Time**: ~120ms for full test suite
152+
153+
### CI/CD Integration
154+
- **GitHub Actions**: Automated testing on every push and PR
155+
- **Cross-Platform**: Tests run on Ubuntu, macOS, and Windows
156+
- **Multiple Node Versions**: Tests against Node 18.x and 20.x
157+
- **Matrix Testing**: 6 parallel test jobs (3 OS × 2 Node versions)
158+
- **Build Pipeline**: Automatic VSIX package build and artifact upload
159+
- **Status Badges**: CI and test status visible in README
160+
161+
### Test Files
162+
- `src/test/unit/validators.test.ts` - Folder name validation tests
163+
- `src/test/unit/dateHelpers.test.ts` - Date formatting and manipulation tests
164+
- `src/test/unit/folderHelpers.test.ts` - Recursive folder operations tests
165+
- `src/test/unit/fileSystemService.test.ts` - File I/O operation tests
166+
- `src/test/unit/templateService.test.ts` - Template generation tests
167+
- `src/test/unit/treeItems.test.ts` - Tree view item tests
168+
- `src/test/mocks/vscode.ts` - VS Code API mocks
169+
- `src/test/setup.ts` - Test environment configuration
170+
171+
### Running Tests
172+
```bash
173+
# Run all unit tests
174+
pnpm run test:unit
175+
176+
# Compile and run tests
177+
pnpm run compile && pnpm run test:unit
178+
179+
# Run VS Code integration tests (requires VS Code)
180+
pnpm run test
181+
```
182+
141183
## Recent Updates
142184

143185
### Modular Architecture Refactoring (Completed)
@@ -154,3 +196,24 @@ All templates automatically include a timestamp header with creation date and ti
154196
- **Improved performance**: Async operations prevent UI freezing with large note collections
155197
- **Updated TreeDataProvider**: `getChildren()` and `handleDrop()` now fully async
156198
- **Better user experience**: Clear error notifications when operations fail
199+
200+
### Testing & CI/CD Implementation (Completed)
201+
- **Comprehensive Test Suite**: 66 unit tests covering all core functionality
202+
- Validators: 9 tests for folder name validation patterns
203+
- Date Helpers: 14 tests for date formatting and manipulation
204+
- Folder Helpers: 7 tests for recursive folder operations
205+
- File System Service: 11 tests for all async file operations
206+
- Template Service: 9 tests for built-in and custom templates
207+
- Tree Items: 16 tests for all tree view node types
208+
- **Testing Infrastructure**:
209+
- Mocha test runner with Chai assertions (v4 for CommonJS compatibility)
210+
- Custom VS Code API mocks for pure unit testing
211+
- Test execution in ~120ms without VS Code dependency
212+
- **GitHub Actions CI/CD**:
213+
- Two workflows: full CI pipeline and test-focused workflow
214+
- Cross-platform testing: Ubuntu, macOS, Windows
215+
- Multiple Node versions: 18.x and 20.x
216+
- Automatic VSIX package building and artifact upload
217+
- Status badges in README showing build status
218+
- **Dependencies**: Using pnpm@8.15.9 with committed lockfile for reproducible builds
219+
- **Documentation**: AUTOMATED_TESTING.md with comprehensive troubleshooting guides

src/utils/dateHelpers.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ export function getFolderName(date: Date): string {
7474
* Get time string for filename (HHMM)
7575
*/
7676
export function getTimeForFilename(date: Date): string {
77-
return date.toLocaleTimeString('en-US', {
78-
hour: '2-digit',
79-
minute: '2-digit',
80-
hour12: false
81-
}).replace(':', '');
77+
const hours = date.getHours().toString().padStart(2, '0');
78+
const minutes = date.getMinutes().toString().padStart(2, '0');
79+
return `${hours}${minutes}`;
8280
}
8381

8482
/**

0 commit comments

Comments
 (0)