Configuration
React Native Harness can be configured through a configuration object that defines various aspects of your testing setup.
The most basic configuration would, assuming you support both iOS and Android platforms, look like this:
rn-harness.config.mjs
Entry Point and App Component
React Native Harness needs to know how to locate and integrate with your React Native app.
entryPoint
The path to your React Native app's entry point file.
appRegistryComponentName
The name of the component registered with React Native's AppRegistry.
For Expo projects, the entryPoint should be set to the path specified in the main property of package.json. The appRegistryComponentName is typically set to main for Expo apps.
All Configuration Options
Test Runners
A test runner defines how tests are executed on a specific platform. React Native Harness uses platform-specific packages to create runners with type-safe configurations.
For detailed installation and configuration instructions, please refer to the platform-specific guides:
Default Runner
When you have multiple runners configured, you can specify which one to use by default when no runner is explicitly specified in the CLI command.
If no defaultRunner is specified, you must explicitly provide the --harnessRunner flag when running tests:
Bridge Timeout
The bridge timeout controls how long React Native Harness waits for communication between the test runner and the React Native app. This is particularly important for slower devices or complex test setups.
Default: 60000 (60 seconds) Minimum: 1000 (1 second)
Increase this value if you experience timeout errors, especially on:
- Slower devices or simulators
- Complex test suites with heavy setup
Bundle Start Timeout
The bundle start timeout controls how long React Native Harness waits for Metro to start bundling after the app is restarted. This timeout is used in conjunction with the app restart mechanism to detect when an app has failed to report ready.
Default: 15000 (15 seconds) Minimum: 1000 (1 second)
This timeout works with the maxAppRestarts setting to automatically restart the app when it fails to communicate with the test harness. If no bundling activity is detected within this timeout period, the app will be restarted automatically.
Maximum App Restarts
The maximum app restarts setting controls how many times React Native Harness will attempt to restart the app when it fails to report ready within the configured timeout periods.
Default: 2 Minimum: 0
When set to 0, automatic app restarting is disabled. Higher values provide more resilience against flaky test environments but may increase test execution time. The app will be restarted when:
- No bundling activity is detected within the
bundleStartTimeoutperiod - The bridge fails to establish communication within the
bridgeTimeoutperiod
Web Socket Port
The port used for the WebSocket bridge communication between the CLI and the device.
Default: 3001
Change this if port 3001 is already in use on your system.
Environment-Specific Configurations
You can create different configurations for different environments:
rn-harness.config.mjs
Coverage Root
The coverage root option specifies the root directory for coverage instrumentation in monorepository setups. This is particularly important when your tests run from a different directory than where your source files are located.
Default: process.cwd() (current working directory)
This option is passed to babel-plugin-istanbul's cwd option and ensures that coverage data is collected correctly in monorepo scenarios where:
- Tests run from an
example/directory but source files are in../src/ - Libraries are structured with separate test and source directories
- Projects have nested directory structures that don't align with the current working directory
Without specifying coverageRoot, babel-plugin-istanbul may skip instrumenting files outside the current working directory, resulting in incomplete coverage reports.
Set coverageRoot when you notice 0% coverage in your reports or when source files are not being instrumented for coverage. This commonly occurs in create-react-native-library projects and other monorepo setups.
