[react-packager] Make the fs mock async

This commit is contained in:
Amjad Masad 2015-08-19 16:11:50 -07:00
parent 866df6d37c
commit 208f54002f
1 changed files with 10 additions and 0 deletions

View File

@ -10,7 +10,14 @@
var fs = jest.genMockFromModule('fs'); var fs = jest.genMockFromModule('fs');
function asyncCallback(callback) {
return function() {
setImmediate(() => callback.apply(this, arguments));
};
}
fs.realpath.mockImpl(function(filepath, callback) { fs.realpath.mockImpl(function(filepath, callback) {
callback = asyncCallback(callback);
var node; var node;
try { try {
node = getToNode(filepath); node = getToNode(filepath);
@ -24,6 +31,7 @@ fs.realpath.mockImpl(function(filepath, callback) {
}); });
fs.readdir.mockImpl(function(filepath, callback) { fs.readdir.mockImpl(function(filepath, callback) {
callback = asyncCallback(callback);
var node; var node;
try { try {
node = getToNode(filepath); node = getToNode(filepath);
@ -42,6 +50,7 @@ fs.readdir.mockImpl(function(filepath, callback) {
}); });
fs.readFile.mockImpl(function(filepath, encoding, callback) { fs.readFile.mockImpl(function(filepath, encoding, callback) {
callback = asyncCallback(callback);
if (arguments.length === 2) { if (arguments.length === 2) {
callback = encoding; callback = encoding;
encoding = null; encoding = null;
@ -60,6 +69,7 @@ fs.readFile.mockImpl(function(filepath, encoding, callback) {
}); });
fs.stat.mockImpl(function(filepath, callback) { fs.stat.mockImpl(function(filepath, callback) {
callback = asyncCallback(callback);
var node; var node;
try { try {
node = getToNode(filepath); node = getToNode(filepath);