-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Testing: Add integration test which ensures that npm packages can be used with Node #17273
Comments
Hi, I'm new to this project and this issue kind of intrigued me. I really would like to try this one but I'm not that familiar with testing. Are there any instructions or guides on how integration testing works for this project? |
We have the Testing Overview document. You can put tests under: The file(s) should have In this particular case, it's necessary to change the testing environment for the individual test. It can be done with:
Based on Jest documentation available at https://jestjs.io/docs/en/configuration#testenvironment-string. |
Thank you. I'll start by going through those docs. |
Would it be possible to lint for unguarded browser globals with Eslint? Would simply defining |
You can give it a try. I have no idea, to be honest. How about using |
What we want to do is to check that the code can run both in Node and browser. I.e., use only globals and API that are valid on both platforms. Platform-specific code should be guarded ( For React components, there's one additional gotcha: it's ok to work with DOM in "effects": componentDidMount() {
window.addEventListener( 'scroll', this.handleScroll );
} or useEffect( () => {
ReactDom.findDomNode( this.cartRef ).scrollIntoView();
} ); When server-side rendering, only constructors, I don't know how to lint for that -- maybe |
There's not much linting that can do here - typically what's done is that you have two enzyme test runs: one with jsdom, and one without - and all your
|
In the announcement post for Jest 26 (https://jestjs.io/blog/2020/05/05/jest-26), they shared the roadmap for upcoming breaking changes including:
It looks like we should change the default env to |
This should prevent bugs like #17165 where a naked reference to
window
will crash if used in a SSR context where there's nowindow
.See more details in the comment from @jsnajdr #17165 (comment):
The text was updated successfully, but these errors were encountered: