-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Auth: Run codemods; use enzyme, remove mixin injection from tests #18472
Conversation
75ac8a3
to
8361756
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.
I haven't tested and scanned in-depth every line, but in overall those changes look really good 👍
Eslint complains about react/prefer-es6-class
, but I think it's kind of excepted in this iteration because of mixins.
|
||
describe( 'LoginTest', function() { | ||
let Login, page, React, ReactDom, ReactClass, TestUtils; | ||
|
||
before( () => { |
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.
We finally are getting rid of those require statements in before
block :)
@@ -247,7 +247,7 @@ | |||
"chai": "3.5.0", | |||
"chai-enzyme": "0.5.2", | |||
"deep-freeze": "0.0.1", | |||
"enzyme": "2.4.1", | |||
"enzyme": "2.9.1", |
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.
As far as we can go with React 15.x 👍
Migrating to React 16 test wise might be a big challenge.
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.
Think so? I was hoping to upgrade to enzyme
3.x once enzymejs/chai-enzyme#198 is merged, an a new chai-enzyme
version that includes it is released...
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 forgot about enzyme adapter for React 15. It might be solid. I haven’t tried it. We get some failing tests in Gutenberg when trying to use enzyme 3 with React 16. It looks like it has some hidden bugs.
You can also explore jest-enzyme 😃
client/auth/login.jsx
Outdated
</div> | ||
); | ||
} | ||
const LostPassword = localize( ( { translate } ) => { |
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.
Bonus points for moving those child components, to their own files 🥇
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.
Thanks for moving the components to their own files. Much appreciated 🏆 |
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.
This is good to go after shrinkwrap file gets regenerated with the latest changes from master. Great work @ockham 👍
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.
Gave this one a test run, looks and works well, awesome work 👍 As @gziolo mentioned, it should be good to go after generating a fresh shrinkwrap.
2.5.0 supports passing callbacks to `setState`, which we require for `client/auth/test/login`. Furthermore, there's a fix in 2.6.0 that's required for this to actually work (enzymejs/enzyme#490) Not updating to >=3.0.0 yet since chai-expect isn't compatible (yet). Changelog: https://github.com/airbnb/enzyme/blob/master/CHANGELOG.md#252-november-9-2016
These were only used by tests.
b028f99
to
0c8c7fb
Compare
…8472) * Auth: Prettify login.jsx * Auth: Run i18n codemod on login.jsx * Auth: Run react-create-class codemod on login.jsx * Auth: Prettify login.jsx * Auth: Simplify login.jsx * Auth: Named export for un-localized Login component * Framework: Upgrade enzyme to 2.9.1 2.5.0 supports passing callbacks to `setState`, which we require for `client/auth/test/login`. Furthermore, there's a fix in 2.6.0 that's required for this to actually work (enzymejs/enzyme#490) Not updating to >=3.0.0 yet since chai-expect isn't compatible (yet). Changelog: https://github.com/airbnb/enzyme/blob/master/CHANGELOG.md#252-november-9-2016 * Auth: Simplify FormTextInput ref (focus) * Auth: Use enzyme to test login.jsx * Auth: Remove obsolete refs from login.jsx (These were only used by tests.) * Auth: Move SelfHostedInstructions and LostPassword to separate files
Rationale: We're trying to get rid of mixin auto-injection for the React 16 upgrade, since this relies on methods (
react/lib
) that aren't part of the public interface.This was tricky. These tests were a bit dubious in the first place, since they were arguably diluting the concept of a unit test. My fix was to use
enzyme
to shallow-render the component, which brings us closer to actual unit testing.I also ran the
i18n
andcreateClass
codemods onlogin.jsx
, and modified it toexport
the un-localize()
dLogin
component so we could test it (without having to inject thei18n
mixin, which was the whole point of this PR). That's pretty standard stuff tho.Other than that, I tried to change tests as little as possible. To continue to pass a callback to
setState
in tests, I had to upgradeenzyme
(0dc7829):To test: