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

Use unmock on device in development #3

Merged
merged 12 commits into from Dec 20, 2019
Merged

Use unmock on device in development #3

merged 12 commits into from Dec 20, 2019

Conversation

@ksaaskil
Copy link
Contributor

ksaaskil commented Dec 12, 2019

  • Example of using unmock in running on-device in React Native. In development, where NODE_ENV==="development", switches on Unmock to mock the Cat Facts API.
  • Uses unmock from unmock-browser: this seems to be a safer bet than using unmock package, because using that seems to mess things up when running a development server. unmock-browser only overrides global.fetch or window.fetch and cannot have weird sife-effects of messing up other Node.js stuff (might be worth checking if this can be fixed by adding react-native field in the package.json of unmock

Tricks this required:

  • global.Buffer needs to be poly-filled with require('buffer').Buffer: facebook/react-native#23922 (comment) Implemented in unmock/unmock-js#359
  • json-schema-ref-parser depends on http, https and url so metro bundler fails building the project because http, https and url cannot be resolved. The manual fix is to edit node_modules/json-schema-ref-parser/package.json and add http: false and https: false in its browser field (apparently the modules are not needed by unmock-core). The problem with url can be similarly by adding url: false or, preferably, "url": "whatwg-url" Implemented in unmock/unmock-js#360

Future stuff:

  • Running tests in the virtual device using Unmock?
  • Adding a component for switching Unmock on and off?
  • Adding CircleCI integration
@ksaaskil ksaaskil mentioned this pull request Dec 17, 2019
@ksaaskil ksaaskil changed the title Use unmock in development. Use unmock on device Dec 20, 2019
@ksaaskil ksaaskil added this to In progress in Unmock Road Map Dec 20, 2019
@ksaaskil ksaaskil changed the title Use unmock on device Use unmock on device in development Dec 20, 2019
@ksaaskil ksaaskil merged commit 19cf883 into master Dec 20, 2019
@ksaaskil ksaaskil deleted the add-unmock branch Dec 20, 2019
@ksaaskil ksaaskil moved this from In progress to Done in Unmock Road Map Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
1 participant
You can’t perform that action at this time.