aseemk / requireDir

Node.js helper to require() directories.
MIT License
484 stars 60 forks source link

when use requireDir with Jest,require.extensions is empty #66

Open i5ting opened 3 years ago

i5ting commented 3 years ago

https://github.com/aseemk/requireDir/blob/master/index.js#L50

const isJestEnviroment = process.env.JEST_WORKER_ID !== undefined

if (isJestEnviroment) extensions = ['.js', '.json','.mjs']
rhenandias commented 2 years ago

Apparently, there is a bug envolving dependencies when Jest is used with requireDir, check this thread, this comment in specific, recomends switching requireDir package for require-directory package.

The module require-directory works just fine for me along side Jest.

For me, what would be writed as: const routesDefinition = requireDir("./routes");

was replaced by: const routesDefinition = requireDirectory(module, "./routes");