Skip to content

Commit

Permalink
fix: return / when calling realpathSync with / (#867)
Browse files Browse the repository at this point in the history
* fix #863 -- realpathSync('/') returns invalid result

-  #863

* run prettier

* style: move a test case

* refactor: inline conditional

Co-authored-by: Gareth Jones <Jones258@Gmail.com>
  • Loading branch information
williamstein and G-Rath authored Nov 13, 2022
1 parent eb692e4 commit 8d8e8d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/__tests__/volume/realpathSync.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { create } from '../util';

describe('.realpath(...)', () => {
describe('.realpathSync(...)', () => {
it('works with symlinks, #463', () => {
const vol = create({});
vol.mkdirSync('/a');
Expand All @@ -11,4 +11,8 @@ describe('.realpath(...)', () => {
const path = vol.realpathSync('/a/b/index.js');
expect(path).toBe('/c/index.js');
});
it('returns the root correctly', () => {
const vol = create({ './a': 'a' });
expect(vol.realpathSync('/')).toBe('/');
});
});
2 changes: 1 addition & 1 deletion src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ export class Volume {
const realLink = this.getResolvedLink(steps);
if (!realLink) throw createError(ENOENT, 'realpath', filename);

return strToEncoding(realLink.getPath(), encoding);
return strToEncoding(realLink.getPath() || '/', encoding);
}

realpathSync(path: PathLike, options?: IRealpathOptions | string): TDataOut {
Expand Down

0 comments on commit 8d8e8d1

Please sign in to comment.