mirror of https://github.com/status-im/metro.git
Implement proper command handling for new worker tool
Reviewed By: matryoshcow Differential Revision: D3906818 fbshipit-source-id: a192723a16094d3901de40a9914428fd6ff119a2
This commit is contained in:
parent
3d23012d06
commit
92fb9957b4
|
@ -9,6 +9,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const fs = jest.genMockFromModule('fs');
|
const fs = jest.genMockFromModule('fs');
|
||||||
|
const {dirname} = require.requireActual('path');
|
||||||
const stream = require.requireActual('stream');
|
const stream = require.requireActual('stream');
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
|
|
||||||
|
@ -71,7 +72,11 @@ fs.readFile.mockImpl(function(filepath, encoding, callback) {
|
||||||
if (node && typeof node === 'object' && node.SYMLINK == null) {
|
if (node && typeof node === 'object' && node.SYMLINK == null) {
|
||||||
callback(new Error('Error readFile a dir: ' + filepath));
|
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) {
|
} catch (e) {
|
||||||
return callback(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);
|
fs.__setMockFilesystem = (object) => (filesystem = object);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue