Skip to content
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

trouble with joi when fs is stubbed #200

Open
travi opened this issue Mar 17, 2017 · 2 comments
Open

trouble with joi when fs is stubbed #200

travi opened this issue Mar 17, 2017 · 2 comments

Comments

@travi
Copy link

travi commented Mar 17, 2017

This issue seems to arise with the v4.0.0 release, but I finally got around to investigating with v4.2.0. I'm not sure this is specific to joi, but that's where I'm seeing the issue. It's not obvious to me what the problem is because it appears to be related to a simple require() statement, which seems unlikely. If you have better ideas of what to dig into from the details below, I'm happy to help investigate.

I'm running cucumber tests that stub fs for writing a json file and then the tests read the file and verify it's structure using joi. When calling either joi.assert() or joi.validate(), I get the following error related to the require() statement here

Error: ENOENT, no such file or directory '/path/to/my/project/node_modules'
         at Binding.<anonymous> (/path/to/my/project/node_modules/mock-fs/lib/binding.js:988:13)
         at maybeCallback (/path/to/my/project/node_modules/mock-fs/lib/binding.js:43:17)
         at Binding.lstat (/path/to/my/project/node_modules/mock-fs/lib/binding.js:985:10)
         at Object.fs.lstatSync (fs.js:893:18)
         at Object.realpathSync (fs.js:1527:21)
         at toRealPath (module.js:132:13)
         at tryFile (module.js:128:22)
         at tryExtensions (module.js:140:22)
         at Function.Module._findPath (module.js:192:20)
         at Function.Module._resolveFilename (module.js:470:25)
         at Function.Module._load (module.js:420:25)
         at Module.require (module.js:500:17)
         at require (internal/module.js:20:19)
         at Object.checkOptions (/path/to/my/project/node_modules/joi/lib/any.js:81:25)
         at Object._validateWithOptions (/path/to/my/project/node_modules/joi/lib/any.js:602:18)
         at Object.root.validate (/path/to/my/project/node_modules/joi/lib/index.js:121:23)

If I call .restore() after reading the file from the stubbed filesystem, but before running joi things work as I would expect. (I was already calling .restore() after each test)

@rprieto
Copy link

rprieto commented Nov 26, 2017

This might be related to #213.

@gamegee
Copy link

gamegee commented May 11, 2018

I have the same issue :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants