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

Api bzz react native #98

Merged
merged 15 commits into from
Aug 8, 2019
Merged

Conversation

vmaark
Copy link
Contributor

@vmaark vmaark commented Jun 21, 2019

Changes

Implements partial support for react-native, for the bzz functionality in particular. Related issue #52
There are 2 differences compared to api-bzz-browser:

  • the URL type is used for other purposes in react-native, so in the implementation we have to depend on a URL type provided by universal-url
  • Blob and FormData has some differences in react-native and typing issues (both in flow and TypeScript), this had to be resolved as well

Todo

Run tests in detox, or other method which is closer to react-native then node / browser.

This is a draft PR, I opened it to make further discussions easier.

I had some tests failing locally:
FAIL tests/timeline.js
● Test suite failed to run

FAIL tests/api-bzz-node.js
● api-bzz-node › encountered a declaration exception

ReferenceError: URL is not defined

@PaulLeCam
Copy link
Collaborator

Thanks for your PR!
Regarding the errors running tests, are you using node v10+ please? I think older versions don't expose the URL class globally.

@vmaark
Copy link
Contributor Author

vmaark commented Jun 24, 2019

damn nvm :) I was running the tests on another tab with v8.9.0.
Btw I noticed that there are commands which exit with an error if you are using node <v10, but some aren't.

@PaulLeCam
Copy link
Collaborator

I think some tests probably have dangling timers (notably when testing subscriptions) that aren't cleared when an error is thrown, I'll try to go through these when I have the chance.

@vmaark
Copy link
Contributor Author

vmaark commented Jul 20, 2019

Hi, I was thinking about how to move forward. I can create a simple react-native application, where we can run functionally the same tests as in the browser test suite, I'm just wondering what would be the best setup from the repository and the CI/CD point of view. I can imagine the following setups:

  • the react-native test up is a package in this repo, making any changes to the repo would trigger running those tests as well
  • the react-native app and the tests are in a separate repo, and the erebos build should trigger its test-suite
  • the react-native app is in a sepearate repo, the tests are in erebos, and somehow we load it in the react-native app

The first one is the most straightforward, but I'm not sure if you want to put a relatively heavy sub-project (the most basic react-native app) to this repo.
The second one needs some additional work regarding CI/CD, but I'm not sure about Mainframe's setup, maybe it's something you already are doing with some other projects. Another downside to consider is that the tests are in a separate repo, which should be updated when there is new functionality to erebos.
The third one might be technically difficult, without further investigation I'm not sure if it can be achieved easily.

@PaulLeCam
Copy link
Collaborator

Hey, thanks for looking into this!

I agree that the first option is likely the simplest setup.
I don't mind adding the react-native dependencies in the repository if it's needed for tests anyways, as long as it doesn't prevent installation on any platform (so running yarn install on Windows should work even if iOS tests couldn't be run on Windows).

For CI currently we're using Circle but it doesn't have a free macOS plan (which I assume is needed to test iOS?), so I'm thinking about switching to Travis or Azure Pipelines, do you have any recommendation please?
Thanks!

@vmaark
Copy link
Contributor Author

vmaark commented Jul 22, 2019

We are using Travis, sometimes we saw XCode builds fail in a non-reproducible way, but it was rare, and haven't seen it in a while either. I'll have a look at creating the app in the coming weeks.

@PaulLeCam
Copy link
Collaborator

Great, thanks!
I'll try to move our current CI setup from Circle to Travis if I have time this week, it should simplify the process.

Also FYI I started rewriting Erebos in TypeScript so it may affect your changes, here is the current changelog: https://github.com/MainframeHQ/erebos/blob/typescript/CHANGELOG.md#v090-unreleased
I was planning on releasing v0.9 with this rewrite once typescript-eslint v2 is released with eslint v6 support, but if support for React-Native is around the corner I think it makes sense to include it in v0.9 as well, what do you think?

@vmaark
Copy link
Contributor Author

vmaark commented Jul 23, 2019

Sure! Happy to hear you are moving to TypeScript!

@PaulLeCam
Copy link
Collaborator

Thanks!
I added the Travis config to https://github.com/MainframeHQ/erebos/blob/master/.travis.yml please feel free to edit as needed to make it work for React-Native integration tests!

@vmaark vmaark marked this pull request as ready for review August 6, 2019 19:29
Copy link
Collaborator

@PaulLeCam PaulLeCam left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!
Beyond the few questions below, it seems the types/index.d.ts from api-bzz-browser has been moved to api-bzz-react-native, while both packages should probably have it, could you fix this as well please?
Thanks!

"universal-url": "^2.0.0"
},
"devDependencies": {
"flow-bin": "^0.101.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you remove this dependency now that the project uses TypeScript please?

export class Bzz extends BaseBzz<Response> {
public constructor(config: BzzConfig) {
const { url, ...cfg } = config
super(window.fetch.bind(window), { ...cfg, url: new URL(url).href })
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this use global instead of window?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is needed, fetch is available globally in react-native, should we just pass in fetch?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure in RN but on the Web it needed to be bound to the proper context, there was some issue without.

packages/timeline/types/index.d.ts Outdated Show resolved Hide resolved
yarn.lock Outdated Show resolved Hide resolved
@PaulLeCam PaulLeCam merged commit db34150 into MainframeOS:master Aug 8, 2019
@PaulLeCam
Copy link
Collaborator

Thanks!

@PaulLeCam PaulLeCam mentioned this pull request Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants