downshift-js / downshift

🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.
http://downshift-js.com/
MIT License
12.09k stars 929 forks source link

Fix react native tests #594

Open kentcdodds opened 6 years ago

kentcdodds commented 6 years ago

They're currently disabled. I'm not sure what's wrong with them.

I don't have time to work on this and I don't use react native. So we'll need contributions here.

eliperkins commented 6 years ago

Sorry I missed when this happened before! 🤔

Is there a point when CI failed? I'll repro this locally, but discussing over a build failure might be more helpful.

kentcdodds commented 6 years ago

here: https://travis-ci.org/paypal/downshift/builds/437797785

eliperkins commented 6 years ago

I'd say this is due to React Native 0.57 changing the default Babel preset, from babel-preset-react-native to metro-react-native-babel-preset: https://github.com/react-native-community/react-native-releases/issues/34#issuecomment-407006185

I'll pick this one up real quick and see what I can find.

eliperkins commented 6 years ago

Here's a better link to the changes that need to happen: https://github.com/react-native-community/react-native-releases/blob/master/CHANGELOG.md#updating-to-this-version

eliperkins commented 6 years ago

Hmmm, upgrading only the Babel preset doesn't seem to address all the issues, as I still get the following error after running yarn remove babel-preset-react-native && yarn add --dev metro-react-native-babel-preset@\^0.45.0 && yarn run jest --projects other/misc-tests other/react-native

  ● Console

    console.error node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6884
      The above error occurred in the <mockConstructor> component:
          in mockConstructor (at onChange-tests.js:19)
          in View (created by Component)
          in Component (at onChange-tests.js:9)
          in RootView (at onChange-tests.js:18)
          in Downshift (at onChange-tests.js:16)

      Consider adding an error boundary to your tree to customize error handling behavior.
      Visit https://fb.me/react-error-boundaries to learn more about error boundaries.

  ● calls onChange when TextInput changes values

    Cannot find module 'schedule/tracking' from 'ReactNativeRenderer-dev.js'

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:221:17)
      at node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:29:20
      at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:16199:5)
eliperkins commented 6 years ago

Aaaaaand one more bit of sleuthing to discover some more context here: https://github.com/facebook/react-native/issues/21150#issuecomment-427768751

I ran yarn add --dev schedule@0.4.0 followed by yarn run jest --projects other/react-native and got the following:

❯ yarn run jest --projects other/react-native
yarn run v1.10.1
$ /Users/eliperkins/src/downshift/node_modules/.bin/jest --projects other/react-native
 PASS  other/react-native/__tests__/onBlur-tests.js

 RUNS  other/react-native/__tests__/onChange-tests.js
/Users/eliperkins/src/downshift/dist/downshift.native.cjs.js:1035
      var downshiftButtonIsActive = _this4.props.environment.document.activeElement.dataset.toggle && _this4._rootNode && _this4._rootNode.contains(_this4.props.environment.document.activeElement);
                                                                      ^

TypeError: Cannot read property 'activeElement' of undefined
    at Timeout._onTimeout (/Users/eliperkins/src/downshift/dist/downshift.native.cjs.js:1035:71)
    at ontimeout (timers.js:427:11)
    at tryOnTimeout (timers.js:289:5)
    at listOnTimeout (timers.js:252:5)
    at Timer.processTimers (timers.js:212:10)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I'm out of time to look at this further tonight, but I'd say we've got some pretty hairy version mismatches to unwind here, along with a wee bit of platform mismatch in usage of things like document for certain platforms.

If someone wants to pick this up before me, feel free! Otherwise, I can pick this up at my next free moment.