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

import {
  androidPlatform,
  androidEmulator,
} from '@react-native-harness/platform-android';
import {
  applePlatform,
  appleSimulator,
} from '@react-native-harness/platform-apple';

const config = {
  entryPoint: './index.js',
  appRegistryComponentName: 'App',

  runners: [
    androidPlatform({
      name: 'android',
      device: androidEmulator('Pixel_8_API_35'),
      bundleId: 'com.yourapp',
      appLaunchOptions: {
        extras: {
          launch_mode: 'test',
        },
      },
    }),
    applePlatform({
      name: 'ios',
      device: appleSimulator('iPhone 16 Pro', '18.0'),
      bundleId: 'com.yourapp',
      appLaunchOptions: {
        arguments: ['--mode=test'],
      },
    }),
  ],
};

export default config;

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.

{
  entryPoint: './src/main.tsx',
}

appRegistryComponentName

The name of the component registered with React Native's AppRegistry.

// In your app's entry point
import { AppRegistry } from 'react-native';
import App from './App';

AppRegistry.registerComponent('MyApp', () => App);
// In your rn-harness.config.mjs
{
  appRegistryComponentName: 'MyApp',
}
Expo

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

OptionDescription
entryPointRequired. Path to your React Native app's entry point file.
appRegistryComponentNameRequired. Name of the component registered with AppRegistry.
runnersRequired. Array of test runners (at least one required).
pluginsArray of Harness plugins to run during the test lifecycle.
defaultRunnerDefault runner to use when none specified.
hostHostname or IP address to bind the Metro server to (default: Metro default).
metroPortPreferred port used by Metro and Harness bridge traffic (default: 8081). Harness falls back to the next available port when this one is already in use.
webSocketPortDeprecated. Bridge traffic now uses metroPort; this option is ignored.
platformReadyTimeoutPlatform-ready timeout in milliseconds (default: 300000).
bridgeTimeoutBridge timeout in milliseconds (default: 60000).
testTimeoutRuntime timeout for each test case and suite hook in milliseconds (default: 5000). Harness config takes precedence over Jest testTimeout.
bundleStartTimeoutBundle start timeout in milliseconds (default: 60000).
maxAppRestartsMaximum number of automatic app relaunch attempts while Harness is waiting for startup (default: 2).
eagerPrewarmStart building the Metro bundle while the platform is still booting so the first bundle is ready sooner (default: true).
permissionsEnable platform-specific permission prompt automation (default: false). On iOS, this controls whether Harness starts the XCTest-based permission helper.
resetEnvironmentBetweenTestFilesHow to reset the environment between test files: true/'process' restarts the app process (default), 'runtime' reloads the JS runtime in place (falling back to a process restart on failure), false disables resetting.
detectNativeCrashesDetect native app crashes during startup and test execution (default: true).
crashDetectionIntervalInterval in milliseconds to check for native crashes (default: 500).
disableViewFlatteningDisable view flattening in React Native (default: false).
coverageCoverage configuration object.
coverage.rootRoot directory for coverage instrumentation (default: process.cwd()).
coverage.native.ios.podsExperimental list of CocoaPods target names to instrument for iOS native coverage.
forwardClientLogsForward console logs from the app to the terminal (default: false).
diagnosticsRecord a timing trace and resource metrics for the run: true, or an object with enabled, probes and sampleIntervalMs (default: false). See Diagnostics.
cacheCache configuration object.
cache.metroEnable persistent Metro transform and file-map caching under .harness/cache (default: true).
cache.versionUser-controlled salt folded into the Metro cache version. Bump it to force-invalidate previously cached transforms.
unstable__enableMetroCacheDeprecated. Use cache.metro instead.

Test Runners

Metro Port Fallback

Harness treats metroPort as the preferred starting port. If that port is already in use, Harness tries the next available ports automatically and logs the port it selected for the run.

Physical iOS devices are the exception: they always use the default Metro port and do not support custom or fallback ports.

When multiple Harness runs target the same device, simulator, emulator, or browser configuration, Harness waits for the existing run to finish before starting the next one.

When a run finishes, Harness clears platform-specific dev settings it applied for the session (for example the Android debug HTTP host override and the iOS simulator JS location override) so your next normal Metro or dev-client launch is not stuck pointing at Harness's port.

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.

Runner-specific launch options belong inside each runner config via appLaunchOptions. They are passed whenever Harness launches or relaunches the app for that runner.

For @react-native-harness/platform-web, browser launch options such as ignoreDefaultArgs belong on the browser config passed to chromium, chrome, firefox, or webkit.

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.

