Closed nickserv closed 6 years ago
It seems like prefixing require-dir
's relative path arguments with __dirname
fixes this, since it's forced to use the absolute path. Is there a way we could do this within require-dir
in a way that still works in Jest?
Nevermind, that doesn't fix it, Jest's environment incorrectly returns empty directory contents (which breaks this library) because Jest doesn't support module.parent
, which this library relies on.
Unfortunately this means that require-dir
can't be used in Jest (even by an indirect dependency) unless the issue is fixed upstream. For now I'd recommend that projects that use Jest or have dependents using Jest migrate away from this library using a static index.js
file of imports and exports instead (which has performance and ES6 migration advantage anyway).
Still seeing this in jest 22.1.4 and the latest require-dir
This is still happening for me with Jest 22.4.2.
Same for me, Jest 22.4.2
Yeah, this is a jest bug. Nothing we can really do from this library - sorry! Open a ticket on the jest repo for it - this also might be related https://github.com/facebook/jest/issues/5235
Currently the problem with Jest lies in https://github.com/aseemk/requireDir/blob/master/index.js#L98. In Jest land require.extensions
is an empty object {}
. That way, map
variable is not populated correctly. Please note that require.extensions
is also deprecated in latest node.
I've tried various, hacky solutions via Jest preprocessors as stated in this related issue but they didn't work.
I am sorry but I have to switch to require-directory
package that doesn't have the require.extensions
dependency. I really hope the above information help into addressing the problem faster.
Please refer to https://github.com/facebook/jest/issues/4567.
It appears that a Jest specific issue causes
require-dir
's module resolution to happen relatively to the test package instead of the parent package. This causes dependents ofrequire-dir
, includingnpm-check-updates
, to break when used in Jest tests.