-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Description
Describe the bug
Hello,
I'm mocking fs to be used in a tested function.
The function is using fs-extra to read some files.
After testing, I found out that the issue is with graceful-fs (also used by fs-extra).
import fs from 'fs'
import gfs from 'graceful-fs';
export async function testFunction(filePath: string): Promise<void> {
fs.readFile(filePath, 'utf8', (error, data) => console.log(error ?? data));
// get the content of the mocked file
gfs.readFile(filePath, 'utf8', (error, data) => console.log(error ?? data));
// get: Error: ENOENT: no such file or directory, open '/incoming/package.json'
...
}
Reproduction
I've made the test project: https://github.com/daiyam/issues/tree/master/vitest/9343 which replicate the issue.
System Info
System:
OS: macOS 15.3.1
CPU: (10) arm64 Apple M4
Memory: 255.73 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.21.1 - /Users/baptiste/.nvm/versions/node/v22.21.1/bin/node
Yarn: 1.22.22 - /Users/baptiste/.nvm/versions/node/v14.21.3/bin/yarn
npm: 7.24.2 - /Volumes/Data/Development/Projects/github.com/zokugun/artifact/node_modules/.bin/npm
bun: 1.3.0 - /Users/baptiste/.bun/bin/bun
Browsers:
Brave Browser: 143.1.85.117
Chrome: 143.0.7499.170
Firefox: 146.0
Safari: 18.3
npmPackages:
vitest: ^4.0.16 => 4.0.16Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.