> ## 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.

# 快速开始

> 从一个新建的 Expo App 到在 Web、iOS 和 Android 上通过的测试。

前提条件：Node.js 24+，一个基于 SDK 55 或更高版本的 Expo App（`npx create-expo-app@latest`）。另外，每个要测试的平台还需要：

| 平台 | 所需环境 |
| - | - |
| Web | 无需其他准备：最后一步会由 Playwright 下载 Chromium |
| iOS | 一台装有 Xcode 和 iOS 模拟器的 Mac |
| Android | Android SDK（Android Studio）和一个模拟器（AVD） |

前四步对所有平台都一样，最后一步在你选择的平台上运行测试。

**1. 初始化项目**

```sh pnpm theme={null}
cd my-app

# 依赖、config plugin、Metro、入口文件、quiesco.config.mts，以及第一个测试
pnpm dlx quiesco init
```

```sh npm theme={null}
cd my-app

# 依赖、config plugin、Metro、入口文件、quiesco.config.mts，以及第一个测试
npx quiesco init
```

```sh bun theme={null}
cd my-app

# 依赖、config plugin、Metro、入口文件、quiesco.config.mts，以及第一个测试
bunx quiesco init
```

```sh yarn theme={null}
cd my-app

# 依赖、config plugin、Metro、入口文件、quiesco.config.mts，以及第一个测试
yarn dlx quiesco init
```

