-
Notifications
You must be signed in to change notification settings - Fork 154
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
test: add support for automated tests for frontend with Jest and tests for HomeLoggedOut and NetworkHeader components #136
test: add support for automated tests for frontend with Jest and tests for HomeLoggedOut and NetworkHeader components #136
Conversation
Looks good to me |
The only problem that I see is the mixture of the ES6 and CommonJS modules. Is something broken with ES6? It is better to migrate fully to the ES6. So the |
There you go, should be better now and all tests still pass. Would you mind keeping issue #135 opened until all tests have been built for the frontend? |
Yes, certainly Are you going to open the new PR with other frontend tests so I should merge it now, or we could just change the current PR title? |
Yes! It will take me time to create all tests. It went somewhat quickly for the 2 components included in this PR because they were somewhat small but with more complex ones, it could take me weeks to cover them well. I already updated the PR title with the additional tests I added this morning and if you agree, this PR could be merged and I would open additional PR's as I move along with more tests until issue #136 is fully resolved. |
@@ -0,0 +1,59 @@ | |||
import { render, screen } from "@testing-library/react"; | |||
import HomeLoggedOut from "../../src/components/HomeLoggedOut"; |
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 think there is a better way to import the components
I think that it's better to have an import path like |
To be honest, I thought about it, I hesitated and when I saw the other imports did not have anything before them and were names like |
Is there any additional change you would like to see for this PR? |
frontend/package.json
Outdated
"source-map-explorer": "^2.5.2" | ||
}, | ||
"scripts": { | ||
"start": "BROWSER=none react-scripts start", | ||
"build": "react-scripts build", | ||
"analyze": "source-map-explorer 'build/static/js/*.js'" | ||
"analyze": "source-map-explorer 'build/static/js/*.js'", | ||
"test:unit": "npx jest --coverage --testPathPattern='unit'" |
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 think that it would be better to install jest in devDependencies and use it directly. ZeroUI uses the yarn package manager, so it's a bit confusing to see the npx.
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.
Ok, sorry about this! I realized another package was missing too after adding Jest so I added that other package as well (jest-environment-jsdom
). Let me know if you see anything else that needs to be changed!
This error message appeared before the installation of this package resolved the issue: SecurityError: localStorage is not available for opaque origins
Seems to be something is wrong now.
|
I came across this, but it is technically unrelated to the PR. I can make the changes anyways if you want to see the errors gone. I did a successful test change with |
Ok, that's fine, I could merge it now. |
Thank you very much! I'll proceed to add more tests! |
Pull Request type
Please check the type of change your PR introduces:
Support for automated tests with Jest for the frontend only.
What is the current behavior?
There are currently no automated tests with the codebase. This pull request is meant to add such support for the frontend only for now using Jest and other related tools and to provide the tests for the first component: HomeLoggedOut.
Issue Number: #135
What is the new behavior?
Automated tests will now be supported for the frontend. More tests are required to fully cover the codebase but this is a starting point to eventually enable GitHub's dependabot, automated tests with GitHub Actions, etc.
Does this introduce a breaking change?
The changes are mainly related to development-related functionalities.
package.json
is updated to add the required additional dev dependencies and so isyarn.lock
to reflect these changes.Other information
Don't hesitate to ask me any question you might have about the change.