# @config-plugins/detox 中文文档

规范地址：https://npmcn.com/package/%40config-plugins/detox/

版本：11\.0\.0
npm 元数据更新时间：2026-09-23T11:25:59.486Z
中文译文更新时间：2026-11-10T15:19:11.923Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40config-plugins/detox
原文对照：https://npmcn.com/package/%40config-plugins/detox/?lang=original
项目主页：https://github.com/expo/config-plugins#readme
源码仓库：https://github.com/expo/config-plugins

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：25.4 kB，16 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：expo ^53
- 首次发布：2021-06-14T16:42:46.571Z
- 最新版本发布：2025-06-02T23:49:32.781Z
- 近 30 天下载量：187042（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：18（近 12 个月 0 个）

## 中文简介

预建时自动配置解毒的配置插件

## 安装

```sh
npm install @config-plugins/detox
```

也可以使用：`pnpm add @config-plugins/detox`、`yarn add @config-plugins/detox`、`bun add @config-plugins/detox`

## README

# 配置插件/解毒剂

当生成本地代码时, 配置自动配置解毒器的插件( E)`npx expo prebuild`) (中文(简体) ).

## 版本

确保您使用共同工作的版本 !

| `expo` | `detox` | `@config-plugins/detox` |
| --- | --- | --- |
| 53.0.0 (韩语) | 20.37.0 (简体中文) | ^10.0 |
| 52.0.0 (简体中文) | 20.28.0 (单位:千美元) | ^ 9.0.0 (中文(简体) ) |
| 51.0.0 (单位:千美元) | 20.20.3 联合国 | ^ 8.0.0 (韩语) |
| 50.0.0 (中文(简体) ) | 20.17.0 (简体中文) | ^7.0.0 (中文(简体) ) |
| 49.0.0 (单位:千美元) | 20.11.0 (单位:千美元) | ^ 6. 0 |
| 48.0.0 (简体中文) | 20.5.0 (中文(简体) ) | ^ 5.0.0 (中文(简体) ) |
| 47.0.0 (简体中文) | 19.13.0 (中文(简体) ) | ^ 4.0.0 (中文(简体) ) |
| 46.0.0 (单位:千美元) | 19.9.0 (中文(简体) ) | ^ 3. 0.0 (韩语) |
| 45.0.0 (单位:千美元) | 19.6.9 联合国 | ^ 2. 0 |
| 44.0.0 (单位:千美元) | 19.1.0 (中文(简体) ) | ^ 1.1.0 (中文(简体) ) |
| 43.0.0 (单位:千美元) | 19.1.0 (中文(简体) ) | ~ 1. 0 个 |
| 40.0.0 (单位:千美元) | 18.6.2 国家 | ~0.0 (中文(简体) ) |

最显著的是,所需最低程度的克特林版本改为: `1.3.50` 在 SDK 40 到 `1.4.21` 在SDK 43. 中,在SDK 43. 不使用正确的版本可能导致 Android 构建错误,比如 `Execution failed for task ':react-native-screens:compileDebugKotlin'.` 或者说 `Execution failed for task ':expo:compileDebugKotlin'.`。 。 。 .

### 将软件包添加到您的 npm 依赖性

