mirror of https://github.com/status-im/metro.git
react-native-github: remove old fs mock implementation
Reviewed By: rafeca Differential Revision: D7652914 fbshipit-source-id: 5494305750e7616b5120169266c519f460ae7e6d
This commit is contained in:
parent
3bf01f272f
commit
4a118ee69c
|
@ -1,5 +1,7 @@
|
||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`posix support readlink throws when trying to read a regular file 1`] = `"EINVAL: \`/foo.txt\`: entity is not a symlink"`;
|
||||||
|
|
||||||
exports[`posix support throws when finding a symlink loop 1`] = `"ELOOP: \`/foo.txt\`: too many levels of symbolic links"`;
|
exports[`posix support throws when finding a symlink loop 1`] = `"ELOOP: \`/foo.txt\`: too many levels of symbolic links"`;
|
||||||
|
|
||||||
exports[`posix support throws when trying to create symlink over existing file 1`] = `"EEXIST: \`/foo.txt\`: directory or file already exists"`;
|
exports[`posix support throws when trying to create symlink over existing file 1`] = `"EEXIST: \`/foo.txt\`: directory or file already exists"`;
|
||||||
|
|
|
@ -494,6 +494,25 @@ describe('posix support', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('readlink', () => {
|
||||||
|
it('reads a symlink target', () => {
|
||||||
|
fs.symlinkSync('foo.txt', '/bar.txt');
|
||||||
|
expect(fs.readlinkSync('/bar.txt')).toBe('foo.txt');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('reads a symlink target as buffer', () => {
|
||||||
|
fs.symlinkSync('foo.txt', '/bar.txt');
|
||||||
|
expect(fs.readlinkSync('/bar.txt', 'buffer')).toEqual(
|
||||||
|
Buffer.from('foo.txt'),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws when trying to read a regular file', () => {
|
||||||
|
fs.writeFileSync('/foo.txt', 'test');
|
||||||
|
expectFsError('EINVAL', () => fs.readlinkSync('/foo.txt'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('throws when trying to read inexistent file', () => {
|
it('throws when trying to read inexistent file', () => {
|
||||||
expectFsError('ENOENT', () => fs.readFileSync('/foo.txt'));
|
expectFsError('ENOENT', () => fs.readFileSync('/foo.txt'));
|
||||||
});
|
});
|
||||||
|
|
|
@ -50,6 +50,7 @@ type Encoding =
|
||||||
| 'ascii'
|
| 'ascii'
|
||||||
| 'base64'
|
| 'base64'
|
||||||
| 'binary'
|
| 'binary'
|
||||||
|
| 'buffer'
|
||||||
| 'hex'
|
| 'hex'
|
||||||
| 'latin1'
|
| 'latin1'
|
||||||
| 'ucs2'
|
| 'ucs2'
|
||||||
|
@ -99,6 +100,7 @@ const ASYNC_FUNC_NAMES = [
|
||||||
'read',
|
'read',
|
||||||
'readdir',
|
'readdir',
|
||||||
'readFile',
|
'readFile',
|
||||||
|
'readlink',
|
||||||
'realpath',
|
'realpath',
|
||||||
'stat',
|
'stat',
|
||||||
'unlink',
|
'unlink',
|
||||||
|
@ -317,6 +319,34 @@ class MemoryFs {
|
||||||
return result.toString(encoding);
|
return result.toString(encoding);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
readlinkSync = (
|
||||||
|
filePath: string | Buffer,
|
||||||
|
options: ?Encoding | {encoding: ?Encoding},
|
||||||
|
): string | Buffer => {
|
||||||
|
let encoding;
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
encoding = options;
|
||||||
|
} else if (options != null) {
|
||||||
|
({encoding} = options);
|
||||||
|
}
|
||||||
|
filePath = pathStr(filePath);
|
||||||
|
const {node} = this._resolve(filePath, {keepFinalSymlink: true});
|
||||||
|
if (node == null) {
|
||||||
|
throw makeError('ENOENT', filePath, 'no such file or directory');
|
||||||
|
}
|
||||||
|
if (node.type !== 'symbolicLink') {
|
||||||
|
throw makeError('EINVAL', filePath, 'entity is not a symlink');
|
||||||
|
}
|
||||||
|
if (encoding == null || encoding === 'utf8') {
|
||||||
|
return node.target;
|
||||||
|
}
|
||||||
|
const buf = Buffer.from(node.target);
|
||||||
|
if (encoding == 'buffer') {
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
return buf.toString(encoding);
|
||||||
|
};
|
||||||
|
|
||||||
realpathSync = (filePath: string | Buffer): string => {
|
realpathSync = (filePath: string | Buffer): string => {
|
||||||
return this._resolve(pathStr(filePath)).realpath;
|
return this._resolve(pathStr(filePath)).realpath;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue