From bbade77fb421d755995466e5ac806d6e34059c52 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 4 Oct 2016 02:57:47 -0700 Subject: [PATCH] Implement proper command handling for new worker tool Reviewed By: matryoshcow Differential Revision: D3906818 fbshipit-source-id: a192723a16094d3901de40a9914428fd6ff119a2 --- .../src/node-haste/__mocks__/graceful-fs.js | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packager/react-packager/src/node-haste/__mocks__/graceful-fs.js b/packager/react-packager/src/node-haste/__mocks__/graceful-fs.js index e72e4b0a8..e67e63be5 100644 --- a/packager/react-packager/src/node-haste/__mocks__/graceful-fs.js +++ b/packager/react-packager/src/node-haste/__mocks__/graceful-fs.js @@ -9,6 +9,7 @@ 'use strict'; const fs = jest.genMockFromModule('fs'); +const {dirname} = require.requireActual('path'); const stream = require.requireActual('stream'); const noop = () => {}; @@ -71,7 +72,11 @@ fs.readFile.mockImpl(function(filepath, encoding, callback) { if (node && typeof node === 'object' && node.SYMLINK == null) { callback(new Error('Error readFile a dir: ' + filepath)); } - return callback(null, node); + if (node == null) { + callback(Error('No such file: ' + filepath)); + } else { + callback(null, node); + } } catch (e) { return callback(e); } @@ -247,6 +252,26 @@ fs.createReadStream.mockImpl(path => { }); }); +fs.createWriteStream.mockImpl(file => { + let node; + try { + node = getToNode(dirname(file)); + } finally { + if (typeof node === 'object') { + const writeStream = new stream.Writable({ + write(chunk) { + this.__chunks.push(chunk); + } + }); + writeStream.__file = file; + writeStream.__chunks = []; + return writeStream; + } else { + throw new Error('Cannot open file ' + file); + } + } +}); + fs.__setMockFilesystem = (object) => (filesystem = object);