Plugins

Harness plugins are the way to extend Harness beyond what it offers out of the box.

Use them to add project-specific capabilities on top of Harness, such as native coverage collection, custom reporting, artifact collection, or workflow-specific automation.

A plugin can react to events such as:

  • Harness startup and teardown
  • run start and finish
  • runtime ready and disconnect events
  • Metro initialization and bundle events
  • app lifecycle signals
  • collection, suite, and test execution events

Each plugin receives a context with useful runtime information such as a logger, project root, current runner, current config, and hook-specific data like the run ID or test file path.

Defining a Plugin

Use definePlugin() from @react-native-harness/plugins and register the plugin in your Harness config.

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

export const loggingPlugin = () =>
  definePlugin({
    name: 'logging-plugin',
    hooks: {
      harness: {
        beforeCreation: async (ctx) => {
          ctx.logger.info('Harness is starting for', ctx.platform.platformId);
        },
      },
      run: {
        started: async (ctx) => {
          ctx.logger.info('Run started', ctx.runId);
        },
        finished: async (ctx) => {
          ctx.logger.info('Run finished', ctx.runId, ctx.status);
        },
      },
      testFile: {
        finished: async (ctx) => {
          ctx.logger.info('Finished test file', ctx.file, ctx.status);
        },
      },
    },
  });

Then register it in rn-harness.config.mjs:

import {
  applePlatform,
  appleSimulator,
} from '@react-native-harness/platform-apple';
import { loggingPlugin } from './logging-plugin';

export default {
  entryPoint: './src/test.ts',
  appRegistryComponentName: 'App',
  runners: [
    applePlatform({
      name: 'ios',
      device: appleSimulator('iPhone 16 Pro', '18.0'),
      bundleId: 'com.example.app',
    }),
  ],
  plugins: [loggingPlugin()],
};

Typical Uses

Plugins are a good fit when you want to:

  • write custom logs for run start, finish, or failures
  • collect screenshots, crash artifacts, or extra diagnostics
  • send results to external reporting systems
  • trigger project-specific automation around test runs

Keep plugins focused on workflow needs that are specific to your app or team.

Available Events

The full list of plugin events is defined in the source here:

The public plugin shape is based on nested objects like run.started, runtime.ready, metro.bundleFinished, app.exited, or harness.beforeDispose.

Need React or React Native expertise you can count on?