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

Add environ for device.launchApp #376

Closed
fangpenlin opened this issue Oct 27, 2017 · 6 comments
Closed

Add environ for device.launchApp #376

fangpenlin opened this issue Oct 27, 2017 · 6 comments

Comments

@fangpenlin
Copy link

For now, we can launch the app with launchArgs

await device.launchApp({launchArgs: {arg1: 1, arg2: "2"}});

but in many cases, it's easier to pass in environment variables, like this

await device.launchApp({environ: {API_URL: 'http://localhost:3000'}});

as launchArgs require parsing, while environment variable can be read directly with simple key. So I think it would be nice to add support for launching the app with environment variables.

@LeoNatan
Copy link
Contributor

What is your use case here?
Remember, with Detox you should be testing your app as close to what the user experience is. The user cannot set environment variables (or launch arguments).

@fangpenlin
Copy link
Author

@LeoNatan the use case we had at Envoy is, we sometimes needs to set a different configuration value for testing purpose, such as API_URL mentioned above, which is a perfect example. Surely user cannot set the environment variable, nor change the launch arguments, but the problem is just because so, we cannot change things like API_URL to a local API server that servers mock API endpoints via user interface, we need to change it via environment or launch argument.

@fangpenlin
Copy link
Author

Besides API, there is also stuff we need to mock via feeding a different environment variable to the app. For example, our Envoy sign-in app supports badge printing, to test the badge printer, there is no way we make the iPad really print the badge out and somehow ensure the badge printing is correct.

In that case, we will need to feed in an environment variable telling the app to use a mock printer module, and talk to our local HTTP server instead, and the HTTP server is running with our tester, so that we can check the parameters sending to the mock printer server, and we can see if it's working as expected. Like this

BADGE_PRINTER_TYPE=MOCK
BADGE_PRINTER_HOST=http://localhost:4567

Likewise, we have to mock PubNub, that's also done with a mock API server doing long polling.

For more details, we have a blog post for it

https://envoy.engineering/embedded-web-server-for-ios-ui-testing-8ff3cef513df

Anyway, in short, that's not for user interaction, it's more for changing the configuration to make some untestable thing testable for our use case.

@wix wix deleted a comment from rotemmiz Oct 30, 2017
@LeoNatan
Copy link
Contributor

We have a mocking recommendation, but unfortunately it is only supported on a very old RN version (0.44). Hang in there.

@fangpenlin
Copy link
Author

@leeor besides mocking, we also have use case for operations such as resetting key chain, for example, before certain test case, we want to reset the key chain, then we pass in

RESET_LOGIN=1

when the app reads this part, it will clear the key chain before launching the app. We can also set some variable, like access key

ACCESS_KEY=MOCK_ACCESS_KEY

As for our use case, it's not possible to reset key chain via user interface, we do have reset login, but that needs to be done via a toggle in Settings app.

@LeoNatan
Copy link
Contributor

Any reason not to use launch arguments? There is a similar API you can use to test whether a launch argument exists.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants