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

# CLI

> quiesco 命令：init、build、test、ui、list、devices、doctor 和 tree，以及全部选项。

```sh pnpm theme={null}
pnpm exec quiesco <command> [options]
```

```sh npm theme={null}
npx quiesco <command> [options]
```

```sh bun theme={null}
bunx quiesco <command> [options]
```

```sh yarn theme={null}
yarn quiesco <command> [options]
```

## `quiesco init`

在 Expo 项目中配置 Quiesco。每一步都会报告做了什么；已有文件绝不会被覆盖——当某个文件需要 Quiesco 无法安全完成的修改时，它会打印出需要添加的内容。App 低于 Expo SDK 55 时会给出警告（Quiesco 支持 SDK 55 及以上），但仍会完成配置。

它首先会询问使用哪个测试运行器：Vitest（默认选中）、Jest 或 Cucumber（[测试运行器](https://docs.quiesco.dev/zh/runners.md)）。`--runner` 可以预先给出答案；终端前没有人时（CI），直接使用 Vitest。

1. 用项目的包管理器（根据 lock 文件判断 npm、pnpm、yarn 或 bun）安装包：`@quiesco/agent`、`@quiesco/native` 作为 dependencies；`quiesco`、`@quiesco/core`、`@quiesco/expo-plugin`、运行器的包（`@quiesco/vitest` 和 `vitest`、`@quiesco/jest` 和 `jest`，或 `@quiesco/cucumber` 和 `@cucumber/cucumber`），以及 Web 用的 `@quiesco/web`、`playwright` 作为 dev dependencies。Quiesco 的包按运行 `init` 的 CLI 的版本安装（`npx quiesco@0.4.0 init` 安装 0.4.0），因此它写入的脚本与安装的 CLI 一致。安装后 `init` 会读回已安装的版本，有不一致时停止，并给出要运行的安装命令（例如包管理器用了缓存中过期的 registry 元数据时）。
2. 把 `@quiesco/expo-plugin` 加到 `app.json` 的 plugins 中，并补上它缺少的 App ID：`ios.bundleIdentifier`、`android.package`（都是 `com.anonymous.<slug>`）和 `scheme`（slug），让构建出来的 App 和 `quiesco.config.mts` 指的是同一个 App。缺少这些值时，`expo prebuild` 会用自己的默认值，而 iOS 和 Android 的默认值不一样。项目用的是 `app.config.js` / `.ts` 时，改为列为需要你做的事项。
3. 创建带有 `withQuiesco()` 的 `metro.config.js`（或说明如何包装已有的配置）。
4. 让 `@quiesco/agent` 成为入口文件的第一个 import。Expo Router App 会得到一个 `index.ts`（`import '@quiesco/agent'; import 'expo-router/entry';`）以及 `"main": "index.ts"`。如果入口注册的是本地组件（`registerRootComponent(App)`，空白模板就是这样），`init` 还会在入口中用 `<QuiescoRoot>` 包裹该组件。
5. 写入 `quiesco.config.mts`（bundle id、package 和 scheme 取自 `app.json`）、运行器的配置和第一个测试，以及 `e2e:*` 脚本：

   | 运行器 | 文件 |
   | - | - |
   | Vitest | `vitest.config.mts`、`e2e/app.test.ts` |
   | Jest | `jest.config.cjs`、`e2e/app.test.js` |
   | Cucumber | `cucumber.mjs`、`features/support/quiesco.ts`、`features/app.feature` 及其步骤；并在 `tsconfig.json` 中加上 `"allowImportingTsExtensions": true`（step 文件之间用 `.ts` 导入，见 [step 文件不会被编译](https://docs.quiesco.dev/zh/driver-pattern-cucumber.md#type-stripping)） |

   如果项目已经有 Vitest 或 Jest 配置（单元测试用的），会原样保留：Quiesco 的配置放在它旁边，命名为 `vitest.e2e.config.mts` / `jest.e2e.config.cjs`，`e2e:*` 脚本会用 `--config` 传入这个文件名。

| 选项 | |
| - | - |
| `--platforms ios,android,web` | 要配置的平台。默认：iOS 和 Android，安装了 `react-native-web` 时再加上 Web |
| `--runner vitest\|jest\|cucumber` | 要配置的测试运行器，不再询问。默认：在终端中询问（默认选中 Vitest）；CI 中用 Vitest |
| `--packages <dir>` | 从 `<dir>` 中的 `.tgz` 文件（`pnpm pack` 的输出）安装 Quiesco，并把它们之间的相互依赖固定到这些文件 |
| `--skip-install` | 只打印安装命令 |
| `--upgrade` | 把用旧版本设置的项目升级到这个版本（[升级项目](#quiesco-init-upgrade)） |
| `--dry-run` | 与 `--upgrade` 一起用：只列出要做的改动，不实际修改 |

`init` 留给你做的事：添加 test id；在 Expo Router App（以及它无法安全修改的其他入口）中用 `<QuiescoRoot>` 包裹根布局。`init` 会列出剩下的事项。

### 升级项目

```sh pnpm theme={null}
# 指定版本时用 quiesco@0.4.1
pnpm dlx quiesco@latest init --upgrade

# 只列出改动
pnpm dlx quiesco@latest init --upgrade --dry-run
```

```sh npm theme={null}
# 指定版本时用 quiesco@0.4.1
npx quiesco@latest init --upgrade

# 只列出改动
npx quiesco@latest init --upgrade --dry-run
```

```sh bun theme={null}
# 指定版本时用 quiesco@0.4.1
bunx quiesco@latest init --upgrade

# 只列出改动
bunx quiesco@latest init --upgrade --dry-run
```

```sh yarn theme={null}
# 指定版本时用 quiesco@0.4.1
yarn dlx quiesco@latest init --upgrade

# 只列出改动
yarn dlx quiesco@latest init --upgrade --dry-run
```

把用旧版 `quiesco init` 设置的项目升级到执行它的 CLI 的版本：

1. 把所有 Quiesco 包装成这个版本，包括 `init` 不会添加的包（例如 `@quiesco/steps`），并像 `init` 一样在安装后读回版本进行确认。精确版本（`"quiesco": "0.10.0"`）保持精确，范围保持范围。运行器本身（`vitest`、`jest`、`@cucumber/cucumber`）和 `playwright` 不动。
2. 删除 cucumber 配置里的 `paths: ['features/**/*.feature']`。旧版本会写入这一行；有了它，`quiesco test features/x.feature` 会运行所有 feature。
3. 在 `tsconfig.json` 中加上 `"allowImportingTsExtensions": true`。
4. 把 `app.json` 缺少的 App ID 写进去（与上面第 2 步相同），并用这些值替换 `quiesco.config.mts` 里的 `// TODO: expo.…` 占位符。
5. 用 `<QuiescoRoot>` 包裹 `registerRootComponent(App)`。`e2e:*` 脚本保持原样（你删掉的不会被加回来），只列出 `init` 会添加的脚本名。

每项改动都会列出来。无法安全修改的内容（你自己设置的 `paths`、带注释的 `tsconfig.json`、`app.config.js` / `.ts`）会连同该怎么做一起列出。再次执行不会有任何改动。平台取自 `quiesco.config.mts`（或 `--platforms`）。执行完后请运行 `npx quiesco doctor`。

## `quiesco build`

```sh pnpm theme={null}
pnpm exec quiesco build ios
pnpm exec quiesco build android --force
pnpm exec quiesco build ios --clean
```

```sh npm theme={null}
npx quiesco build ios
npx quiesco build android --force
npx quiesco build ios --clean
```

```sh bun theme={null}
bunx quiesco build ios
bunx quiesco build android --force
bunx quiesco build ios --clean
```

```sh yarn theme={null}
yarn quiesco build ios
yarn quiesco build android --force
yarn quiesco build ios --clean
```

构建 e2e App（以 `EXPO_PUBLIC_QUIESCO=1` 运行 `expo prebuild`，然后是面向模拟器的 `xcodebuild`，或 `gradlew assembleDebug` / `assembleRelease`），并写到 `apps.<platform>.binaryPath`。在 iOS 上，derived data 路径、构建配置和 scheme 都从这个路径（`<dir>/Build/Products/<Configuration>-iphonesimulator/<Name>.app`）中读取。如果自上次构建以来 App 配置和依赖（含已安装的版本）都没有变化，并且构建产物还在，会跳过 Debug 构建；加 `--force` 则总是构建。Release 构建包含 JS bundle，总是会构建。加 `--clean` 会运行 `expo prebuild --clean`：删除 `ios/` / `android/` 并重新生成，在其中手动做过的修改都会丢失。适合在移除原生模块之后，或原生工程状态异常时使用；此时也总是会构建。

## `quiesco test`

```sh pnpm theme={null}
pnpm exec quiesco test --platform web
pnpm exec quiesco test --platform android e2e/login.test.ts
pnpm exec quiesco test --platform ios --config vitest.e2e.config.mts
pnpm exec quiesco test --platform web --runner cucumber --tags @smoke features/login.feature
pnpm exec quiesco test --platform web -- --testNamePattern todo
pnpm exec quiesco test --help
```

```sh npm theme={null}
npx quiesco test --platform web
npx quiesco test --platform android e2e/login.test.ts
npx quiesco test --platform ios --config vitest.e2e.config.mts
npx quiesco test --platform web --runner cucumber --tags @smoke features/login.feature
npx quiesco test --platform web -- --testNamePattern todo
npx quiesco test --help
```

```sh bun theme={null}
bunx quiesco test --platform web
bunx quiesco test --platform android e2e/login.test.ts
bunx quiesco test --platform ios --config vitest.e2e.config.mts
bunx quiesco test --platform web --runner cucumber --tags @smoke features/login.feature
bunx quiesco test --platform web -- --testNamePattern todo
bunx quiesco test --help
```

```sh yarn theme={null}
yarn quiesco test --platform web
yarn quiesco test --platform android e2e/login.test.ts
yarn quiesco test --platform ios --config vitest.e2e.config.mts
yarn quiesco test --platform web --runner cucumber --tags @smoke features/login.feature
yarn quiesco test --platform web -- --testNamePattern todo
yarn quiesco test --help
```

设置 `QUIESCO_PLATFORM` 并运行项目的测试运行器——`vitest run`、`jest` 或 `cucumber-js`；其余参数原样传给它。不加 `--runner vitest|jest|cucumber` 时，运行已安装了 Quiesco 包（`@quiesco/vitest`、`@quiesco/jest`、`@quiesco/cucumber`）的那个运行器；装了多个或一个都没装时，运行 `cucumber-js`。`--` 之后的参数也传给运行器，`--` 本身会被去掉，因此写在它之后的 Quiesco 选项名归运行器所有（`quiesco test -- --help` 显示运行器的帮助）。`--workers N` 运行 N 个 worker，每个使用自己的设备（[parallel.md](https://docs.quiesco.dev/zh/parallel.md)）：对 cucumber-js 会变成 `--parallel N`，对 Jest 是 `--maxWorkers N`，对 Vitest 是 `--fileParallelism --maxWorkers N`（运行器自身的参数同样有效）。

在终端中，运行器的输出照常向上滚动，最后一行始终显示进度条：已完成 / 总数、通过、失败与跳过的数量、已用时间，以及当前正在运行的测试（有多个 worker 时每台设备一个）。进度由运行器发送：`quiesco test` 会自动为 cucumber-js 加上 `@quiesco/cucumber` 的 formatter，Vitest 需要 `quiescoPlugin()`，Jest 由 preset 提供（[测试运行器](https://docs.quiesco.dev/zh/runners.md)）；没有接入时，运行结束会提示需要添加什么。`--no-progress` 或 `QUIESCO_PROGRESS=0` 可以关闭进度条；在 CI 中以及输出不是终端时它也会关闭。退出码就是运行器的退出码。

当 App 从 Metro 加载 JS（`devClient.metroUrl`，或 `apps.web.url`）而那里没有响应时，`quiesco test` 会以 `EXPO_PUBLIC_QUIESCO=1` 启动 Metro（`npx expo start --port <port>`，输出写到 `artifacts/metro.log`），等待它就绪，并在运行器结束时（包括 Ctrl-C）停止它。已经在运行的 Metro 会直接使用。配置中的 `devServer` 可以修改命令和超时时间，或关闭这一行为（`autoStart: false`）。直接运行运行器（`npx vitest run`）时不会启动 Metro。

## `quiesco ui`

```sh pnpm theme={null}
pnpm exec quiesco ui --platform web
pnpm exec quiesco ui --platform ios --config vitest.e2e.config.mts --port 5173
pnpm exec quiesco ui --help
```

```sh npm theme={null}
npx quiesco ui --platform web
npx quiesco ui --platform ios --config vitest.e2e.config.mts --port 5173
npx quiesco ui --help
```

```sh bun theme={null}
bunx quiesco ui --platform web
bunx quiesco ui --platform ios --config vitest.e2e.config.mts --port 5173
bunx quiesco ui --help
```

```sh yarn theme={null}
yarn quiesco ui --platform web
yarn quiesco ui --platform ios --config vitest.e2e.config.mts --port 5173
yarn quiesco ui --help
```

在浏览器中打开[测试 UI](https://docs.quiesco.dev/zh/ui.md)：项目里的测试、点一下即可运行全部 / 某个文件 / 单个测试、实时进度，以及失败和对应的证据。需要在项目中安装 `@quiesco/ui`。`--platform`、`--runner`、`--workers` 和运行器的参数与 `quiesco test` 相同；`--port N` 指定端口，`--no-open` 不自动打开浏览器。运行期间 Metro 保持启动；按 Ctrl-C 停止。

## `quiesco list`

```sh pnpm theme={null}
pnpm exec quiesco list
pnpm exec quiesco list e2e/login.test.ts
pnpm exec quiesco list --runner cucumber features/login.feature --json
```

```sh npm theme={null}
npx quiesco list
npx quiesco list e2e/login.test.ts
npx quiesco list --runner cucumber features/login.feature --json
```

```sh bun theme={null}
bunx quiesco list
bunx quiesco list e2e/login.test.ts
bunx quiesco list --runner cucumber features/login.feature --json
```

```sh yarn theme={null}
yarn quiesco list
yarn quiesco list e2e/login.test.ts
yarn quiesco list --runner cucumber features/login.feature --json
```

按文件列出运行器（与 `quiesco test` 使用的相同）将会运行的测试及其行号，既不运行测试，也不启动设备。cucumber-js 会做一次去掉报告格式的 dry run（报告文件保持不变），Vitest 会解析测试文件，Jest 会在不使用 Quiesco 测试环境和项目 global setup 的情况下收集测试（setup files 仍会运行）。`--json` 输出列表，其中的测试 id 与进度条和测试 UI 使用的一致。什么都无法列出时，退出码为 1。

## `quiesco devices`

```sh pnpm theme={null}
# Quiesco 为并行 worker 创建的模拟器 / AVD
pnpm exec quiesco devices

# 关闭并删除它们
pnpm exec quiesco devices --prune
```

```sh npm theme={null}
# Quiesco 为并行 worker 创建的模拟器 / AVD
npx quiesco devices

# 关闭并删除它们
npx quiesco devices --prune
```

```sh bun theme={null}
# Quiesco 为并行 worker 创建的模拟器 / AVD
bunx quiesco devices

# 关闭并删除它们
bunx quiesco devices --prune
```

```sh yarn theme={null}
# Quiesco 为并行 worker 创建的模拟器 / AVD
yarn quiesco devices

# 关闭并删除它们
yarn quiesco devices --prune
```

列出 `"<name> (Quiesco N)"` 模拟器和 `<avd>_quiesco_N` AVD（正在运行的会标注 `[running]`）；`--prune` 删除它们。下次并行运行时会重新创建；你自己的设备永远不会被动到。

## `quiesco doctor`

```sh pnpm theme={null}
# quiesco.config.mts 中配置的所有平台
pnpm exec quiesco doctor

pnpm exec quiesco doctor --platform ios
```

```sh npm theme={null}
# quiesco.config.mts 中配置的所有平台
npx quiesco doctor

npx quiesco doctor --platform ios
```

```sh bun theme={null}
# quiesco.config.mts 中配置的所有平台
bunx quiesco doctor

bunx quiesco doctor --platform ios
```

```sh yarn theme={null}
# quiesco.config.mts 中配置的所有平台
yarn quiesco doctor

yarn quiesco doctor --platform ios
```

检查 Node.js、Expo SDK（55 及以上）、项目配置（包、所有 Quiesco 包是否为同一版本、package.json 脚本中的每个 `quiesco <command>` 是否存在、config plugin、Metro 中的 `withQuiesco()`、agent 是否为入口的第一个 import、`<QuiescoRoot>`、配置文件）、App ID（`quiesco.config.mts` 与 `app.json` 和构建产物是否一致，以及 `init` 留下的占位符；有 `app.config.js` / `.ts` 时与 `npx expo config` 解析出的配置比对）、旧版本写入的设置（cucumber 配置中的 `paths`；step 文件导入 `.ts` 但没有 `allowImportingTsExtensions`）、平台工具（模拟器、adb 和 AVD、配置中的 Playwright 浏览器）、App 构建和端口。每个问题都附带修复方法；旧的设置缺少的大部分内容，`npx quiesco@latest init --upgrade` 都能修好。必需的检查失败时以 1 退出；警告和提示（ℹ️，例如缺少 `e2e:build:*` 脚本）不会导致失败。

## 测试放在单独的包里

测试不在 Expo App 的目录里时（monorepo，或 `app/` 和 `e2e/` 并列），把 `quiesco.config.mts`、runner 及其包放在测试包里，用 `appDir` 指向 App（相对于配置文件）：

```ts theme={null}
// e2e/quiesco.config.mts
export default defineConfig({
  appDir: '../app',
  apps: {
    ios: { bundleId: 'com.acme.shop', binaryPath: '../app/ios/build/Build/Products/Debug-iphonesimulator/shop.app' },
  },
});
```

在测试包里运行命令。`doctor` 在 `appDir` 中检查 App（Expo、`@quiesco/agent`、config plugin、Metro、入口、`<QuiescoRoot>`、`app.json`），在运行的目录中检查测试设置（测试包里的 runner、配置文件、脚本），并检查两边的 Quiesco 包是否为同一版本。`build` 在 `appDir` 中运行 `expo prebuild` 和 xcodebuild / gradle；`binaryPath` 仍然相对于配置文件。`init --upgrade` 在 App 中升级 `@quiesco/agent`、`@quiesco/native` 和 `@quiesco/expo-plugin`，在测试包中升级其余的包。`quiesco test` 在 `appDir` 中启动 Metro。`--app-dir <dir>`（doctor、build、`init --upgrade`）可以不经配置文件直接指定 App。

## `quiesco tree`

```sh pnpm theme={null}
# 连接到正在运行的 App
pnpm exec quiesco tree

pnpm exec quiesco tree --launch --platform android
pnpm exec quiesco tree --json > tree.json
```

```sh npm theme={null}
# 连接到正在运行的 App
npx quiesco tree

npx quiesco tree --launch --platform android
npx quiesco tree --json > tree.json
```

```sh bun theme={null}
# 连接到正在运行的 App
bunx quiesco tree

bunx quiesco tree --launch --platform android
bunx quiesco tree --json > tree.json
```

```sh yarn theme={null}
# 连接到正在运行的 App
yarn quiesco tree

yarn quiesco tree --launch --platform android
yarn quiesco tree --json > tree.json
```

打印 App 当前屏幕的元素树——每个元素的类型、`#testID`、文本和 `[role]`——帮助你为步骤找到匹配器：

```
RCTView #todos-screen
  RCTText #greeting "a@example.com"
  RCTScrollView #todo-list
    RCTText #todo-empty "No todos yet"
  RCTView #add-todo [button]
    RCTText "New"
```

默认只启动 host 端服务器，等待已在运行的 App（手动启动的 e2e 构建，或测试运行后留下的 App，会在几秒内重新连接），因此你看到的就是你导航到的那个屏幕。`--launch` 会像测试运行一样先启动设备并启动 App。`--timeout <ms>` 设置等待 App 的时长。


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