question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow customization of Jest: transformIgnorePatterns

See original GitHub issue

There are a ton of issues about this, and after two hours of reading through them all, I still wasn’t able to get a sense of the state of things.

We have a case where we have local libraries that are brought into node_modules, but then Jest stumbles whenever we import them, because it is not pre-processing the React components in node_modules. Transpiling our components before export is not an option because the constant transpiling every time one makes a change is a serious drag on development.

Some discussion threw out symlinks as a solution or workaround, but another developer on our team sunk many hours into that before finally getting stuck again.

There has to be a simple way to make LibraryA/MyReactComponent go into MyApp/node_modules, such that MyApp/src/MyComponent can import MyReactComponent during tests without any problems.

It would seem to be a common use case.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:12
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

23reactions
john-goldsmithcommented, May 18, 2018

@Primajin @michaeldewolf85 @mandysimon88 It’s true that the transformIgnorePatterns option is currently not available via the jest property in package.json, however, you can still tap into Jest’s configuration options without ejecting using the CLI:

npm test -- --transformIgnorePatterns "node_modules/(?!(your-untranspiled-module|some-other-module)/)"

Via the docs:

Every one of Jest’s Configuration options can also be specified through the CLI.

Note: CLI options take precedence over values from the Configuration.

That last bit is what tipped me off (maybe a documentation improvement @gaearon). Obviously configuring Jest via package.json doesn’t work, and my jest.config.js seemed to get trumped by CRA’s Jest config, so CLI args was the saving grace. Hope that helps!

17reactions
adrianblynchcommented, Sep 5, 2017

I have the same issue with an ejected app. Components in node_modules that need to be transpiled by Jest/Babel.

I ended up changing transformIgnorePatterns to:

["/node_modules/(?!(our-react-components-.*?\\.js$))"]

Now JS files in our-react-components-* folders in node_modules are being transpiled.

I understand the discussion is around a non-ejected app, I just wanted to give a solution to those that don’t mind ejecting.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring Jest
This config option lets you customize where Jest stores that cache ... number represent the maximum number of uncovered entities allowed.
Read more >
To have some of your "node_modules" files transformed, you ...
You don't need to add transformIgnorePatterns configuration for jest config, the node_modules folder is ignored by transformers.
Read more >
to have some of your "node_modules" files transformed, you ...
You don't need to add transformIgnorePatterns configuration for jest config, the node_modules folder is ignored by transformers. But this is not the issue....
Read more >
Configuring Jest
These options let you control Jest's behavior in your package.json file. ... This config option lets you customize where Jest stores that cache...
Read more >
Integrating React Native App with Jest - DEV Community ‍ ‍
I used transformIgnorePatterns right below the preset of jest in the ... to be transformed you can customize this configuration option by ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found