Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Track: HTTP client support on React Native for Android and iOS #3404

Closed
43 of 51 tasks
acostalima opened this issue Nov 17, 2020 · 16 comments
Closed
43 of 51 tasks

Track: HTTP client support on React Native for Android and iOS #3404

acostalima opened this issue Nov 17, 2020 · 16 comments
Assignees
Labels
awesome endeavour kind/maybe-in-helia P2 Medium: Good to have, but can wait until someone steps up

Comments

@acostalima
Copy link

acostalima commented Nov 17, 2020

HTTP client - January 18-29 ⌛

React Native Test Runner - January 4-8 ✅

A CLI tool in line of what @hugomrdias has done with playright-test but for React Native. The first version includes support for Zora test runner.

Repo: https://github.com/acostalima/react-native-test-runner

  • Concept validation: use React Native's bundler, Metro, to report test results from an iOS or Android app to a Node process.
  • Find iOS simulator by name and OS version
  • Start/stop headless iOS simulador
  • Install/launch iOS app on simulator
  • Build iOS app in debug mode programatically
    • Tools: xcodebuild, pod
    • Output binary location: ??
  • Metro bundler: server.close() hangs after an app connects to the server and then when it's terminated
  • Fix Zora's exports in package.json for React Native
  • Find Android emulator by name and OS version
  • Build Android app in debug mode programatically
    • Tools: gradlew
    • Output binary location: ??
  • Install/launch Android app on emulator
    • Tools: adb, emulator, avdmanager
  • Start/stop headless Android emulator
  • CLI
  • Tests
  • Add README
  • Setup CI pipeline in GitHub Actions
    • Android job
    • iOS job
    • Android cache
    • iOS cache
    • npm cache
  • Use react-native init to initialize a new React Native app instead and distributing it
    • When the test runner is installed as dev dependency, React Native itself and its dependencies may be hoisted
    • There are files in the Android and iOS projects that expect React Native, its CLI and Metro to be available at the top level node_modules directory by hardcoded relative path look ups (e.g. ../node_modules/react-native). As such, the Android and iOS projects cannot be packaged and released to npm.
    • Accept a CLI option to pass React Native semver to use
    • Create/delete RN test app directory
    • Make RN and Metro requires relative to RN's test app directory
    • Use default package name and bundle ID defined by react-native init for Android and iOS respectively to launch the apps
    • Check whether Babel config file needs to be copied to the RN test app's directory

References & Inspiration

Fetch API - January 8-15 ✅

Technical discussion: react-native-community/fetch#4

React Native - January 18-22 ⌛

Related work

Jet by Invertase

Jet lets you bring your React Native JS code into NodeJS and test it mock free and native testing code free - ideal for testing React Native modules e2e.

The developers behind React Native Firebase. Currently, the project is a PoC and does not have a dedicated GitHub repo.

Blob download/upload

@acostalima acostalima added the need/triage Needs initial labeling and prioritization label Nov 17, 2020
@acostalima
Copy link
Author

acostalima commented Nov 17, 2020

Having tests running in React Native will be tricker than I initially expected. I had a look at Detox a couple of weeks ago and I was under the impression it allowed to run any kind of tests in React Native's environment. However, I had a deeper look most recently and Detox's architecture and inner workings and it turns out it's not possible at all.

Detox supports test runners such as Mocha and Jest, but they actually run in a separate Node process, external to the app's runtime. Detox's assertions and matchers communicate with the app back and forth through a web socket and such APIs are designed exclusively for UI testing. Therefore, we will not be able to use Detox to run Fetch's tests.

I was not able to find anything else out there in open source that achieves what we're looking for, i.e. having tests actually running in a React Native app just like Playwright does so in the web counterpart. Thus, we have to come up with something of our own.

