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

Can't Modify Jest Transform Patterns #6042

Closed
jamesmfriedman opened this issue Dec 14, 2018 · 5 comments
Closed

Can't Modify Jest Transform Patterns #6042

jamesmfriedman opened this issue Dec 14, 2018 · 5 comments

Comments

@jamesmfriedman
Copy link
Contributor

In a perfect world, everyone ships ES5 code.

In reality, they don't.

If you have a 3rd party module that relies on es modules, Jest will happily fail.

I understand the strong stance against configuration, but this one seems like a no brainer since it makes it too easy to render the testing framework useless.

Steps to Reproduce

(Write your steps here:)

  1. Create react app
  2. import an es6 module
  3. Write a basic test
  4. Watch it fail

image

There seems to have been a lot of effort put in to making sure people could override / extend some things and not others. Can't you just shallow merge the config keys and honor whatever the user has passed in?

As a small addendum, even though moduleNameNapper is not in the supported list, it does indeed work, although you have to copy over the original declaration manually.

@mrmckeb
Copy link
Contributor

mrmckeb commented Dec 15, 2018

I've encountered this myself, with a package we were using internally across a few projects. Webpack is fine with ESM, but you need CJS for Jest.

I'd recommend reaching out to the person that built that module and asking them to fix it, as this is an issue others will encounter too. Some people may not be as fast to understand the root cause, so this definitely should be addressed.

You could also consider creating a mock for the module, if you don't actually need it to be in your tests.

I don't think this is something that needs to be fixed in CRA (because this module should be updated), but I do agree that we can always do more to allow custom configuration.

@jamesmfriedman
Copy link
Contributor Author

jamesmfriedman commented Dec 15, 2018

Getting everyone to fix their external modules seems like a bit more work than adding a few lines to the jest config :). I’ll create a PR for this for reference.

Another larger pipe dream would be to get Jest to speak ES6 but I’m assuming there are some complexities there that I don’t understand.

Thanks for the quick reply

@mrmckeb
Copy link
Contributor

mrmckeb commented Dec 15, 2018

I understand @jamesmfriedman, but I also feel we need to ensure that authors of modules follow standards. The module field should be used for ESM, and main for CJS. This ensures compatibility, whilst offering ESM for those that can consume it.

I'm sure the jest team are working on this too, as it'll become more of a problem in future.

I'll close this off as you're working on a PR, and we'll keep looking at ways to be more flexible with configs.

@mrmckeb mrmckeb closed this as completed Dec 15, 2018
@jamesmfriedman
Copy link
Contributor Author

Lol, I meant a PR for this repo that shows how easy it is to fix this issue 🤓

@jamesmfriedman
Copy link
Contributor Author

Ok @mrmckeb, PR is up :)

@lock lock bot locked and limited conversation to collaborators Jan 8, 2019
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

2 participants