diff --git a/packages/metro-memory-fs/src/__tests__/index-test.js b/packages/metro-memory-fs/src/__tests__/index-test.js index 18726841..be0a038b 100644 --- a/packages/metro-memory-fs/src/__tests__/index-test.js +++ b/packages/metro-memory-fs/src/__tests__/index-test.js @@ -11,6 +11,8 @@ 'use strict'; +jest.useRealTimers(); + const MemoryFs = require('../index'); let fs; diff --git a/packages/metro-memory-fs/src/index.js b/packages/metro-memory-fs/src/index.js index 104b47b2..939d890d 100644 --- a/packages/metro-memory-fs/src/index.js +++ b/packages/metro-memory-fs/src/index.js @@ -497,20 +497,16 @@ class MemoryFs { } callback(); }, - final: callback => { - try { - if (autoClose !== false) { - this.closeSync(ffd); - rst.emit('close'); - } - } catch (error) { - callback(error); - return; - } - callback(); - }, }); st = rst; + if (autoClose !== false) { + const doClose = () => { + this.closeSync(ffd); + rst.emit('close'); + }; + rst.on('finish', doClose); + rst.on('error', doClose); + } (st: any).path = filePath; (st: any).bytesWritten = 0; return st;