metro-buck: add e2e testing of command
Reviewed By: davidaurelio Differential Revision: D6533842 fbshipit-source-id: b641559eb3085bac57ab3a1cc80a3f2f86b7ec92
This commit is contained in:
parent
dab313a0de
commit
ecec4319c4
|
@ -66,29 +66,7 @@ fs.readdir.mockImplementation((filepath, callback) => {
|
||||||
return callback(null, Object.keys(node));
|
return callback(null, Object.keys(node));
|
||||||
});
|
});
|
||||||
|
|
||||||
fs.readFile.mockImplementation(function(filepath, encoding, callback) {
|
fs.readFile.mockImplementation(asyncify(fs.readFileSync));
|
||||||
filepath = path.normalize(filepath);
|
|
||||||
callback = asyncCallback(callback);
|
|
||||||
if (arguments.length === 2) {
|
|
||||||
callback = encoding;
|
|
||||||
encoding = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let node;
|
|
||||||
try {
|
|
||||||
node = getToNode(filepath);
|
|
||||||
if (isDirNode(node)) {
|
|
||||||
callback(new Error('Error readFile a dir: ' + filepath));
|
|
||||||
}
|
|
||||||
if (node == null) {
|
|
||||||
return callback(Error('No such file: ' + filepath));
|
|
||||||
} else {
|
|
||||||
return callback(null, node);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return callback(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
fs.readFileSync.mockImplementation(function(filepath, encoding) {
|
fs.readFileSync.mockImplementation(function(filepath, encoding) {
|
||||||
filepath = path.normalize(filepath);
|
filepath = path.normalize(filepath);
|
||||||
|
@ -156,7 +134,9 @@ fs.mkdirSync.mockImplementation((dirPath, mode) => {
|
||||||
if (!isDirNode(node)) {
|
if (!isDirNode(node)) {
|
||||||
throw fsError('ENOTDIR', 'not a directory: ' + parentPath);
|
throw fsError('ENOTDIR', 'not a directory: ' + parentPath);
|
||||||
}
|
}
|
||||||
node[path.basename(dirPath)] = {};
|
if (node[path.basename(dirPath)] == null) {
|
||||||
|
node[path.basename(dirPath)] = {};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function fsError(code, message) {
|
function fsError(code, message) {
|
||||||
|
|
|
@ -64,6 +64,17 @@ describe('fs mock', () => {
|
||||||
* comment and run Flow. */
|
* comment and run Flow. */
|
||||||
expect(content).toEqual('foobar');
|
expect(content).toEqual('foobar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not erase directories', () => {
|
||||||
|
fs.mkdirSync('/dir', 0o777);
|
||||||
|
fs.writeFileSync('/dir/test', 'foobar', 'utf8');
|
||||||
|
fs.mkdirSync('/dir', 0o777);
|
||||||
|
const content = fs.readFileSync('/dir/test', 'utf8');
|
||||||
|
/* $FlowFixMe(>=0.56.0 site=react_native_oss) This comment suppresses an
|
||||||
|
* error found when Flow v0.56 was deployed. To see the error delete this
|
||||||
|
* comment and run Flow. */
|
||||||
|
expect(content).toEqual('foobar');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createWriteStream()', () => {
|
describe('createWriteStream()', () => {
|
||||||
|
|
Loading…
Reference in New Issue