Skip to content

Commit a544cd2

Browse files
committed
fix(test): add delay before cleanup on Windows to release file handles
Windows can hold file handles briefly after file operations complete, causing EPERM errors when trying to delete the temp directory in afterEach. - Add 100ms delay on Windows using node:timers/promises - Ensures file handles are fully released before cleanup - Fixes: EPERM: operation not permitted, rmdir in json.test.ts
1 parent 7cd5124 commit a544cd2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/unit/json.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import { mkdtemp, readFile, writeFile } from 'node:fs/promises'
1717
import { tmpdir } from 'node:os'
1818
import { join } from 'node:path'
19+
import { setTimeout as sleep } from 'node:timers/promises'
1920

2021
import { safeDelete } from '@socketsecurity/lib/fs'
2122
import { getEditableJsonClass } from '@socketsecurity/lib/json/edit'
@@ -766,6 +767,11 @@ describe('json', () => {
766767

767768
afterEach(async () => {
768769
if (testDir) {
770+
// On Windows, add a small delay to ensure file handles are released
771+
// before attempting to delete the temp directory
772+
if (process.platform === 'win32') {
773+
await sleep(100)
774+
}
769775
await safeDelete(testDir)
770776
}
771777
})

0 commit comments

Comments
 (0)