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

Auth: Run codemods; use enzyme, remove mixin injection from tests #18472

Merged
merged 11 commits into from
Oct 5, 2017

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Oct 3, 2017

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 and createClass codemods on login.jsx, and modified it to export the un-localize()d Login component so we could test it (without having to inject the i18n 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 upgrade enzyme (0dc7829):

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

To test:

  • Verify that tests pass.
  • Verify that login still works.

@matticbot
Copy link
Contributor

@ockham ockham changed the title Auth: Run i18n codemod on login.jsx Auth: Run codemods; use enzyme, remove mixin injection from tests Oct 3, 2017
@ockham ockham added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. and removed [Status] In Progress labels Oct 3, 2017
Copy link
Member

@gziolo gziolo left a 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( () => {
Copy link
Member

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",
Copy link
Member

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.

Copy link
Contributor Author

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...

Copy link
Member

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 😃

</div>
);
}
const LostPassword = localize( ( { translate } ) => {
Copy link
Member

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 🥇

Copy link
Contributor Author

@ockham ockham Oct 3, 2017

Choose a reason for hiding this comment

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

@gziolo
Copy link
Member

gziolo commented Oct 3, 2017

Thanks for moving the components to their own files. Much appreciated 🏆

Copy link
Member

@gziolo gziolo left a 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 👍

Copy link
Member

@tyxla tyxla left a 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.

@ockham ockham merged commit 70aec10 into master Oct 5, 2017
@ockham ockham deleted the codemod/auth-login branch October 5, 2017 11:02
@ockham
Copy link
Contributor Author

ockham commented Oct 5, 2017

Thanks for reviewing @gziolo @tyxla!

@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Oct 5, 2017
MicBosi pushed a commit that referenced this pull request Oct 5, 2017
…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
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.

4 participants