Permalink
Browse files

packager-worker-for-buck: bundleCommand-test.js: add more consistency

Reviewed By: davidaurelio

Differential Revision: D6395673

fbshipit-source-id: 24516bd456a231708891e789f1d5aa5c18f4eeca
  • Loading branch information...
jeanlauliac authored and facebook-github-bot committed Nov 23, 2017
1 parent 2ae255a commit 7d969a05de6a45543bc31a3b982828865bc57cdb
Showing with 9 additions and 0 deletions.
  1. +3 −0 local-cli/__mocks__/fs.js
  2. +6 −0 local-cli/__tests__/fs-mock-test.js
@@ -67,6 +67,7 @@ fs.readdir.mockImplementation((filepath, callback) => {
});
fs.readFile.mockImplementation(function(filepath, encoding, callback) {
filepath = path.normalize(filepath);
callback = asyncCallback(callback);
if (arguments.length === 2) {
callback = encoding;
@@ -90,6 +91,7 @@ fs.readFile.mockImplementation(function(filepath, encoding, callback) {
});
fs.readFileSync.mockImplementation(function(filepath, encoding) {
filepath = path.normalize(filepath);
const node = getToNode(filepath);
if (isDirNode(node)) {
throw new Error('Error readFileSync a dir: ' + filepath);
@@ -103,6 +105,7 @@ fs.readFileSync.mockImplementation(function(filepath, encoding) {
fs.writeFile.mockImplementation(asyncify(fs.writeFileSync));
fs.writeFileSync.mockImplementation((filePath, content, options) => {
filePath = path.normalize(filePath);
if (options == null || typeof options === 'string') {
options = {encoding: options};
}
@@ -46,6 +46,12 @@ describe('fs mock', () => {
fs.writeFileSync('/dir/test', 'foobar', 'utf8'),
).toThrowError('ENOENT: no such file or directory');
});
it('properly normalizes paths', () => {
fs.writeFileSync('/test/foo/../bar/../../tadam', 'beep', 'utf8');
const content = fs.readFileSync('/glo/../tadam', 'utf8');
expect(content).toEqual('beep');
});
});
describe('mkdirSync()', () => {

0 comments on commit 7d969a0

Please sign in to comment.