Skip to content

Commit 155444f

Browse files
committed
docs: add guidance for Windows-compatible directory cleanup in tests
1 parent 9dbe9db commit 155444f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

CLAUDE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,25 @@ The anti-pattern is using timeouts to "fix" async cleanup issues.
345345

346346
**Current Status**: The BackupJob implementation correctly uses `Napi::AsyncProgressWorker`, which is the proper Node.js async pattern. This ensures threads are properly managed and cleaned up.
347347

348+
## Windows-Compatible Directory Cleanup
349+
350+
**IMPORTANT**: Never use `fs.rmSync()` or `fs.rm()` without proper Windows retry logic for directory cleanup in tests.
351+
352+
**Problem**: On Windows, SQLite database files can remain locked longer than on Unix systems, causing `EBUSY` errors during cleanup.
353+
354+
**Proper Solution**: Use `fsp.rm()` (async) with retry options:
355+
356+
```typescript
357+
await fsp.rm(tempDir, {
358+
recursive: true,
359+
force: true,
360+
maxRetries: process.platform === "win32" ? 3 : 1,
361+
retryDelay: process.platform === "win32" ? 100 : 0,
362+
});
363+
```
364+
365+
**Best Practice**: Use the existing test utilities (`useTempDir`, `useTempDirSuite`) which already handle Windows-compatible cleanup. Don't manually clean up temp directories - let the test framework handle it.
366+
348367
## References
349368

350369
- [Node.js SQLite Documentation](https://nodejs.org/api/sqlite.html)

0 commit comments

Comments
 (0)