Skip to content

Commit

Permalink
packager-worker-for-buck: bundleCommand-test.js: add more consistency
Browse files Browse the repository at this point in the history
Reviewed By: davidaurelio

Differential Revision: D6395673

fbshipit-source-id: 24516bd456a231708891e789f1d5aa5c18f4eeca
  • Loading branch information
Jean Lauliac authored and facebook-github-bot committed Nov 23, 2017
1 parent 2ae255a commit 7d969a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions local-cli/__mocks__/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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};
}
Expand Down
6 changes: 6 additions & 0 deletions local-cli/__tests__/fs-mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down

0 comments on commit 7d969a0

Please sign in to comment.