> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quiesco.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Set up a bare React Native app

> Set Quiesco up in a React Native app that does not use Expo.

Quiesco's packages need React Native only: `@quiesco/native` is a React Native TurboModule and
`@quiesco/agent` a plain JS package, so an app made with the React Native Community CLI
(`npx @react-native-community/cli init`) can be tested on iOS and Android without installing `expo`.
The app needs React Native 0.83 or later with the New Architecture. For an Expo app, see
[Set up an Expo app](https://docs.quiesco.dev/expo.md).

`quiesco init` does the setup and `quiesco build` makes the e2e build, in the project's own `ios/` and
`android/`: nothing of Expo is installed or run. A complete example is in the repository:
[examples/bare-rn-app](https://github.com/h2nology/quiesco/tree/main/examples/bare-rn-app).

```sh theme={null}
npx quiesco init
```

`init` asks which test runner to use (Vitest, Jest or Cucumber), never overwrites a file and lists what it
left to you ([CLI](https://docs.quiesco.dev/cli.md#without-expo)).

## What is set up

**1. Packages**

```sh theme={null}
npm install @quiesco/agent @quiesco/native
npm install --save-dev quiesco @quiesco/core @quiesco/vitest vitest
```

`@quiesco/vitest` is the Vitest integration; [Jest and Cucumber](https://docs.quiesco.dev/runners.md) work the same way.

**2. Metro**

```js metro.config.js theme={null}
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const { withQuiesco } = require('@quiesco/agent/metro');

const config = {};

module.exports = withQuiesco(mergeConfig(getDefaultConfig(__dirname), config));
```

`withQuiesco()` puts the agent into bundles made with `EXPO_PUBLIC_QUIESCO=1` and a no-op stub into
every other bundle. The variable keeps its name in apps without Expo. `init` wraps the config of
React Native's template; for another one it says what to add.

**3. The entry file**

```js index.js theme={null}
import { QuiescoRoot } from '@quiesco/agent'; // must stay the first import
import { createElement } from 'react';
import { AppRegistry } from 'react-native';

import App from './App';
import { name as appName } from './app.json';

// <QuiescoRoot> renders App unchanged in builds without EXPO_PUBLIC_QUIESCO=1.
function QuiescoApp() {
  return createElement(QuiescoRoot, null, createElement(App));
}

AppRegistry.registerComponent(appName, () => QuiescoApp);
```

The agent must be the first import of the app, and `<QuiescoRoot>` connects the app to the test run.
`init` writes this for the entry of React Native's template; you can also wrap the root component in
`App.tsx` yourself.

**4. The config**

```ts quiesco.config.mts theme={null}
import { defineConfig } from '@quiesco/core';

export default defineConfig({
  apps: {
    ios: {
      bundleId: 'com.example.myapp',
      binaryPath: 'ios/build/Build/Products/Debug-iphonesimulator/MyApp.app',
    },
    android: {
      package: 'com.example.myapp',
      binaryPath: 'android/app/build/outputs/apk/debug/app-debug.apk',
      // A debug build loads its JS from Metro on the host's localhost.
      reversePorts: [8081],
    },
  },
  // quiesco test starts Metro when it is not running.
  devServer: { url: 'http://localhost:8081', command: ['npx', 'react-native', 'start', '--port', '{port}'] },
});
```

The app IDs are read from the native projects. `devServer.url` says that the debug builds load their
JS from Metro: `quiesco test` starts it when it is not running. `reversePorts` lets the emulator
reach it. Every option is in [configuration](https://docs.quiesco.dev/config.md); the runner's own config and a first test are
in [test runners](https://docs.quiesco.dev/runners.md).

## Build and run

> [tab] iOS
>
> ```sh theme={null}
> npx quiesco build ios
> npx quiesco test --platform ios
> ```

> [tab] Android
>
> ```sh theme={null}
> npx quiesco build android
> npx quiesco test --platform android
> ```

`quiesco build ios` runs `pod install` and `xcodebuild`; `quiesco build android` deletes React Native's
autolinking list and runs `gradlew`. Both set `EXPO_PUBLIC_QUIESCO=1`, because autolinking takes
`@quiesco/native` only then ([CLI](https://docs.quiesco.dev/cli.md#without-expo)).

The log of a run says whether the native module is in the app (`native module true`). When it says
`false`, the build was made without the variable, or with the autolinking result of an earlier build:
actions then fall back to [`js` mode](./api-actions).

## Build without the CLI

`quiesco build` runs ordinary React Native builds. The same by hand, for example in a CI job that has
its own build steps:

> [tab] iOS
>
> ```sh theme={null}
> cd ios
> EXPO_PUBLIC_QUIESCO=1 pod install
> EXPO_PUBLIC_QUIESCO=1 xcodebuild -workspace MyApp.xcworkspace -scheme MyApp -configuration Debug \
>   -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' -derivedDataPath build build
> ```

> [tab] Android
>
> ```sh theme={null}
> rm -rf android/build/generated/autolinking
> cd android
> EXPO_PUBLIC_QUIESCO=1 ./gradlew assembleDebug
> ```
>
> React Native's Gradle plugin keeps the list of linked libraries in
> `android/build/generated/autolinking` until a lockfile changes; deleting it makes Gradle ask again.

A debug build loads its JS from Metro, which must run with the variable too (`quiesco test` starts it
that way). A release build has its JS inside; build it with the variable, and remove `devServer` from
`quiesco.config.mts`.

## Builds that are not e2e builds

Without the variable autolinking leaves `@quiesco/native` out and Metro bundles a stub in place of the
agent, so a release contains nothing of Quiesco and your app needs no setting for that. When you go back
from an e2e build:

* iOS: run `pod install` again without the variable. The pod stays in the Xcode project until you do.
* Android: a build that would still link the module from the cached list stops with a message and deletes
  the list; run it again.

> [!WARNING]
>
> `@quiesco/native` uses private UIKit API to inject touches, which the App Store does not accept. Make
> release builds from a checkout whose `pod install` ran without `EXPO_PUBLIC_QUIESCO`, as your CI does.

## The web

An app that also runs in the browser with `react-native-web` is tested there too. The web build is the
project's own. Quiesco supports one made with Vite: `quiescoAgent()` does for Vite what `withQuiesco()`
does for Metro.

```ts vite.config.mts theme={null}
import { quiescoAgent } from '@quiesco/agent/vite';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [quiescoAgent()],
  resolve: {
    alias: [{ find: /^react-native$/, replacement: 'react-native-web' }],
    extensions: ['.web.tsx', '.web.ts', '.web.jsx', '.web.js', '.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],
  },
});
```

The plugin puts the agent into builds made with `EXPO_PUBLIC_QUIESCO=1` and a no-op stub into every other
build. The agent must be the first import of the web build's entry file too (the module script of
`index.html`).

```ts quiesco.config.mts theme={null}
import { defineConfig } from '@quiesco/core';

export default defineConfig({
  apps: {
    web: { url: 'http://localhost:5173' },
  },
});
```

```sh theme={null}
npm install --save-dev @quiesco/web playwright
npx playwright install chromium
npx quiesco test --platform web
```

`quiesco test` starts Vite's dev server with the variable when nothing answers at `apps.web.url`, and
stops it afterwards. To test a built app, set `apps.web.distDir` to the output of `vite build`, made with
the variable. `quiesco init` does this setup when the project has `react-native-web` and a Vite config.
Touches and text come from Playwright in the browser, so `@quiesco/native` is not in the web build. Vite
is the only bundler with a plugin.

## What is different from an Expo app

* The app must be able to reach the test run on `localhost`. A debug build can; a release build needs
  `NSAllowsLocalNetworking` in the Info.plist's App Transport Security settings (the React Native template
  has it) and, on Android, a network security config that allows cleartext traffic to `localhost`.
  `@quiesco/expo-plugin` writes both for an Expo app.
* `apps.<platform>.devClient` is for Expo development builds. Do not set it: a React Native debug build
  finds Metro by itself, and `devServer.url` tells `quiesco test` where that is.
* `app.device.relaunch({ url })` gives the app the link through React Native's `Linking.getInitialURL()`.
* The web build is the project's own, made with Vite; Expo's web export is not used ([the web](#web)).
* `quiesco build` never generates or deletes `ios/` and `android/`, and always builds: the native
  projects are yours.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.