-
-
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
Fix options.moduleNameMapper override order with preset (#3565) #3689
Conversation
I think that some "prettier" or ESLint checks failed on CircleCi (hard to tell from the output):
The first an last errors are just some whitespace that my vs code formatting added. I'll fix that. (ESLint and prettier do not work after forking and following all the contribution instructions, so a client side check is difficult. Not a great experience I must say... may have just been in a broken state at the point when I forked) |
Codecov Report
@@ Coverage Diff @@
## master #3689 +/- ##
=======================================
Coverage 58.08% 58.08%
=======================================
Files 195 195
Lines 6751 6751
Branches 6 6
=======================================
Hits 3921 3921
Misses 2827 2827
Partials 3 3
Continue to review full report at Codecov.
|
It would be great if this could be part of the next release. I am assuming you are doing trunk based dev so I created this pull request for master. |
wow finally someone solved this!!! #Legend |
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.
Looks good to me
@thymikee are you able to approve this and merge it? |
Maybe a little background first. Presets may have some very loosely declared mappings, e.g.: preset: "moduleNameMapper": {
"(.*)": "<rootDir>/src/$1"
}, user config: "moduleNameMapper": {
"(.*)": "$1",
"/my-module/(.*)": "<rootDir>/abc/$1"
}, This mapping ( What this PR does is that it lets in a bit hacky way overcome this issue by merging What do you think @cpojer? |
By the time it's not merged (I'm not sure if it will be), you can temporarily copy the preset configuration and adjust it the way you like. It's not a blocker. |
|
||
test('merges with options and moduleNameMapper preset is overridden by options', () => { | ||
/* eslint-disable sort-keys */ | ||
// prettier-ignore |
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.
Can you please enable prettier here and enable sort keys?
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.
Thanks for the review. See my comment above about the sort-keys rule.
I really think that a test for the correct handling of the order precedence of user and preset config should not only give a scenario that could imply that alphabetical order is the precedence of choice. Providing the object properties out of order makes the test more explicit and more resilient in my opinion.
I'm happy to change my test to support the rule and remove the disable if you prefer the following of the style rules over a more resilient test. Let me know ;)
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.
I was just thinking that I could alternatively retain the resilience of the test just by changing semantics. Instead of using the object initializer I could create an empty object and then assign each property in separate statements. Please let me know what you would prefer. Thanks!
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.
Yeah that sounds reasonable.
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.
Great...
Which one? The last suggestion? 😄
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.
Yes
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.
Done.
I don't really have super strong feelings about this, if you fix up the test code to not opt-out of the code standards from this repo, I'm fine merging it. |
The Circleci build failed on my latest commit due to a failure of the 'yarn run danger' step. |
This also happened on another PR. Cc @orta |
Weird, that looks like a bug on GitHub's end wrt their API - Danger's making an API call to an open repo, doesn't look like it's being rate-limited either. So I wouldn't expect this to ever fail. |
@cpojer looks like that may be an intermittent isue in the one build step. Would you be able to kick off a rebuild, or should I do a small superfluous check-in to get it rebuilding again? |
Thanks @thymikee for kicking off a rebuild. |
All tests pass, danger token issue is known and there's nothing you can do but wait for your PR to be merged. @cpojer is on his vacation now, so it may take a while. |
Hope you have a great time away @cpojer! |
This is a really annoying issue with
? |
@michahell you can directly copy jest-preset.json to your package.json and remove the mapping as a workaround for now. |
This'll need one more rebase, sorry. |
Ok, I'll do that now |
Adjusted the order so that the options mappings are checked first and then the preset mappings are checked. The preset mappings can be overridden by the options mappings.
Thanks @cpojer! |
May 17th, 2019. |
Thanks guys, awesome! I'll postpone writing tests to May 17th, 2019. don't worry, none will notice 😃 😂 |
Come on @michahell I think that is taking it a bit too far. May 17th, 2019 is a Friday 🍺 ! You will have to get them done on the 16th 😜 |
…jestjs#3689) * Fix options.moduleNameMapper override order with preset (jestjs#3565) Adjusted the order so that the options mappings are checked first and then the preset mappings are checked. The preset mappings can be overridden by the options mappings. * Fix prettier linting issues * Fix eslint issues * Workaround in test for eslint sort-keys rule
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
Adjusted the order so that the options mappings are checked first and then the preset mappings are checked.
The preset mappings can be overridden by the options mappings.
Fixes #3565
Test plan
Modified existing test and added a new test.
Tests passed after making the necessary code changes. TDD FTW ;) !