metro-memory-fs: Do not report a file change when reading a file

Reviewed By: jeanlauliac

Differential Revision: D7584517

fbshipit-source-id: 55f87d15c723f697ea00c357da1d36f5d31accbb
This commit is contained in:
Rafael Oleza 2018-04-11 09:41:32 -07:00 committed by Facebook Github Bot
parent bd5d776a2f
commit d0fdca73cd
2 changed files with 12 additions and 1 deletions

View File

@ -429,6 +429,15 @@ describe('watch', () => {
watcher.close();
});
it('does not report changes when just reading a file', () => {
const changedPaths = [];
fs.writeFileSync('/foo.txt', '');
const watcher = collectWatchEvents('/', {}, changedPaths);
fs.readFileSync('/foo.txt');
expect(changedPaths).toEqual([]);
watcher.close();
});
function collectWatchEvents(entPath, options, events) {
return fs.watch(entPath, options, (eventName, filePath) => {
events.push([eventName, filePath]);

View File

@ -197,7 +197,9 @@ class MemoryFs {
closeSync = (fd: number): void => {
const desc = this._getDesc(fd);
if (desc.writable) {
this._emitFileChange(desc.nodePath.slice(), {eventType: 'change'});
}
this._fds.delete(fd);
};