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

# 运行时同步

> 在测试中更改 driver 要等待的内容：关闭跟踪器，或忽略更多请求和元素。

每个调用都会等待 App 空闲（[同步](https://docs.quiesco.dev/zh/sync.md)）。当某个页面让 App 一直忙碌——它在轮询、动画永不停止，或保持着一个未完成的请求——`app.sync` 可以在测试的剩余部分更改 Quiesco 要等待的内容，而不是把同步完全关闭。

```ts theme={null}
// 每 200 ms 轮询一次、显示实时计数的仪表盘
await app.sync.disableTracker('timer');
await app.sync.ignoreElements.add('poll-count');
```

这些更改持续到测试结束，并会在下一个测试之前撤销。它们在重新启动和重新连接之后依然有效。如果只想让单次调用不等待，`{ sync: false }` 依然可用（[调用选项](https://docs.quiesco.dev/zh/api.md#call-options)）。

## 跟踪器

### `disableTracker(name)`

```ts theme={null}
disableTracker(name: TrackerName): Promise<void>
```

类型： [`TrackerName`](./api-types#trackername)

不再等待某一个 [跟踪器](https://docs.quiesco.dev/zh/sync.md#trackers)，即一种忙碌来源。

```ts theme={null}
// 实时比分页面每 200 ms 轮询一次
await app.sync.disableTracker('timer');
await app.tap('live-scores');
```

`name` 是 `network`、`timer`、`react`、`idle-callback`、`frame-stable`、`native` 和 `native-module`（构建包装原生模块时开启：[原生模块调用](https://docs.quiesco.dev/zh/sync.md#native-module-calls)）之一。其他名称会抛出 `RangeError`。

### `enableTracker(name)`

```ts theme={null}
enableTracker(name: TrackerName): Promise<void>
```

类型： [`TrackerName`](./api-types#trackername)

重新等待某个跟踪器，包括配置中关闭的跟踪器。

```ts theme={null}
await app.sync.disableTracker('timer');
await app.tap('live-scores');
await app.goBack();
await app.sync.enableTracker('timer');
```

### `disable()`

```ts theme={null}
disable(): Promise<void>
```

完全不再等待 App：在 `enable()` 之前，所有跟踪器都关闭（Detox 的 `disableSynchronization`）。

```ts theme={null}
// 永远不会结束的启动动画
await app.sync.disable();
await app.expectVisible('splash');
```

### `enable()`

```ts theme={null}
enable(): Promise<void>
```

重新等待 App：跟踪器恢复为配置中的状态，`disableTracker` 和 `enableTracker` 所做的更改仍然有效。

```ts theme={null}
await app.sync.disable();
await app.tap('skip-intro');
await app.sync.enable();
```

## 忽略列表

### `ignoreUrls.add(pattern)` / `ignoreUrls.remove(pattern)`

```ts theme={null}
ignoreUrls.add(pattern: string | RegExp): Promise<void>
ignoreUrls.remove(pattern: string | RegExp): Promise<void>
```

在配置的 `sync.ignoreUrls`（[配置](https://docs.quiesco.dev/zh/config.md#sync)）基础上，向 `network` 跟踪器忽略的请求中添加或移除一个 URL。`pattern` 是字符串或正则表达式。

```ts theme={null}
// 一个永不结束的统计分析请求
await app.sync.ignoreUrls.add(/\/analytics/);

// 聊天页面上的长轮询
await app.sync.ignoreUrls.add('/chat/poll');
```

`remove` 也能在测试的剩余部分移除来自配置的模式。

### `ignoreElements.add(target)` / `ignoreElements.remove(target)`

```ts theme={null}
ignoreElements.add(target: MatcherInput): Promise<void>
ignoreElements.remove(target: MatcherInput): Promise<void>
```

类型： [`MatcherInput`](./api-types#matcherinput)

在配置的 `sync.ignoreElements`（[配置](https://docs.quiesco.dev/zh/config.md#sync)）基础上，向 `frame-stable` 跟踪器排除的元素中添加或移除一个元素。`target` 是一个 [匹配器](https://docs.quiesco.dev/zh/api-matchers.md)。

```ts theme={null}
// 它的文本随每次轮询变化
await app.sync.ignoreElements.add('poll-count');

// header 中一直在转的加载指示器
await app.sync.ignoreElements.add({ type: SemanticType.progress, within: 'header' });
```

`remove` 也能在测试的剩余部分移除来自配置的匹配器。


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