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

Reviewed By: davidaurelio

Differential Revision: D6395673

fbshipit-source-id: 24516bd456a231708891e789f1d5aa5c18f4eeca
This commit is contained in:
Jean Lauliac 2017-11-23 03:10:04 -08:00 committed by Facebook Github Bot
parent 2ae255a6ea
commit 7d969a05de
2 changed files with 9 additions and 0 deletions

View File

@ -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};
}

View File

@ -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()', () => {