0

I was wondering if it's possible to have different apps being built out of a single repo in React Native. The reason I'm trying to do this would probably be a huge edge case, but it's basically for unit testing RN modules that I'm developing.

I know I can unit test individual components using Enzyme, but I have some modules that are part of a whole framework, and I need to do end-to-end unit tests on them. So my thinking is that I should build the app and run unit tests on it with Appium. But what if there are multiple unit tests? I guess we would need to build multiple separate apps? But there's only one index.js file.

I was reading that I could set up some app targets and schemes (iOS) and equivalent stuff in Android. But how would I handle that on the RN side? Where can I specify which .js file is the entry point for each target? And how does RN handle building different targets?

https://www.dev6.com/frameworks/building-multiple-apps-from-one-react-native-project/ Read this article about setting up multiple schemes and using those to set environment variables that could influence control flow in the app. However, this would mean that I would have to run the unit tests in serial, loading the same app up over and over with different env (not the end of the world, I guess).

I was thinking that if I had multiple index.js files, one for each unit test, I could maybe set up some separate app targets/schemes and use those, but I guess I would have to figure out how to build and run them concurrently for concurrent unit testing. I think that the react-native run-ios and run-android commands just build a single app though, so I'm not sure how I'd fit that into my unit testing workflow.

Any thoughts on this strategy or other possible strategies would be very welcome! Thanks :)

nerdlinger
  • 1,610
  • 2
  • 17
  • 24

1 Answers1

1

Not a concrete answer but speaking of approach, you will need multiple native iOS/android app targets, multiple app/bundle IDs to have multiple instances of application running at the same time, may be below references can help -

  1. Create different app targets - https://gist.github.com/jacks205/45b2721bf2a2b912b1c130aef2572820
  2. Provide unique app/bundle identifier to each target - Get Bundle ID from a different target
  3. Utilize multiple targets for react native project - https://medium.com/@jacks205/adding-multiple-target-pipelines-for-react-native-apps-and-fastlane-circleci-deployment-pt-1-ae9590ae52f2
Atul
  • 698
  • 4
  • 13