---
title: Library maintainers
description: >-
  Measure a React Native library's native code from unit tests and from a test
  app, and fail CI when that package has no hits.
---
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.page/invertase/react-native-coverage/llms.txt
> Use this file to discover all available pages before exploring further.

The install itself is on [App developers](/app-developers); do that first in your [test app](/coverage#dedicated-test-app), then come back here for what is specific to a library.

Unit tests and the test app measure different things. Keep both layers:

| Layer | Tooling | Artifact | Codecov flag |
|-------|---------|----------|--------------|
| Unit tests | Jest `--coverage` | `coverage/unit/lcov.info` | `unit-js` |
| Test app, JavaScript and TypeScript | `babel-plugin-istanbul` and the NYC (Istanbul CLI) remap | `coverage/js/lcov.info` | `e2e-js` (single-app) |
| Test app, native iOS | TurboModule flush, then `llvm-cov` | `lcov.info` | Single-app: `e2e-ios`. This repo's matrix: `e2e-ios-dynamic`, `e2e-ios-static` |
| Test app, native Android | TurboModule flush, then JaCoCo | `jacocoTestReport.xml` | `e2e-android` |

## Before you begin

- Use a monorepo with a [dedicated test app](/coverage#dedicated-test-app) that renders your library's native surface.
- Copy this repository's shape: the library at the root, with the `example/` (Expo) and `example-dynamic/` (React Native CLI, dynamic frameworks) directories beside it.

## Measure unit tests

Your Jest suite already exercises the JavaScript and TypeScript surface. Turn on coverage and upload it:

```sh
jest --coverage   # writes coverage/unit/lcov.info
codecov -f coverage/unit/lcov.info -F unit-js
```

Unit tests run in Node with the native module mocked, so they cannot show that native code ran. The test app layer does that. Keep both.

## Measure native code in a test app

### Point coverage at your package

In the test app, configure the plugin (Expo) or the helpers (React Native CLI) with your library's names:

```json
{
  "expo": {
    "plugins": [
      [
        "react-native-coverage",
        {
          "libraryProjectMatchers": ["my-lib"],
          "frameworkNamePrefixes": ["MyLib"],
          "enableAndroidCoverage": true
        }
      ]
    ]
  }
}
```

`libraryProjectMatchers` matches your Android Gradle library projects. `frameworkNamePrefixes` matches your iOS frameworks so the flush includes their `LINKEDIT` counters.

### Include workspace libraries in JavaScript coverage

A default `babel-plugin-istanbul` roots `test-exclude` at the Babel working directory and skips anything outside it, including a yarn workspace library resolved to its real path. Pass `cwd` and `include` to the Babel plugin and to the `nyc.config.js` file. Root both at the monorepo so the shared library stays in the LCOV. For more information about the setup, see [JavaScript and TypeScript](/integration/js).

### Install, flush, and pull

The install, the flush at the end of the run, and the pull and report commands are the same as for an app. Follow App developers from **Install in the test app** to **Pull, report, and fail CI on empty coverage**.

## Fail CI when your package has no hits

A passing end-to-end run that writes an empty LCOV hides a broken pipeline. Configure `assert` to require hits in your library's paths, not just any file:

```js
// react-native-coverage.config.js
module.exports = {
  strict: true, // exit 2 on empty reports, the CI default
  assert: {
    lcovPathIncludes: ['packages/my-lib'],   // at least one LCOV SF: path must match and have hits
    jacocoPackageIncludes: ['com.my.lib'],   // at least one JaCoCo package must have LINE hits
    defaultLcovPath: 'coverage/ios/lcov.info',
    // Gradle default after `android report` is under android/app/build/reports/jacoco/…
    // Point here only after you copy the XML (or set android.jacocoReportXml / --jacoco-xml).
    defaultJacocoXmlPath: 'coverage/android/jacocoTestReport.xml',
  },
};
```

For more information about every key, see [Configuration](/reference/config).

## Upload one Codecov flag per platform

**This repository's matrix** (static + dynamic iOS cells). A single consumer test app usually uses the simpler `e2e-ios` / `e2e-android` / `e2e-js` set on [App developers](/app-developers#optional-upload-to-codecov) instead.

Upload each cell under its own flag and disable automatic report search, as this repository's [`codecov.yml`](https://github.com/invertase/react-native-coverage/blob/main/codecov.yml) file does:

```sh
codecov -f coverage/unit/lcov.info               -F unit-js
codecov -f coverage/ios-dynamic/lcov.info        -F e2e-ios-dynamic
codecov -f coverage/ios-static/lcov.info         -F e2e-ios-static
# JaCoCo: upload the Gradle default path, or a file you copied to coverage/android/
codecov -f coverage/android/jacocoTestReport.xml -F e2e-android
```

That split gives iOS dynamic, iOS static, and Android their own number, as in the [example from this package](/coverage#example-from-this-package).

## Run this repository's test apps

Run the coverage end-to-end scripts for this repository:

```sh
yarn e2e:ios:dynamic   # example-dynamic/, React Native CLI, dynamic frameworks
yarn e2e:ios:static    # example/, Expo, static libraries
yarn e2e:android       # example/, Expo, JaCoCo and JavaScript
```

<CardGroup cols={3}>
  <Card title="This repository on GitHub" icon="github" href="https://github.com/invertase/react-native-coverage">
    Library at the root, `example/` and `example-dynamic/` test apps, `e2e/` specs, CI scripts.
  </Card>
  <Card title="This repository on Codecov" icon="chart-line" href="https://app.codecov.io/gh/invertase/react-native-coverage">
    The per-flag dashboard your setup reproduces.
  </Card>
  <Card title="CI with Appium" icon="gears" href="/integration/ci-appium">
    The GitHub Actions job, and the failures it already fixed.
  </Card>
</CardGroup>