The first step is to explore how to have Mocha running in React Native (eventually discuss this with Mocha's team as well). I did have a quick shot at it yesterday, but I got a bunch of errors so I'll have to go in deeper. If Mocha reveals to be quite problematic in this regard, I can try with something more simpler, such as Tape.

The second step is to design a solution to extract test results out of the app. A HTTP server should do, since we only need unidirectional communication where the app is the client. Once the JS kicks in upon app startup, the test runner would start immediately.

The third and last step is to orchestrate the whole thing with a Node process: build the app, start te app, setup the server, signal the server that the tests are about to run, wait for the tests to run to completion, send the results and report them.

@hugomrdias
Copy link
Member

try https://github.com/lukeed/uvu or https://github.com/lorenzofox3/zora these should be simpler to integrate in rn and wrap with something similar to playrwright-test for rn.

@acostalima
Copy link
Author

@hugomrdias thanks! 💪

@achingbrain achingbrain added awesome endeavour and removed need/triage Needs initial labeling and prioritization labels Dec 3, 2020
@acostalima
Copy link
Author

@autonome there has been a minor setback with regards to the developments of the test runner for RN. I had a discussion with @hugomrdias today, and we concluded that some changes are necessary to make it work properly when using the runner as a dependency (details above). It will require a bit more work but it's nothing to be concerned about. 😉

@hugomrdias
Copy link
Member

@autonome when @acostalima updates the OP you probably don't get a notification, we can setup a different process to make sure you get a ping about updates.

@jacobheun
Copy link
Contributor

Adding #3076 for tracking as well

@acostalima
Copy link
Author

acostalima commented Jan 6, 2021

Finishing up the changes me and @hugomrdias agreed on in order to avoid packaging and distributing the test app to npm: acostalima/react-native-test-runner#2. The tests are passing locally, but failing on CI at the moment. I'm currently fixing this. Fixed!

@acostalima
Copy link
Author

acostalima commented Jan 11, 2021

This week:

  • Finish fetch's test suite, update README and publish v1.0.0.
  • Squeeze in a couple of PRs to React Native.

@acostalima
Copy link
Author

The Fetch implementation for React Native is ready for v1.0.0 release. Meanwhile, I've asked Christoph from Facebook to give me permissions to publish the package in react-native-community scope.

CC @autonome

@acostalima acostalima changed the title Track: HTTP client support on React Native Track: HTTP client support on React Native for Android and iOS Jan 14, 2021
@acostalima
Copy link
Author

acostalima commented Jan 18, 2021

Last week

  • Updated demo app repo, in particular the contents of the README to better explain how to properly setup an app to use the HTTP client for the time being given the known limitations and issues.
  • Concluded fetch's test suite and updated the README. The publication of v1.0.0 remains pending until I am granted permission to publish the package under react-native-community's scope.
  • Updated polyfill globals repo to remove a few no longer necessary patches and add the setup to polyfill React Native's environment with the alternative fetch implementation.
  • Started to work on the changes to submit to React Native's repo.

This week

  • Submit PRs to React Native, namely:
    • Implement .set method in FormData.
    • Make FormData.getParts capable of handling Blobs.
    • Implement FileReader.readAsArrayBuffer.
  • Submit PR to HTTP client to enable text streaming on fetch for React Native via custom option.
  • Investigate whether/how mocha can be used in React Native's runtime.

CC @autonome

@acostalima
Copy link
Author

acostalima commented Jan 25, 2021

Last week

This week

CC @autonome

@acostalima
Copy link
Author

acostalima commented Feb 1, 2021

Last week

  • PRs to complete the integration of the HTTP client runtime and test suite in React Native are ready for peer review.

Next

  • Waiting for peer review and support to complete the work on IPFS end @hugomrdias.
  • Waiting for peer review on PRs submitted to React Native.

CC @autonome

@rikur
Copy link

rikur commented Mar 28, 2021

This looks very promising, thank you @acostalima! As it may take a while to get any feedback from RN team, I'd like to ask if this is currently usable with the polyfills/patches?

@acostalima
Copy link
Author

acostalima commented Mar 28, 2021

@rikur yes, you should be able to use most methods of the HTTP client with the available polyfills and patches. Have a look at https://github.com/ipfs-shipyard/react-native-ipfs-demo to see how to make it work.

Note that I'm not sure whether the patch available at https://github.com/acostalima/react-native-polyfill-globals/blob/master/patches/react-native%2B0.63.3.patch can be applied to RN versions in the range <0.63.3 >=0.64.0. I know for sure the patch is compatible with 0.63.3 and 0.63.4.

If you run into any issues, please let me know. 💪

@lidel lidel added the P2 Medium: Good to have, but can wait until someone steps up label Jun 7, 2021
@Haianh9999
Copy link

Haianh9999 commented Sep 23, 2022

@BigLep
Currently ipfs-http-client can work properly with react native yet?. I tried the latest version and got the error 🙇

@SgtPooki
Copy link
Member

js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide.

Please feel to reopen with any comments by 2023-06-02. We will do a final pass on reopened issues afterward (see #4336).

@Haianh9999 note that I'm pushing for getting an example using react-native in Helia. I posted a comment at ipfs/helia#43 (comment), please feel free to contribute an example if you get time!

@github-project-automation github-project-automation bot moved this from 🛑 Blocked to ✅ Done in js-ipfs deprecation May 26, 2023
@github-project-automation github-project-automation bot moved this from Next to Done in IP JS (PL EngRes) v2 May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awesome endeavour kind/maybe-in-helia P2 Medium: Good to have, but can wait until someone steps up
Projects
No open projects
Status: Done
Development

No branches or pull requests

8 participants