import {
  androidPlatform,
  androidEmulator,
} from '@react-native-harness/platform-android';
import {
  applePlatform,
  appleSimulator,
} from '@react-native-harness/platform-apple';

const config = {
  runners: [
    androidPlatform({
      name: 'android',
      device: androidEmulator('Pixel_8_API_35'),
      bundleId: 'com.myapp',
    }),
    applePlatform({
      name: 'ios',
      device: appleSimulator('iPhone 16 Pro', '18.0'),
      bundleId: 'com.myapp',
    }),
  ],
  defaultRunner: 'android', // Will use Android runner by default
};

If no defaultRunner is specified, you must explicitly provide the --harnessRunner flag when running tests:

# With default runner set (uses the runner specified in defaultRunner)
react-native-harness

# Without default runner (explicit runner required)
react-native-harness --harnessRunner android
react-native-harness --harnessRunner ios

Platform Ready Timeout

Permissions

Use the permissions flag to opt into Harness-managed permission prompt handling.

{
  permissions: true,
}

Default: false

When permissions is false, Harness does not start platform-specific permission automation helpers. On iOS that means no XCTest agent session is started for permission auto-accept. Physical iOS devices still require device.codeSign in the runner config when you set permissions: true.

The platform ready timeout controls how long React Native Harness waits for the selected device, simulator, or emulator to become usable. This includes device discovery, simulator or emulator boot, and platform runtime setup before the app is launched.

{
  platformReadyTimeout: 300000,  // 5 minutes in milliseconds
}

Default: 300000 (5 minutes) Minimum: 1000 (1 second)

Increase this value if you experience startup failures while:

  • Booting cold simulators or emulators
  • Starting devices in slower CI environments

Bridge Timeout

The bridge timeout controls the app-side bridge readiness window after Harness launches the app. It does not include simulator or emulator boot time.

Once the app is connected, Harness checks two things while tests run:

  • The connection. The app's WebSocket must keep answering pings. It answers them natively, even while JavaScript is busy, so a failure here means the app was killed, froze, or lost its network connection.
  • The JS thread. The app's JS thread may be blocked, for example by synchronous work in a test, for as long as the current step allows: testTimeout plus 5 seconds while a test or a beforeAll/afterAll hook runs, bundleStartTimeout while a setup file or test file loads, and 20 seconds otherwise. If it stays blocked longer, the run fails with an error naming the test, hook, or file. Harness enforces this from the CLI, so testTimeout also applies to tests that block the JS thread, which a timer inside the app cannot do.

Harness uses bridgeTimeout while waiting for the app runtime to connect, and as the timeout for shorter bridge RPCs such as screenshots or image snapshot matching.

{
  bridgeTimeout: 120000,  // 2 minutes in milliseconds
}

Default: 60000 (60 seconds) Minimum: 1000 (1 second)

Increase this value if Harness times out before the app runtime reports ready, especially on:

  • Slower app startup after launch
  • Apps that take longer to load the Metro bundle and initialize the Harness runtime

Test Timeout

The test timeout controls how long the runtime allows each test case and suite hook to run before reporting a timeout failure.

{
  testTimeout: 30000,
}

Default: 5000 (5 seconds) Minimum: 1000 (1 second)

Harness testTimeout takes precedence over Jest's testTimeout setting so runtime timeout behavior lives next to the rest of your Harness configuration.

Bundle Start Timeout

The bundle start timeout controls how long React Native Harness waits for the launched app to request its Metro bundle.

{
  bundleStartTimeout: 120000,
}

Default: 60000 (60 seconds) Minimum: 1000 (1 second)

Startup Recovery

Harness can retry app startup automatically when the app fails to come up cleanly during launch.

{
  maxAppRestarts: 2,
}

Default: 2 Minimum: 0

Increase this value if your app occasionally needs another launch attempt before it reaches a ready state, especially in slower CI environments.

Set it to 0 if you want startup failures to fail immediately without any automatic retry.

Diagnostics

Diagnostics record where a run spends its time and how loaded the machine is while it does. They are most useful on slow or flaky CI runners, where you need data to tell a slow simulator boot from a slow bundle or an overloaded host.

Turn them on with diagnostics: true, or set RN_HARNESS_DIAGNOSTICS=1 for a single run without touching your config. Pass an object to tune what is collected:

{
  diagnostics: {
    probes: {
      host: true, // load, CPU split and memory pressure of the machine
      node: true, // memory and event loop lag of the Harness process
      snapshots: true, // process listing at run milestones (macOS only)
      platform: true, // platform-specific data, such as the process count inside an iOS simulator
    },
    sampleIntervalMs: 5000,
  },
}

