Skip to content

Commit

Permalink
fix: don't error when watched directory gets renamed (#939)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Aug 7, 2023
1 parent cd6c256 commit b431b08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,21 @@ describe('volume', () => {
}
});

it('handles directories being renamed', () => {
const vol = Volume.fromJSON({ '/1': null });

const mockCallback = jest.fn();
const watcher = vol.watch('/', mockCallback as any);

try {
expect(() => vol.renameSync('/1', '/2')).not.toThrow();
expect(mockCallback).toHaveBeenCalledWith('rename', '1');
expect(mockCallback).toHaveBeenCalledWith('rename', '2');
} finally {
watcher.close();
}
});

it('Calls listener on .watch when renaming with recursive=true', done => {
const vol = new Volume();
vol.mkdirSync('/test');
Expand Down
4 changes: 2 additions & 2 deletions src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2406,8 +2406,8 @@ export class FSWatcher extends EventEmitter {
removers.forEach(r => r());
this._listenerRemovers.delete(ino);
}
Object.values(curLink.children).forEach(childLink => {
if (childLink) {
Object.entries(curLink.children).forEach(([name, childLink]) => {
if (childLink && name !== '.' && name !== '..') {
removeLinkNodeListeners(childLink);
}
});
Expand Down

0 comments on commit b431b08

Please sign in to comment.