mirror of
https://github.com/status-im/metro.git
synced 2025-01-13 12:35:57 +00:00
metro-memory-fs: Allow to also listen directly to files
Reviewed By: jeanlauliac Differential Revision: D7584516 fbshipit-source-id: 4362b148a59f11b7cc1ccb27e4c1a9ebf042e52c
This commit is contained in:
parent
76a9a21369
commit
bd5d776a2f
@ -420,6 +420,15 @@ describe('watch', () => {
|
||||
watcher.close();
|
||||
});
|
||||
|
||||
it('reports changed files when watching a file directly', () => {
|
||||
const changedPaths = [];
|
||||
fs.writeFileSync('/foo.txt', '');
|
||||
const watcher = collectWatchEvents('/foo.txt', {}, changedPaths);
|
||||
fs.writeFileSync('/foo.txt', 'test');
|
||||
expect(changedPaths).toEqual([['change', 'foo.txt']]);
|
||||
watcher.close();
|
||||
});
|
||||
|
||||
function collectWatchEvents(entPath, options, events) {
|
||||
return fs.watch(entPath, options, (eventName, filePath) => {
|
||||
events.push([eventName, filePath]);
|
||||
|
@ -791,9 +791,14 @@ class MemoryFs {
|
||||
nodePath: Array<[string, EntityNode]>,
|
||||
options: {eventType: 'rename' | 'change'},
|
||||
): void {
|
||||
const node = nodePath.pop();
|
||||
let filePath = node[0];
|
||||
const fileNode = nodePath.pop();
|
||||
let filePath = fileNode[0];
|
||||
let recursive = false;
|
||||
|
||||
for (const watcher of fileNode[1].watchers) {
|
||||
watcher.listener(options.eventType, filePath);
|
||||
}
|
||||
|
||||
while (nodePath.length > 0) {
|
||||
const dirNode = nodePath.pop();
|
||||
for (const watcher of dirNode[1].watchers) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user