tschaub / mock-fs

Configurable mock for the fs module
https://npmjs.org/package/mock-fs
Other
911 stars 86 forks source link

fs.rm behaves differently on NodeJS 16 vs 14 #346

Open yotamselementor opened 2 years ago

yotamselementor commented 2 years ago

The following code behaves differently on NodeJS 16 and NodeJS 14:

            mockFs({
                path: {
                    source: {
                        subdir: mockFs.directory(),
                    },
                },
            });
            await fs.rm("path/source", { force: true });

On NodeJS 14, the code runs successfully, while on NodeJS 16 it fails with the following error: SystemError: Path is a directory: rm returned EISDIR (is a directory) path/source

3cp commented 2 years ago

fs.rm was just added in nodejs v14.14.0. We never had any test coverage on it. I can work on it when I got time.

3cp commented 2 years ago

I tested fs.rm with force:true without mock-fs, nodejs v14.18.1 returns same error as nodejs v17.1.0. You have to use recursive:true for any rm(folder). It's understandable, as fs.rm is modeled on the standard POSIX rm utility (rm -r dir).

(node:46582) UnhandledPromiseRejectionWarning: SystemError [ERR_FS_EISDIR]: Path is a directory: rm returned EISDIR (is a directory) a

What nodejs v14 version were you using?

(I found another issue related to file permission when testing fs.rm with mock-fs, working on it.)