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

Update to Jest 22 #11956

Merged
merged 14 commits into from
Jan 4, 2018
Merged

Update to Jest 22 #11956

merged 14 commits into from
Jan 4, 2018

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jan 3, 2018

jsdom update made this one challenging.

It uncovered some issues in tests, but I believe some of the remaining 9 tests I haven't fixed yet actually point out legit problems (where we emit a different number of warnings on the server and on the client).

I made one change to the behavior. Previously we were emitting two different warnings (about bad prop casing and about client/server mismatch) when hydrating a badly cased SVG attribute like <text textlength="10" />. In ed93325, I changed it to only emit one warning (about the prop casing) since that's the actionable one. This fixed the tests (which assume the number of warnings is consistent between server and client).

"jest": "^21.3.0-beta.4",
"jest-config": "^21.3.0-beta.4",
"jest-jasmine2": "^21.3.0-beta.4",
"jest-runtime": "^21.3.0-beta.4",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We weren't using these anymore

Copy link
Contributor

Choose a reason for hiding this comment

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

expect is still in here in beta, is that used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Probably not..

@jquense
Copy link
Contributor

jquense commented Jan 3, 2018

that SVG element support tho 👌

window.addEventListener('error', event => {
if (event.error != null && event.error.suppressReactErrorLogging) {
event.preventDefault();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

might be worth ensuring these are logged somewhere. I noticed on RDL that errors thrown in event handlers where being swallowed by jsdom under mysterious circumstances...I guess there is already an issue for it tho: #8260

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, thanks for highlighting that. They are logged now (by jsdom) but we should probably fail the build on them (?)

This issue (and related PR) is actually why I got curious about updating jsdom :P

The test passed in jsdom due to its implementation details.

The original intention was to test the mutation method, but it was removed a while ago.

Following @nhunzaker's suggestion, I moved the tests to ReactDOMInput and adjusted them to not rely on implementation details.
@gaearon
Copy link
Collaborator Author

gaearon commented Jan 3, 2018

The remaining failing tests are in the DOM server integration suite and have to do with the fact that now we have a few cases where some warnings only fire on the client side (previously we didn't "see" them because of jsdom not faithfully emulating SVG or custom elements).

In some cases we can't really fix the discrepancy. For example "render HTML only and then use innerHTML" tests will never emit React warnings about unknown DOM element type because those only happen in the client-side code. So maybe we should explicitly check expected warnings somehow, or pass different numbers for different cases.

This is a bit ugly but it's just two places. I think we can live with this.
Copy link
Contributor

@nhunzaker nhunzaker left a comment

Choose a reason for hiding this comment

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

Changes look good so far!

We used to warn both about bad casing and about a mismatch.
The mismatch warning was a bit confusing. We didn't know we warned twice because jsdom didn't faithfully emulate SVG.

This changes the behavior to only leave the warning about bad casing if that's what caused the mismatch.
It also adjusts the test to have an expectation that matches the real world behavior.
@gaearon gaearon changed the title [WIP] Update to Jest 22 Update to Jest 22 Jan 4, 2018
@gaearon
Copy link
Collaborator Author

gaearon commented Jan 4, 2018

Failing the build on uncaught errors in event handlers (#8260) is more challenging and I won't do it here. (We didn't do it before either.)

We know how to do it now though (now that we own the error handler), and I think that should be fixed as part of #11098 (comment).

@gaearon gaearon requested a review from bvaughn January 4, 2018 16:34
const containerTag = tags.shift();
const container =
containerTag === 'svg'
? document.createElementNS('http://www.w3.org/2000/svg', containerTag)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nifty

// so that it gets deduplicated later, and doesn't fail the test.
expect(() => {
ReactDOM.render(<nonstandard />, document.createElement('div'));
}).toWarnDev('The tag <nonstandard> is unrecognized in this browser.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever solution. 👍

// So we'll skip the misleading extra mismatch warning in this case.
isMismatchDueToBadCasing = true;
// $FlowFixMe - Should be inferred as not undefined.
extraAttributeNames.delete(standardName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@bvaughn bvaughn left a comment

Choose a reason for hiding this comment

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

Great work, Dan! 👏

It uncovered some issues in tests, but I believe some of the remaining 9 tests I haven't fixed yet actually point out legit problems

I assume this comment is outdated? I don't see any tests that are still failing.

@gaearon
Copy link
Collaborator Author

gaearon commented Jan 4, 2018

Yeah, forgot to update that part. Individual commits show how I fixed them.

@gaearon gaearon merged commit d289d4b into facebook:master Jan 4, 2018
@gaearon gaearon deleted the jest-22 branch January 4, 2018 18:57
yenshih pushed a commit to yenshih/react that referenced this pull request Jan 6, 2018
* Bump deps to Jest 22

* Prevent jsdom from logging intentionally thrown errors

This relies on our existing special field that we use to mute errors.
Perhaps, it would be better to instead rely on preventDefault() directly.
I outlined a possible strategy here: facebook#11098 (comment)

* Update snapshots

* Mock out a method called by ReactART that now throws

* Calling .click() no longer works, dispatch event instead

* Fix incorrect SVG element creation in test

* Render SVG elements inside <svg> to avoid extra warnings

* Fix range input test to use numeric value

* Fix creating SVG element in test

* Replace brittle test that relied on jsdom behavior

The test passed in jsdom due to its implementation details.

The original intention was to test the mutation method, but it was removed a while ago.

Following @nhunzaker's suggestion, I moved the tests to ReactDOMInput and adjusted them to not rely on implementation details.

* Add a workaround for the expected extra client-side warning

This is a bit ugly but it's just two places. I think we can live with this.

* Only warn once for mismatches caused by bad attribute casing

We used to warn both about bad casing and about a mismatch.
The mismatch warning was a bit confusing. We didn't know we warned twice because jsdom didn't faithfully emulate SVG.

This changes the behavior to only leave the warning about bad casing if that's what caused the mismatch.
It also adjusts the test to have an expectation that matches the real world behavior.

* Add an expected warning per comment in the same test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants