mirror of
https://github.com/status-im/react-native.git
synced 2025-01-26 09:19:10 +00:00
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:
parent
2ae255a6ea
commit
7d969a05de
@ -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()', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user