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

Plan for multiple module systems #381

Closed
4 tasks done
iamdustan opened this issue May 27, 2015 · 14 comments
Closed
4 tasks done

Plan for multiple module systems #381

iamdustan opened this issue May 27, 2015 · 14 comments

Comments

@iamdustan
Copy link
Contributor

We’re getting ready to start a few projects where I would like to use jest heavily. The inability to hijack the module resolution calls is a bit prohibitive at the moment though. I would like to propose a simple plan to open up jest to module systems besides Haste.

  • Refactor HasteModuleLoader to the core API and the HasteModuleLoader specifics
  • Move HasteModuleLoader to it’s own npm package jest-haste
  • Use HasteModuleLoader by default with jest (backwards compatibility)
  • Allow config option for specific module loader (jest-webpack, jest-requirejs, etc)

Is there anything I’m completely neglecting or unaware of in this plan?

@blainekasten
Copy link
Contributor

+1. This is a huge pain currently.

@mwolson
Copy link

mwolson commented Sep 15, 2015

Here's a workaround which can resolve webpack paths in the preprocess phase: https://www.npmjs.com/package/jest-webpack-alias

@cpojer
Copy link
Member

cpojer commented Oct 23, 2015

I'm going to start rewriting the haste module loader soon and want to support third-party module loaders as outlined in this plan above. @iamdustan let me if there is anything I can do to support you better with the new functionality. Is adding a config for a different module loader enough for you?

@cpojer
Copy link
Member

cpojer commented Oct 23, 2015

There is a moduleLoader config already that allows you to specify a custom module loader. Is that enough for most cases?

@iamdustan
Copy link
Contributor Author

Sooooo I’m on to a different company and not using Jest anymore.

@cpojer
Copy link
Member

cpojer commented Oct 27, 2015

What, you accepted a new job and didn't check with me first?

@iamdustan
Copy link
Contributor Author

Weeeelllll buy me a house in a London suburb and I'll come work with you kind of sort of. (Not moving to California) 😇

@akheron
Copy link

akheron commented Nov 4, 2015

Will the HasteModuleLoader rewrite fix the issue that it doesn't currently seem to understand how nodejs finds modules? If, for example, there are multiple files called foo.js somewhere under node_modules, only the last one found remains in resourceMap, and all require('foo') calls get that module. I'm not exactly sure why the resource id is resolved as foo for some foo.js files and path/to/foo.js for others, though.

In my case, this is a problem because I have node_modules/react-side-effect/node_modules/fbjs/flow/include/warning.js and node_modules/react-router/node_modules/warning/warning.js. When react-router calls require('warning') it gets the wrong warning.js, which happens to use ES6 syntax that's not supported by Node, and I'm getting a test failure due to SyntaxError.

@cpojer
Copy link
Member

cpojer commented Nov 4, 2015

@akheron I suggest using a preprocessor to compile your code to ES5 before running test. Look at the babel-jest npm module.

@amasad can you elaborate on how the new dependency resolver resolves modules in this case?

@amasad
Copy link
Contributor

amasad commented Nov 5, 2015

So there are two issues here:

  1. @providesModule being a single namespace (which is what fbjs uses). That means that require('warning') will get the last one node-haste managed to look at last. 😷
  2. node-haste not supporting recursive node dependencies: when you have two foo node_modules, in different parts of the tree it will also pick one at random 😫

The react-native-packager resolver we're gonna base this off will solve these two issues by:

  1. Doesn't allow node_modules to reach into the @providesModule namespace
  2. will support recursive deps

@akheron
Copy link

akheron commented Nov 5, 2015

@cpojer I use babel-jest, but the module with ES6 syntax is an external dependency. Furthermore, the file with ES6 syntax is not even used by the dependent library itself, it's just non-precompiled source that is shipped for reference.

@amasad I'm very happy to hear that I'm not the only one having this problem and that it's being fixed 👍

@cpojer
Copy link
Member

cpojer commented Nov 5, 2015

you can still transform this file, you might have to update some configs but you can compile node_modules if you want.

@cpojer
Copy link
Member

cpojer commented Feb 17, 2016

This work was completed in #599. Yay!

@cpojer cpojer closed this as completed Feb 17, 2016
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants
@cpojer @akheron @iamdustan @amasad @mwolson @blainekasten and others