With the object form, diagnostics are on unless you set enabled: false. Every probe is on by default, and sampleIntervalMs defaults to 5000 (minimum 250). Nothing is started, sampled or written when diagnostics are off.

What is recorded

Besides timings for session setup, Metro bundling, app startup and each test file, Harness samples these metrics every sampleIntervalMs:

MetricMeaning
host.load1One-minute load average.
host.cpu.user_pct, host.cpu.sys_pct, host.cpu.idle_pctHow the machine's CPU time was split since the previous sample.
host.mem.free, host.mem.compressed, host.mem.demand (MB)macOS memory pressure. demand is anonymous + wired + compressed memory, the part the OS cannot simply reclaim.
host.mem.swapouts, host.mem.compressions (MB)Cumulative memory swapped out or compressed since boot. A rising swapouts during a run means the machine is out of memory.
node.rss_mb, node.heap_used_mbMemory of the Harness process.
node.event_loop.p50_ms, node.event_loop.p99_ms, node.event_loop.max_msHow late Harness's own timers fire. Large values mean the machine is too busy to schedule work.

On macOS, Harness also records a process listing (telemetry.process_snapshot, the 40 largest processes by memory plus the total process count as host.process_count) when the platform becomes ready, the first time the app becomes ready, and at the end of the run (later app relaunches are not listed again, to keep sampling cheap). For iOS simulators it records platform.ios.simulator.guest_process_count, the number of processes running inside the simulator, at platform ready and at the end of the run, and the platform.ios.simctl.waitForBoot span carries the last boot stage reported by the simulator (bootLastStatus), which shows what a slow or timed-out boot was waiting on.

Output

Everything is written to .harness/diagnostics/ in your project root:

FileContents
<sessionId>.jsonlOne entry per line, written while the run is in progress (and when the process exits), so a job that is cancelled or times out still leaves its data behind.
<runId>.jsonA Chrome Trace Event file written when the run finishes. Open it in Perfetto to see the timeline and a graph for each sampled metric.
<runId>.summary.jsonThe key numbers of the run, for comparing runs: boot wait, time to ready, peak load, peak compressed memory, minimum free memory, memory swapped out, longest event loop lag, number of test files and the result. A value that could not be measured is null.

Sampling is paused between runs in watch mode, so idle time does not show up in a run's metrics. Entries recorded while the session shuts down (the end-of-run process listing, for example) are added to the trace of the last run; the key numbers cover the run itself.

The same key numbers are printed at the end of the run. When running in GitHub Actions, they are also added to the job summary as a table.

Plugins

You can register Harness plugins with the plugins option.

import { definePlugin } from '@react-native-harness/plugins';

const loggingPlugin = definePlugin({
  name: 'logging-plugin',
  hooks: {
    run: {
      started: async (ctx) => {
        ctx.logger.info('Starting run', ctx.runId);
      },
    },
  },
});

export default {
  // ...
  plugins: [loggingPlugin],
};

Use plugins for project-specific logging, artifact collection, reporting, or workflow automation. See the Plugins guide for more.

Environment-Specific Configurations

You can create different configurations for different environments:

rn-harness.config.mjs

import {
  androidPlatform,
  androidEmulator,
} from '@react-native-harness/platform-android';

const isDevelopment = process.env.NODE_ENV === 'development';
const isCI = process.env.CI === 'true';

const config = {
  runners: isDevelopment
    ? [
        // Development runners with local simulators
        androidPlatform({
          name: 'android',
          device: androidEmulator('Pixel_8_API_35'),
          bundleId: 'com.myapp.debug',
        }),
      ]
    : [
        // CI runners with headless or cloud devices
        androidPlatform({
          name: 'android',
          device: androidEmulator('emulator-5554'),
          bundleId: 'com.myapp.debug',
        }),
      ],

  platformReadyTimeout: isCI ? 420000 : 300000,
  bridgeTimeout: isCI ? 180000 : 60000,
  testTimeout: isCI ? 30000 : 5000,
};

export default config;

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.

{
  coverage: {
    root: '../',
  },
}

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 coverage.root, babel-plugin-istanbul may skip instrumenting files outside the current working directory, resulting in incomplete coverage reports.

When to use coverage.root

Set coverage.root 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.

Native iOS Coverage

Harness also supports experimental native iOS coverage for selected CocoaPods.

{
  coverage: {
    native: {
      ios: {
        pods: ['MyLibrary'],
      },
    },
  },
}

Use this when you want coverage data for native code exercised by your Harness tests. Native coverage currently supports iOS simulators only, with Android planned later. For setup details, see Native Coverage.

Need React or React Native expertise you can count on?