Skip to content

Commit ce750e4

Browse files
committed
fixes to tests for win
1 parent 4265b59 commit ce750e4

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/reader-watch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export function createReaderWatch(filePath, { signal } = {}) {
1919
const watcher = fs.watch(
2020
dir,
2121
{ signal, persistent: false },
22-
(_, filename) => {
22+
async (_, filename) => {
2323
console.log(`File change '${_}' detected: ${filename}`)
2424
// If filename is null (which can happen on some platforms), or if the
2525
// changed file is the one we're watching, then we re-create the reader
2626
if (filename && filename !== path.basename(filePath)) return
2727
signal?.removeEventListener('abort', readerClose)
28-
readerClose()
28+
await readerClose()
2929
;({ reader, readerClose } = initializeReader())
3030
},
3131
)

test/reader-watch.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ test('createReaderWatch - file is deleted', async (t) => {
105105
)
106106

107107
// Delete the file
108-
fs.unlinkSync(targetPath)
108+
fs.rmSync(targetPath, { force: true, maxRetries: 5 })
109109
await syncDir(dir)
110110

111111
const reader2 = getReader()
@@ -307,5 +307,9 @@ async function syncDir(dirPath) {
307307

308308
/** @param {string} dirPath */
309309
async function rmDir(dirPath) {
310+
if (isWin) {
311+
// On Windows, sometimes immediate removal fails due to file locks
312+
await setTimeout(200)
313+
}
310314
await fs.promises.rm(dirPath, { recursive: true, force: true, maxRetries: 5 })
311315
}

0 commit comments

Comments
 (0)