-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Clarify behavior of transformIgnorePatterns
when including multiple patterns.
#11796
Clarify behavior of transformIgnorePatterns
when including multiple patterns.
#11796
Conversation
Codecov Report
@@ Coverage Diff @@
## master #11796 +/- ##
=======================================
Coverage 69.04% 69.04%
=======================================
Files 312 312
Lines 16366 16366
Branches 4746 4746
=======================================
Hits 11300 11300
Misses 5039 5039
Partials 27 27 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AndrewSouthpaw! Seems like a good addition to clarify this considering that not everyone knows how Jest treats this under the hood, or are experienced with RegExp. 🙂
Here's a few things I spotted looking over your PR.
@sigveio thanks for the thoughtful and thorough feedback! I'm glad you think the additions are useful. I've pushed up some changes, let me know if they address your concerns. Once it looks good, I'll copy the changes to the versioned docs as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sigveio thanks for the thoughtful and thorough feedback! I'm glad you think the additions are useful.
You are welcome! 😌
I've pushed up some changes, let me know if they address your concerns.
Thanks - I've added some follow-up comments.
With regards to the patterns; what Jest does internally is essentially this after loading the config:
To substitute in <rootDir>
for those using that in their patterns. And then in the transformer:
To construct a combined and appropriately escaped pattern in the form of a RegExp object.
So if you'd like to verify your patterns, you could do the same: run it through the RegExp()
constructor and console.log()
it to get the string. And use a testing tool like this to try it out: https://regex101.com/r/JsLIDM/1
(Note that I added the flags gm
in the tool there just to allow multiple matches across multiple lines for the purpose of that demonstration. Lines where node_modules
is colored = what Jest would ignore for transformations.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is awesome, thank you!! Since this was opened I've added a 27.2 version - would you mind merging in main
and updating that as well? 🙂
…nsform-ignore-patterns * 'main' of https://github.com/facebook/jest: (38 commits) chore: update `npm` instructions in README (jestjs#11890) chore: force patched version of ansi-regex (jestjs#11889) chore: update lockfile after publish v27.2.1 chore: update changelog for release make the syntax error message more helpful for TS users (jestjs#11807) fix: include path to test file in "after teardown" error (jestjs#11885) docs: add link to the typescript integration instructions (jestjs#11806) fix: properly return mocks when using jest.isolatedModules (jestjs#11882) chore: remove node version pinning from CI (jestjs#11866) chore: remove node 13 as condition in some tests (jestjs#11880) chore: fix typo in docs chore: update lockfile after publish v27.2.0 chore: roll new website version chore: update changelog for release chore: update lock feat: support `conditions` from test environments (jestjs#11863) Revert "chore: remove unneeded yarn patch for react native (jestjs#11853)" chore: supress experimental warnings in tests ...
Done! Thanks for the heads up @SimenB! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
I recently bumped into an mystery working with
transformIgnorePatterns
, where I had two negative lookaheads fornode_modules
, like so:As I came to realize, this meant that both
node_modules/foo
andnode_modules/bar
folders were not transformed, because they would always match in the other pattern. I missed the significance of the line:Maybe this is completely evident to other people, but it does seem like an easy detail to miss while working with it.
I figured I'd share these suggestions, and if the team thinks it's a worthwhile addition, I can add the changes in the other doc versions.
Test plan
Checked running website locally.