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

Testing: Upgrade React and Enzyme to the latest version #3079

Merged
merged 1 commit into from
Oct 20, 2017

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Oct 20, 2017

Description

Another attempt to upgrade React and Enzyme to the latest version. We started exploration in #2813 and this PR should finally make it happen. All tests work as expected.

As part of this diff I also improved the behavior of throwing an error when test executes console.error. I provided new logic which uses spies and expect call to validate if test should fail. New output looks as follow:

● InserterMenu › should disable already used blocks with usedOnce

expect(jest.fn()).not.toHaveBeenCalled()

Expected mock function not to be called but it was called with:
  ["Warning: Expected `onMouseLeave` listener to be a function, instead got a value of `boolean` type.
    in button (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in InserterMenu (created by WrapperComponent)
    in WrapperComponent"], ["Warning: Expected `onMouseEnter` listener to be a function, instead got a value of `boolean` type.
    in button (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in div (created by InserterMenu)
    in InserterMenu (created by WrapperComponent)
    in WrapperComponent"]
  
  at Object.<anonymous> (test/setup-test-framework.js:23:23)
  at process._tickCallback (internal/process/next_tick.js:109:7)

It's much easier to read and it properly outputs all warnings and errors.

There are still 2 skipped tests. I will take a closer look at them later and decide if we can fix them or they should be removed.

How Has This Been Tested?

Travis should be happy.

Run npm test locally.

To test new behavior around console.error and console.warn simply put such call in one of the tests.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows has proper inline documentation.

@gziolo gziolo added Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Oct 20, 2017
@gziolo gziolo self-assigned this Oct 20, 2017
@@ -18,6 +18,7 @@ const { UP, DOWN } = keycodes;
describe( 'NavigableMenu', () => {
// Skipping this this because the `isVisible` check in utils/focus/tabbable.js always returns false in tests
// Probbably a jsdom issue
// eslint-disable-next-line jest/no-disabled-tests
it.skip( 'should navigate by keypresses', () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I will look into it later. I added this eslint rule to hide warning.

@@ -290,8 +290,8 @@ export class InserterMenu extends Component {
onClick={ this.selectBlock( block.name ) }
ref={ this.bindReferenceNode( block.name ) }
tabIndex="-1"
onMouseEnter={ ! disabled && this.props.showInsertionPoint }
onMouseLeave={ ! disabled && this.props.hideInsertionPoint }
onMouseEnter={ ! disabled ? this.props.showInsertionPoint : null }
Copy link
Member Author

Choose a reason for hiding this comment

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

This change fixes warnings in the InserterMenu component:

Warning: Expected onMouseLeave listener to be a function, instead got a value of boolean type.
Warning: Expected onMouseEnter listener to be a function, instead got a value of boolean type.

@gziolo gziolo force-pushed the update/react-enzyme-upgrade-tests branch from e3e6eb2 to 54e3057 Compare October 20, 2017 10:02
afterEach( () => {
expect( spyError ).not.toHaveBeenCalled();
expect( spyWarn ).not.toHaveBeenCalled();
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@@ -28,12 +28,12 @@
"moment-timezone": "0.5.13",
"mousetrap": "1.6.1",
"prop-types": "15.5.10",
"react": "15.6.1",
"react": "16.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

you did it 👍

@gziolo gziolo merged commit d8db04b into master Oct 20, 2017
@gziolo gziolo deleted the update/react-enzyme-upgrade-tests branch October 20, 2017 10:41
@aduth
Copy link
Member

aduth commented Oct 20, 2017

Noting that many of our dependencies define a React peer in the 15.x line, so warnings are logged when installing a new version of a package:

npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react-dom@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react-dom@^0.14.0 || ^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^15.5.8 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react@^15.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of react-dom@^15.0.0 but none is installed. You must install peer dependencies yourself.

I imagine at least some of these should have updated versions available which define React 16 as a valid peer.

@gziolo
Copy link
Member Author

gziolo commented Oct 20, 2017

Yes, we can upgrade them after release v1.5. We are using the latest React and React DOM for some time with the bundled code so it seemed like an easier migration path. I can open a follow-up PR on Monday. Thanks for catching this. @youknowriad left a note about this in the preceding PR but I forget to copy it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants