From 208f54002f6a083fa938969dbfe49bcafa3e8bf1 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Wed, 19 Aug 2015 16:11:50 -0700 Subject: [PATCH] [react-packager] Make the fs mock async --- react-packager/src/__mocks__/fs.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/react-packager/src/__mocks__/fs.js b/react-packager/src/__mocks__/fs.js index b5251a44..ced46a98 100644 --- a/react-packager/src/__mocks__/fs.js +++ b/react-packager/src/__mocks__/fs.js @@ -10,7 +10,14 @@ var fs = jest.genMockFromModule('fs'); +function asyncCallback(callback) { + return function() { + setImmediate(() => callback.apply(this, arguments)); + }; +} + fs.realpath.mockImpl(function(filepath, callback) { + callback = asyncCallback(callback); var node; try { node = getToNode(filepath); @@ -24,6 +31,7 @@ fs.realpath.mockImpl(function(filepath, callback) { }); fs.readdir.mockImpl(function(filepath, callback) { + callback = asyncCallback(callback); var node; try { node = getToNode(filepath); @@ -42,6 +50,7 @@ fs.readdir.mockImpl(function(filepath, callback) { }); fs.readFile.mockImpl(function(filepath, encoding, callback) { + callback = asyncCallback(callback); if (arguments.length === 2) { callback = encoding; encoding = null; @@ -60,6 +69,7 @@ fs.readFile.mockImpl(function(filepath, encoding, callback) { }); fs.stat.mockImpl(function(filepath, callback) { + callback = asyncCallback(callback); var node; try { node = getToNode(filepath);