Skip to content

Commit 7d969a0

Browse files
Jean Lauliacfacebook-github-bot
Jean Lauliac
authored andcommittedNov 23, 2017
packager-worker-for-buck: bundleCommand-test.js: add more consistency
Reviewed By: davidaurelio Differential Revision: D6395673 fbshipit-source-id: 24516bd456a231708891e789f1d5aa5c18f4eeca
1 parent 2ae255a commit 7d969a0

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
 

‎local-cli/__mocks__/fs.js

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ fs.readdir.mockImplementation((filepath, callback) => {
6767
});
6868

6969
fs.readFile.mockImplementation(function(filepath, encoding, callback) {
70+
filepath = path.normalize(filepath);
7071
callback = asyncCallback(callback);
7172
if (arguments.length === 2) {
7273
callback = encoding;
@@ -90,6 +91,7 @@ fs.readFile.mockImplementation(function(filepath, encoding, callback) {
9091
});
9192

9293
fs.readFileSync.mockImplementation(function(filepath, encoding) {
94+
filepath = path.normalize(filepath);
9395
const node = getToNode(filepath);
9496
if (isDirNode(node)) {
9597
throw new Error('Error readFileSync a dir: ' + filepath);
@@ -103,6 +105,7 @@ fs.readFileSync.mockImplementation(function(filepath, encoding) {
103105
fs.writeFile.mockImplementation(asyncify(fs.writeFileSync));
104106

105107
fs.writeFileSync.mockImplementation((filePath, content, options) => {
108+
filePath = path.normalize(filePath);
106109
if (options == null || typeof options === 'string') {
107110
options = {encoding: options};
108111
}

‎local-cli/__tests__/fs-mock-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ describe('fs mock', () => {
4646
fs.writeFileSync('/dir/test', 'foobar', 'utf8'),
4747
).toThrowError('ENOENT: no such file or directory');
4848
});
49+
50+
it('properly normalizes paths', () => {
51+
fs.writeFileSync('/test/foo/../bar/../../tadam', 'beep', 'utf8');
52+
const content = fs.readFileSync('/glo/../tadam', 'utf8');
53+
expect(content).toEqual('beep');
54+
});
4955
});
5056

5157
describe('mkdirSync()', () => {

0 commit comments

Comments
 (0)
Please sign in to comment.