mardi 23 janvier 2018

Jest resolves module paths in different order than Node.js

In my Node.js project, I have a passport package installed and also my own config/passport.js file with configuration of Passport strategies along with app config in config/config.js.

I set up my NODE_PATH to app:config (I am on Ubuntu 16.04) so when I run my app with Node, I can just do require('passport') to require Passport.js package and also require('config') to require my app's config.

So far so good, but when I run tests with Jest and set my modulePaths to app and config, the require('passport') call resolves to config/passport.js which (as you can imagine) crashes the app.

Why does Jest look into modulePaths before node_modules when requiring packages? And how could this be solved? I tried adding node_modules to Jest's modulePaths, but it caused more troubles than solved.

Thanks for any advice, I tried looking into Jest's code but with no result.

Aucun commentaire:

Enregistrer un commentaire