Permalink
Browse files

metro-buck: add e2e testing of command

Reviewed By: davidaurelio

Differential Revision: D6533842

fbshipit-source-id: b641559eb3085bac57ab3a1cc80a3f2f86b7ec92
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Dec 11, 2017
1 parent dab313a commit ecec4319c4fda9bebc90216d5340442b2a5725df
Showing with 15 additions and 24 deletions.
  1. +4 −24 local-cli/__mocks__/fs.js
  2. +11 −0 local-cli/__tests__/fs-mock-test.js
@@ -66,29 +66,7 @@ fs.readdir.mockImplementation((filepath, callback) => {
return callback(null, Object.keys(node));
});

fs.readFile.mockImplementation(function(filepath, encoding, callback) {
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.readFile.mockImplementation(asyncify(fs.readFileSync));

fs.readFileSync.mockImplementation(function(filepath, encoding) {
filepath = path.normalize(filepath);
@@ -156,7 +134,9 @@ fs.mkdirSync.mockImplementation((dirPath, mode) => {
if (!isDirNode(node)) {
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) {
@@ -64,6 +64,17 @@ describe('fs mock', () => {
* comment and run Flow. */
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()', () => {

0 comments on commit ecec431

Please sign in to comment.