diff --git a/src/__tests__/volume/realpathSync.test.ts b/src/__tests__/volume/realpathSync.test.ts index 58d77468a..95465c15f 100644 --- a/src/__tests__/volume/realpathSync.test.ts +++ b/src/__tests__/volume/realpathSync.test.ts @@ -1,6 +1,6 @@ import { create } from '../util'; -describe('.realpath(...)', () => { +describe('.realpathSync(...)', () => { it('works with symlinks, #463', () => { const vol = create({}); vol.mkdirSync('/a'); @@ -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('/'); + }); }); diff --git a/src/volume.ts b/src/volume.ts index 145973e1e..cc098c67a 100644 --- a/src/volume.ts +++ b/src/volume.ts @@ -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 {