Skip to content

Commit

Permalink
metro-buck: add e2e testing of command
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D6533842

fbshipit-source-id: b641559eb3085bac57ab3a1cc80a3f2f86b7ec92
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Dec 11, 2017
1 parent dab313a commit ecec431
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
28 changes: 4 additions & 24 deletions local-cli/__mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions local-cli/__tests__/fs-mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit ecec431

Please sign in to comment.