diff --git a/src/print/__tests__/index.test.ts b/src/print/__tests__/index.test.ts index be068fbc7..1a59a0fa9 100644 --- a/src/print/__tests__/index.test.ts +++ b/src/print/__tests__/index.test.ts @@ -48,3 +48,33 @@ test('can stop recursion at specified depth', () => { └─ dir2/ (...)" `); }); + +test('can print symlinks', () => { + const { fs } = memfs({ + '/a/b/c/file.txt': '...', + '/a/b/main.rb': '...', + }); + fs.symlinkSync('/a/b/c/file.txt', '/goto'); + expect(toTreeSync(fs)).toMatchInlineSnapshot(` + "/ + ├─ a/ + │ └─ b/ + │ ├─ c/ + │ │ └─ file.txt + │ └─ main.rb + └─ goto → /a/b/c/file.txt" + `); +}); + +test('can print starting from subfolder', () => { + const { fs } = memfs({ + '/a/b/c/file.txt': '...', + '/a/b/main.rb': '...', + }); + expect(toTreeSync(fs, { dir: '/a/b' })).toMatchInlineSnapshot(` + "b/ + ├─ c/ + │ └─ file.txt + └─ main.rb" + `); +}); diff --git a/src/print/index.ts b/src/print/index.ts index e0202d3e1..e11b05e00 100644 --- a/src/print/index.ts +++ b/src/print/index.ts @@ -17,6 +17,8 @@ export const toTreeSync = (fs: FsSynchronousApi, opts: ToTreeOptions = {}) => { const isDir = entry.isDirectory(); if (isDir) { return toTreeSync(fs, {dir: dir + entry.name, depth: depth - 1, tab}); + } else if (entry.isSymbolicLink()) { + return '' + entry.name + ' → ' + fs.readlinkSync(dir + entry.name); } else { return '' + entry.name; }