Detox Port

Created on 26 Apr 2018  路  7Comments  路  Source: wix/Detox

Description

Very simply, my company has some kind of admin process (most likely a virus scanner) running on port 8081. This is a problem, because in order to run detox I need to go into the project and change every internal reference to 8088 (just some other random port I can use).

When I run react-native run-ios I get the option to pass flag --port=8088 to it so I don't need to manually configure those files. Does Detox have such a flag? Manually changing each port works, but on update / project copy, it has to be redone, which is error prone.

Steps to Reproduce

Block port 8081.
Try to run detox build

Detox, Node, Device, Xcode and macOS Versions

Detox: 7.3.4
OS: macOS Sierra 10.12.6
Node: 9.5.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.9.0
react: ^16.3.0-alpha.1 => 16.3.1
react-native: 0.54.4 => 0.54.4
Xcode: Xcode 9.2 Build version 9C40b
Android Studio: 3.1 AI-173.4670197

Most helpful comment

@noomorph , he refers to the packager port.
react-native cli has support for running the both the packager and the app on different ports for debug builds.

All it requires is running the build command with RCT_METRO_PORT as env variable.

I think running detox commands with this env var set will solve your problem.

RCT_METRO_PORT=8099 detox build {params}
RCT_METRO_PORT=8099 detox test {params}

All 7 comments

As an addendum, can I just build with react-native run-ios --port=8088 and then have detox use that build on the correct port when I run detox test?

Edit: tried this. It works, but it unfortunately opens two simulators and closes neither upon completion.

@Rob117 if it helps in the interim, I use https://www.npmjs.com/package/patch-package to automatically patch files in node_modules - it has a postinstall hook that will auto patch on npm/yarn install - I use this on a few react native projects myself - and a lot of other people do as well. You could use this to change the ports in node modules and then create a patch and commit that patch file as part of your git repo - until you can actually change the port in detox.

@Salakar Absolutely awesome, will try as a stopgap until we can hopefully get a port feature!

@Rob117, I am not sure whether Detox indeed has port 8081 hard-coded. Let's see:

git clone [email protected]:wix/detox.git
cd detox
git grep 8081

The only occurrence it prints is here, but this is just a test app for Detox E2E runs on CI:

detox/test/ios/example/AppDelegate.m:   jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];

Did I overlook something? Could you point, please? As far as I understand it now, Detox doesn't use 8081 port specifically.

@noomorph , he refers to the packager port.
react-native cli has support for running the both the packager and the app on different ports for debug builds.

All it requires is running the build command with RCT_METRO_PORT as env variable.

I think running detox commands with this env var set will solve your problem.

RCT_METRO_PORT=8099 detox build {params}
RCT_METRO_PORT=8099 detox test {params}

I wonder if we can close this one?

The proposed solution works for me; absolutely. Marking as closed,

Was this page helpful?
0 / 5 - 0 ratings