首先用纱线、 npm 或 [`npx expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install)。 。 。 .

```
npx expo install detox @config-plugins/detox
```

Detox是iOS和Android的端到端(e2e)测试库. 您可以使用它实现本地工程的自动化使用 。 这个例子说明如何在本地建设的本土项目中使用Detox和Jest.

## 如何使用

-   安装方式 `yarn` 或者说 `npm install`
    -   安装 iOS 软件包 : `npx pod-install`
-   运行 `yarn e2e:ios` 用于在模拟器上构建并测试 iOS 应用程序(只使用macOS).
    -   这个结合 `yarn build:ios` 财务报告和审定财务报表 `yarn test:ios`。 。 。 .
    -   你们可以跑 `yarn test:ios --watch` 之后将测试保持在监视模式.
-   运行 `yarn e2e:android` 在谷歌模拟器上构建并测试Android应用程序(Genymotion需要额外配置).
    -   这个结合 `yarn build:android` 财务报告和审定财务报表 `yarn test:android`。 。 。 .
    -   你们可以跑 `yarn test:android --watch` 之后将测试保持在监视模式.
-   运行 `yarn e2e:android-release` 在发布模式下构建和测试Android应用程序.

## 重新创建此示例

-   `npx create-react-native-app -t blank`
    -   `cd` 输入项目
-   安装软件包 :
    -   `yarn add -D detox @config-plugins/detox @babel/core @babel/runtime @types/jest babel-jest jest jest-circus ts-jest`
    -   触摸 `tsconfig.json`
    -   运行 `expo start` 确保 TS 设置正确.
-   向您添加以下插件 `app.json` 插件阵列( 预建前) 。 这将自动配置 Android 本地代码以支持 Detox :
    
    ```json
    {
      "plugins": ["@config-plugins/detox"]
    }
    ```
    
-   生成本地代码 `npx expo prebuild`
-   运行 `yarn detox init -r jest`

## API 密码

该插件为额外的定制提供了道具. 每次更换道具或插件,都需要重建(并 `prebuild`(原始内容存档于2018-10-10). ). 本地应用. 如果没有添加额外的属性,则使用默认值.

-   `skipProguard` (单位:千美元)_布尔_: 禁用添加前卫分解 `app/build.gradle`默认为 `false`。 。 。 .
-   `subdomains` (单位:千美元)_字符串 \[ \*\]_:主机名可以添加到网络安全配置中. 过 `'*'` 允许所有域。 默认为 `['10.0.2.2', 'localhost']`。 。 。 .

`app.config.js`

```ts
export default {
  plugins: [
    [
      "@config-plugins/detox",
      {
        skipProguard: false,
        subdomains: ["10.0.2.2", "localhost"],
      },
    ],
  ],
};
```

## 财务问题

如果以下命令失败,可以通过运行子集命令获得更好的调试信息:

-   `yarn e2e:ios`数字 : `yarn ios` (构建iOS应用). xcodebuilding编译出的错误可能以更有用的格式显示(使用xcpretty).
-   `yarn e2e:android`数字 : `yarn android` (构建Android应用). Android编译错误可能以更有用的格式显示.

### `yarn e2e:android` 失败

如果得到错误:

```sh
detox[98696] ERROR: DetoxRuntimeError: Cannot boot Android Emulator with the name: 'Pixel_API_28'

HINT: Make sure you choose one of the available emulators: Pixel_3_API_30,Pixel_6_Pro_API_33,Pixel_C_API_30
```

请务必将第一个仿真器名称(我的情况是"Pixel API 28")与推荐的仿真器之一(我的情况是Pixel 3 API 30,Pixel 6 Pro API 33,Pixel C API 30)一起更改 `detox.config.js` 文件编号 `devices.emulator.device.avdName`. Android Studio可以创建更多的模拟器.

* * *

如果得到错误:

```sh
Error: app binary not found at '/Users/.../with-detox/android/app/build/outputs/apk/debug/app-debug.apk', did you build it
```

这意味着建设步骤失败, 确保运行 `yarn android`,以及 `yarn build:android` 在尝试前工作 `yarn e2e:android` 再来一次.

* * *

如果得到错误:

```sh
PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
```

请务必禁用您计算机上运行的任何可能屏蔽请求的代理(即Charles Proxy). 您可能需要运行 `yarn clean:android` 在试图重建之前.

* * *

如果得到错误:

```sh
CLEARTEXT communication to [some host] not permitted by network security policy
```

这意味着你试图连接到一个 hTTP(不是 HTTPS) _没有_ 在你身边 `subdomains` 设置( 默认为 `['10.0.2.2', 'localhost']`) (中文(简体) ). 设置您的子域设置 。 例如,如果将Detox建设成dev客户端,您会希望确保您可以连接到您的地铁服务器:

```javascript
module.exports = {
  plugins: [
    [
      "@config-plugins/detox",
      {
        subdomains:
          process.env.EAS_BUILD_PROFILE === "development"
            ? "*"
            : ["10.0.2.2", "localhost"],
      },
    ],
  ],
};
```

## 页:1

-   [解毒文件](https://wix.github.io/Detox/docs/introduction/getting-started/)

## 常见问题

### @config-plugins/detox 是什么？

预建时自动配置解毒的配置插件

### 如何安装 @config-plugins/detox？

在项目目录运行 npm install @config-plugins/detox，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：expo（^53）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @config-plugins/detox 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @config-plugins/detox 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @config-plugins/detox 可以商用吗？

@config-plugins/detox 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @config-plugins/detox 的下载量有多少？

根据 npm 官方下载统计，@config-plugins/detox 在 2026/10/11 – 2026/11/09 这 30 天内被下载 187,042 次，日均约 6,235 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @config-plugins/detox 还在维护吗？

最新版本 11\.0\.0 发布于 2025/06/03（1\.4 年前）；至今共发布 18 个版本，其中过去 12 个月发布了 0 个；首次发布于 2021/06/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

