Implement proper command handling for new worker tool

Reviewed By: matryoshcow

Differential Revision: D3906818

fbshipit-source-id: a192723a16094d3901de40a9914428fd6ff119a2
This commit is contained in:
David Aurelio 2016-10-04 02:57:47 -07:00 committed by Facebook Github Bot
parent 3d23012d06
commit 92fb9957b4
1 changed files with 26 additions and 1 deletions

View File

@ -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);