-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime error when using mock-fs and express.js body-parser #47
Comments
the mock-fs package appears to interfere with some other packages, e.g. this, the filesystem is only mocked when required. see also tschaub/mock-fs#47
Thanks for the report @mlenkeit. I'll try to take a look soon. Any chance you checked what encoding was passed to |
unfortunately, the mock-fs package was conflicting with some other packages. also, I didn't find any api for accessing the current content of a mocked file without going through fs.readFile. so the package was replaced by the rewire package and some custom mock fs coding. works like a charm 😄 for mock-fs conflict, see tschaub/mock-fs#47
Sorry for bumping such an old issue, but I was running into the same problem (although with a different error) as the OP. I'm trying to use supertest to test an express server, and was receving this error:
This error seems to be coming from express body-parser requiring files for encoding (as you seem to already know). As a super quick fix, I was able to come up with this function to un-mock a directory:
and all is well. Although this is not ideal, it seems that (at least in my case) it's necessary. Would a mock.Ignore or mock.Exclude function be something worth adding? |
Easier workaround to that problem is to preload the encodings module before mocking a filesystem:
|
I'm testing my express.js middleware with mock-fs to mock files that should be read or written.
It seems that using mock-fs in my tests breaks the express.js body-parser package.
I created a Gist to reproduce the issue: https://gist.github.com/mlenkeit/a6fa3960967b3fa6a165
Simply clone the Gist, run
npm install
followed bynpm test
. The tests will fail somewhere deep in the body-parser package. If you comment mocking the filesystem in the Gist (lines 19 and 23) and run the tests again, everything works fine.I attached a stack trace (which doesn't include any sign of mock-fs).
Stack trace:
The text was updated successfully, but these errors were encountered: