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

Resolve dynamic dependencies correctly when a mapping exists #9303

Merged
merged 9 commits into from
Dec 28, 2019
Merged

Resolve dynamic dependencies correctly when a mapping exists #9303

merged 9 commits into from
Dec 28, 2019

Conversation

MrJohz
Copy link
Contributor

@MrJohz MrJohz commented Dec 13, 2019

Summary

Fix #7511

When resolving a dynamic dependency (e.g. require(`~/${dynamicName}.js`), handle the case where there is a dependency resolution mapping correctly. Do this by catching all errors during the module resolution process, and not adding a new dependency is the would-be dependency cannot be resolved to a real module.

Test plan

I added an additional e2e test that reproduces the failing case. (Thanks to @jeysal for their previous attempt to isolate the cause.) I didn't add additional unit tests for this because I felt it would complicate matters, and figured that the e2e test covered the case entirely.

@MrJohz MrJohz changed the title Dynamic require watches Resolve dynamic dependencies correctly when a mapping exists Dec 14, 2019
@codecov-io
Copy link

codecov-io commented Dec 14, 2019

Codecov Report

Merging #9303 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9303      +/-   ##
==========================================
+ Coverage   64.99%   65.01%   +0.01%     
==========================================
  Files         278      278              
  Lines       11912    11913       +1     
  Branches     2934     2935       +1     
==========================================
+ Hits         7742     7745       +3     
+ Misses       3539     3538       -1     
+ Partials      631      630       -1
Impacted Files Coverage Δ
packages/jest-resolve-dependencies/src/index.ts 94% <100%> (+4.2%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 446d174...5bc89d9. Read the comment docs.

Copy link
Contributor

@jeysal jeysal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, tested against https://github.com/jeysal/jest-7511-repro and looks like it works! :)

packages/jest-resolve-dependencies/src/index.ts Outdated Show resolved Hide resolved
Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a unit test makes sense here in addition to the e2e test

CHANGELOG.md Outdated Show resolved Hide resolved
packages/jest-resolve-dependencies/src/index.ts Outdated Show resolved Hide resolved
e2e/__tests__/watchDynamicRequires.test.ts Outdated Show resolved Hide resolved
@MrJohz
Copy link
Contributor Author

MrJohz commented Dec 16, 2019

I think a unit test makes sense here in addition to the e2e test

@SimenB, I'm trying to write a unit test, but for some reason I can't get the unit tests to actually run. Running yarn jest in the jest-resolve-dependencies directory fails because it's operating on the TS sources without babelification, so jest throws a SyntaxError when it hits the first type annotation. Running yarn test in the root directory doesn't seem to find any of the tests in the individual packages.

Am I missing something here in trying to run the tests?

@SimenB
Copy link
Member

SimenB commented Dec 16, 2019

You should run ./jest (or yarn jest) from the root of the repo. Running with watch mode should ensure you only run the subset of tests for the files you change

@MrJohz
Copy link
Contributor Author

MrJohz commented Dec 27, 2019

@SimenB + others - I've added the unit test

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonderful, thank you!

@github-actions
Copy link

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.
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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

babel-jest can't handle template strings within a require statement in with --watch flag
6 participants