diff --git a/packages/metro-memory-fs/src/__tests__/index-test.js b/packages/metro-memory-fs/src/__tests__/index-test.js index 3781ff1f..6542d292 100644 --- a/packages/metro-memory-fs/src/__tests__/index-test.js +++ b/packages/metro-memory-fs/src/__tests__/index-test.js @@ -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]); diff --git a/packages/metro-memory-fs/src/index.js b/packages/metro-memory-fs/src/index.js index 3d7a5e2e..1497050e 100644 --- a/packages/metro-memory-fs/src/index.js +++ b/packages/metro-memory-fs/src/index.js @@ -197,7 +197,9 @@ class MemoryFs { closeSync = (fd: number): void => { const desc = this._getDesc(fd); - this._emitFileChange(desc.nodePath.slice(), {eventType: 'change'}); + if (desc.writable) { + this._emitFileChange(desc.nodePath.slice(), {eventType: 'change'}); + } this._fds.delete(fd); };