Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: add promise support to linux watcher
- Loading branch information
Showing
3 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const { randomUUID } = require('crypto'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs/promises'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
const testDir = tmpdir.path; | ||
tmpdir.refresh(); | ||
|
||
(async () => { | ||
{ | ||
// Add a file to already watching folder | ||
|
||
const testsubdir = await fs.mkdtemp(testDir + path.sep); | ||
const file = `${randomUUID()}.txt`; | ||
const filePath = path.join(testsubdir, file); | ||
const watcher = fs.watch(testsubdir, { recursive: true }); | ||
|
||
setTimeout(async () => { | ||
await fs.writeFile(filePath, 'world'); | ||
}, 100); | ||
|
||
for await (const payload of watcher) { | ||
const { eventType, filename } = payload; | ||
|
||
assert.ok(eventType === 'change' || eventType === 'rename'); | ||
|
||
if (filename === file) { | ||
break; | ||
} | ||
} | ||
} | ||
})().then(common.mustCall()); |