`init` 会询问使用哪个测试运行器：直接按回车选 Vitest（推荐），也可以选 Jest 或 Cucumber（[测试运行器](https://docs.quiesco.dev/zh/runners.md)）。`--runner vitest|jest|cucumber` 可以跳过询问直接指定。下面的步骤以 Vitest 为例，换成其他运行器只是文件名不同。

`init` 会配置 iOS、Android，以及在 App 带有 `react-native-web` 时配置 Web；用 `--platforms web,ios` 可以只配置其中一部分。它会在 `package.json` 中为每个平台添加一个 `e2e:*` 脚本。

**2. 包裹根布局**

用 `<QuiescoRoot>` 包裹根布局（默认模板中是 `src/app/_layout.tsx`）：

```tsx theme={null}
import { QuiescoRoot } from '@quiesco/agent';

export default function TabLayout() {
  // …
  return (
    <QuiescoRoot>
      <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>…</ThemeProvider>
    </QuiescoRoot>
  );
}
```

**3. 给首页加上 test id**

在 `src/app/index.tsx` 中写 `<ThemedView style={styles.container} testID="home">`。生成的 `e2e/app.test.ts` 会检查它是否可见：

```ts theme={null}
import { test } from '@quiesco/vitest';

test('the home screen is shown', async ({ app }) => {
  await app.expectVisible({ id: 'home' });
});
```

**4. （可选）让首页稳定下来**

只有当首页上有一直在播放的动画时才需要这一步。Quiesco 会等画面稳定后再继续，持续数分钟的动画会让它一直等到 `SYNC_TIMEOUT`。如果首页没有这样的动画，跳过即可。

以 SDK 55 的默认模板为例：它会在首页上让一个装饰性的光晕转动四分钟。之后版本的模板未必还有这个动画，具体以你的项目为准。处理方法是给这个元素加上 test id，再让 Quiesco 在判断稳定时忽略它。

在 `src/components/animated-icon.web.tsx`（iOS / Android 则是 `animated-icon.tsx`）中：

```tsx theme={null}
<Animated.View … style={styles.glow} testID="logo-glow">
```

然后取消 `quiesco.config.mts` 中这一行的注释：

```ts theme={null}
sync: { ignoreElements: ['logo-glow'] },
```

**5. 运行**

选择平台。三个平台用的是同一个测试文件。

> [tab] Web
>
> ```sh pnpm theme={null}
> pnpm exec playwright install chromium
>
> # 以 EXPO_PUBLIC_QUIESCO=1 导出 web 构建，然后执行 quiesco test --platform web
> pnpm e2e:web
> ```
>
> ```sh npm theme={null}
> npx playwright install chromium
>
> # 以 EXPO_PUBLIC_QUIESCO=1 导出 web 构建，然后执行 quiesco test --platform web
> npm run e2e:web
> ```
>
> ```sh bun theme={null}
> bunx playwright install chromium
>
> # 以 EXPO_PUBLIC_QUIESCO=1 导出 web 构建，然后执行 quiesco test --platform web
> bun run e2e:web
> ```
>
> ```sh yarn theme={null}
> yarn playwright install chromium
>
> # 以 EXPO_PUBLIC_QUIESCO=1 导出 web 构建，然后执行 quiesco test --platform web
> yarn e2e:web
> ```
>
> 该模板在服务端渲染（`web.output: "server"`）；对于这种导出，Quiesco 会自行运行 `npx expo serve`。静态导出和单页应用导出则直接托管。

> [tab] iOS
>
> 先启动一个模拟器（`open -a Simulator`，或 `xcrun simctl boot "iPhone 17"`）：Quiesco 会使用已启动的那个。
>
> ```sh pnpm theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> pnpm exec expo install expo-dev-client
>
> # quiesco build ios：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后面向模拟器执行 xcodebuild
> pnpm e2e:build:ios
>
> # quiesco test --platform ios
> pnpm e2e:ios
> ```
>
> ```sh npm theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> npx expo install expo-dev-client
>
> # quiesco build ios：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后面向模拟器执行 xcodebuild
> npm run e2e:build:ios
>
> # quiesco test --platform ios
> npm run e2e:ios
> ```
>
> ```sh bun theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> bunx expo install expo-dev-client
>
> # quiesco build ios：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后面向模拟器执行 xcodebuild
> bun run e2e:build:ios
>
> # quiesco test --platform ios
> bun run e2e:ios
> ```
>
> ```sh yarn theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> yarn expo install expo-dev-client
>
> # quiesco build ios：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后面向模拟器执行 xcodebuild
> yarn e2e:build:ios
>
> # quiesco test --platform ios
> yarn e2e:ios
> ```
>
> 第一次构建需要几分钟；之后只要 App 配置和依赖没有变化，就会跳过构建。如果想让 Quiesco 自己启动模拟器，在 `quiesco.config.mts` 的 `devices.ios` 中指定它（`{ device: 'iPhone 17' }`）。

> [tab] Android
>
> 先启动一个模拟器（Android Studio 的 Device Manager，或 `emulator -avd <name>`）：Quiesco 会使用正在运行的那个。
>
> ```sh pnpm theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> pnpm exec expo install expo-dev-client
>
> # quiesco build android：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后执行 gradlew assembleDebug
> pnpm e2e:build:android
>
> # quiesco test --platform android
> pnpm e2e:android
> ```
>
> ```sh npm theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> npx expo install expo-dev-client
>
> # quiesco build android：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后执行 gradlew assembleDebug
> npm run e2e:build:android
>
> # quiesco test --platform android
> npm run e2e:android
> ```
>
> ```sh bun theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> bunx expo install expo-dev-client
>
> # quiesco build android：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后执行 gradlew assembleDebug
> bun run e2e:build:android
>
> # quiesco test --platform android
> bun run e2e:android
> ```
>
> ```sh yarn theme={null}
> # 只需一次：e2e 构建所基于的 dev client
> yarn expo install expo-dev-client
>
> # quiesco build android：以 EXPO_PUBLIC_QUIESCO=1 执行 prebuild，然后执行 gradlew assembleDebug
> yarn e2e:build:android
>
> # quiesco test --platform android
> yarn e2e:android
> ```
>
> 第一次构建需要几分钟；之后只要 App 配置和依赖没有变化，就会跳过构建。如果想让 Quiesco 自己启动模拟器，在 `quiesco.config.mts` 的 `devices.android` 中指定 AVD 名称（`emulator -list-avds` 会列出所有 AVD）。

`npx quiesco doctor` 会检查配置，并说明如何补齐缺失的部分。`npx quiesco tree` 会打印运行中 App 的元素树，便于查找 test id。

下一步：在 [教程](https://docs.quiesco.dev/zh/tutorial.md) 中编写真正的测试，然后阅读 [测试运行器](https://docs.quiesco.dev/zh/runners.md) 和 [API 参考](https://docs.quiesco.dev/zh/api.md)。


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