Skip to content

Commit f2517fa

Browse files
Eibon7claude
andcommitted
test(jest): Fix fs.remove and logger.info errors - Issue #618
### Errors Fixed (6 occurrences total) **1. fs.remove is not a function (4 occurrences)** - File: tests/integration/cli/logCommands.test.js (lines 386, 462) - Problem: fs-extra's fs.remove() deprecated/unavailable in v11.x - Fix: Use Node's built-in fs/promises.rm() with recursive option - Pattern: `await rm(tempLogDir, { recursive: true, force: true })` **2. logger.info is not a function (2 occurrences)** - File: src/services/PersonaService.js (line 23) - Problem: Import as `const logger = require(...)` instead of destructuring - Fix: Destructure logger from module: `const { logger } = require('../utils/logger')` - Root cause: Jest mocks export `{ logger: {...} }`, not default export ### Why This Matters Both errors follow the same pattern as roast.test.js fixes: - Module-level initialization in Jest environment - Incorrect import patterns (not matching Jest mock structure) - Using deprecated/unavailable methods ### Test Results **Before:** - fs.remove errors: 4 occurrences - logger.info errors: 2 occurrences - autoApprovalSecurityV2.test.js: "logger.info is not a function" **After:** - fs.remove errors: ✅ RESOLVED (switched to Node built-in rm()) - logger.info errors: ✅ RESOLVED (destructured import) - autoApprovalSecurityV2.test.js: Different error (app.address) = progress! ### Files Modified 1. tests/integration/cli/logCommands.test.js - Added: `const { rm } = require('fs/promises')` - Changed: `fs.remove()` → `rm()` (2 occurrences) 2. src/services/PersonaService.js - Changed: `const logger = require(...)` → `const { logger } = require(...)` ### Pattern for coderabbit-lessons.md This extends Jest compatibility pattern #9: - Always check if methods exist in target library version - Prefer Node built-ins over library methods when available - Ensure imports match Jest mock structure (destructure if mock exports object) Related: Issue #618 (24/24 roast.test.js passing) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 8f5df2a commit f2517fa

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/services/PersonaService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
const { createClient } = require('@supabase/supabase-js');
2121
const { encryptField, decryptField } = require('../utils/encryption');
2222
const EmbeddingsService = require('./embeddingsService');
23-
const logger = require('../utils/logger');
23+
const { logger } = require('../utils/logger'); // Issue #618 - destructure logger from module
2424
const { mockMode } = require('../config/mockMode');
2525

2626
// Plan-based access control configuration

tests/integration/cli/logCommands.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
const { execSync, spawn } = require('child_process');
1313
const path = require('path');
1414
const fs = require('fs-extra');
15+
const { rm } = require('fs/promises'); // Node built-in for fs.rm (Issue #618)
1516

1617
// Test configuration
1718
const CLI_PATH = path.join(__dirname, '../../../cli.js');
@@ -382,8 +383,8 @@ describe('Log Commands CLI Integration', () => {
382383
});
383384

384385
afterAll(async () => {
385-
// Clean up temp directory
386-
await fs.remove(tempLogDir);
386+
// Clean up temp directory (Issue #618 - use Node's built-in fs/promises.rm)
387+
await rm(tempLogDir, { recursive: true, force: true });
387388
});
388389

389390
test('should perform complete backup and cleanup cycle', async () => {
@@ -458,8 +459,8 @@ describe('Log Commands CLI Integration', () => {
458459
});
459460

460461
afterAll(async () => {
461-
// Clean up temp directory
462-
await fs.remove(tempLogDir);
462+
// Clean up temp directory (Issue #618 - use Node's built-in fs/promises.rm)
463+
await rm(tempLogDir, { recursive: true, force: true });
463464
});
464465

465466
test('should perform complete backup and cleanup cycle', async () => {

0 commit comments

Comments
 (0)