diff --git a/src/lib/plugins.test.ts b/src/lib/plugins.test.ts index b770e5a9..94a18e3f 100644 --- a/src/lib/plugins.test.ts +++ b/src/lib/plugins.test.ts @@ -40,7 +40,10 @@ class MockFS implements JSRuntimeFS { } } - async readdir(path: string): Promise { + async readdir(path: string): Promise; + async readdir(path: string, options: { withFileTypes: true }): Promise; + async readdir(path: string, options?: { withFileTypes?: boolean }): Promise; + async readdir(path: string, options?: { withFileTypes?: boolean }): Promise { if (!this.dirs.has(path)) throw new Error(`ENOENT: ${path}`); const entries = new Set(); @@ -64,7 +67,21 @@ class MockFS implements JSRuntimeFS { } } - return Array.from(entries); + const names = Array.from(entries); + + if (options?.withFileTypes) { + return names.map(name => { + const fullPath = path === '/' ? `/${name}` : `${path}/${name}`; + const isDir = this.dirs.has(fullPath); + return { + name, + isDirectory: () => isDir, + isFile: () => !isDir, + }; + }); + } + + return names; } async mkdir(path: string, options?: { recursive?: boolean }): Promise { @@ -125,6 +142,18 @@ class MockFS implements JSRuntimeFS { this.files.delete(oldPath); } } + + async lstat(path: string): Promise<{ isDirectory: () => boolean; isFile: () => boolean }> { + return this.stat(path); + } + + async readlink(_path: string): Promise { + throw new Error('Symlinks not supported in MockFS'); + } + + async symlink(_target: string, _path: string): Promise { + throw new Error('Symlinks not supported in MockFS'); + } } describe('plugins', () => {