-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fixes #29637 - Allow jest testing to use foremanReact #8682
Conversation
Issues: #29637 |
8600695
to
d69e943
Compare
Opened up a discussion: https://community.theforeman.org/t/use-foremanreact-directly-in-plugin-tests/18462 |
Then
|
Thanks! I now see that foreman is checked out in Katello itself. I'm testing out hardcoing the jenkins path just to prove that this will work as expected. For this to work across environments, we will have to have some sort of logic to determine where foreman is, either through an environment variable or checking that it is a child directory of Katello first. |
d991d79
to
c87a143
Compare
You can convert it to draft (top right, in the review block) if it shouldn't be merged. |
ccda76a
to
9eca1fa
Compare
Updated to dynamically determine where foreman is when testing, checking sibling, child, and parent directories. This allows I also added a mock for Here is an example error when foreman directory isn't present:
|
9eca1fa
to
45d8987
Compare
99356be
to
93bb8eb
Compare
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 work @johnpmitsch! Web UI and tests all run and pass. Now that the PR is here, I see it's much easier than I thought it would be. We should have done this a long time ago.
I have no philosophical issue with not mocking foremanReact, because in a "normal" app without plugin architecture, you wouldn't have to mock this sort of thing anyway. So, ACK besides the one grammar nitpick below.
jest.config.js
Outdated
|
||
const foremanReactRelative = 'webpack/assets/javascripts/react_app'; | ||
const possibleForemanLocations = ['./foreman', '../foreman', '../../foreman']; | ||
const notFound = 'Foreman directory can not be found! These tests require Foreman to be present ' + |
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.
const notFound = 'Foreman directory can not be found! These tests require Foreman to be present ' + | |
const notFound = 'Foreman directory cannot be found! These tests require Foreman to be present ' + |
const foremanReactRelative = 'webpack/assets/javascripts/react_app'; | ||
const possibleForemanLocations = ['./foreman', '../foreman', '../../foreman']; | ||
const notFound = 'Foreman directory can not be found! These tests require Foreman to be present ' + | ||
'in either a parent, sibling, or child directory relative to Katello and contain the expected ' + |
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.
Was about to ask who in their right mind would put the foreman directory inside of Katello, but then saw the other PR comments 😆
Jest allows local modules to be specified by path, which allows us to use foremanReact as long as foreman is present in a sibling directory to Katello
93bb8eb
to
2b0ae3b
Compare
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 change. Thanks for taking it on ... it really didn't feel right to be mocking out all those modules.
We are currently mocking foremanReact, which is the alias for Foreman's React components and javascript library, while testing. This has been working fine, but is becoming more of an issue as we use and move more logic to Foreman's React components, meaning we have to mock a lot of logic that is used in our components which can limit our testing ability.
Jest (the React test runner) allows local modules to be specified by path, which allows us to use foremanReact as long as foreman is present in a sibling directory to Katello.
This will allow us to use the foremanReact module as-is, which is helpful now but also will be necessary when major components such as tables are moved to Foreman and we will need a way to use them in testing.
The
moduleNameMapper
is what allows us to do this. The jest config is moved tojest.config.js
so nodejs'spath
module can be used to dynamically determine the path..babelrc
is moved tobabel.config.js
as the foremanReact files served directly from foreman were not transpiling during testing. There is a comment on a jest issue that explains the reasoning for this. My understanding is that jest will look up the tree for.babelrc
rather thanbabel.config.js
, which allows multi-repo setups to use transpiled files outside of the repo.I didn't remove some of the mocks because either they created a lot of deprecation/console noise during the tests or they didn't provide consistent snapshots. I think its fine to keep some existing mocks of foremanReact components as the point is to allow the usage of foremanReact directly. It's also worth noting that parts of foremanReact can still be mocked as they have been.