> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Testplane

`@decoyhq/testplane` is a [Testplane](https://testplane.io) plugin. It starts `decoy` for the run,
gives each test its own Session, routes the browser's API calls to Decoy, and exposes the Control
API as `decoy(browser)`.


```sh [npm]
npm install -D @decoyhq/cli @decoyhq/testplane
```

```sh [pnpm]
pnpm add -D @decoyhq/cli @decoyhq/testplane
```

```sh [yarn]
yarn add -D @decoyhq/cli @decoyhq/testplane
```

```sh [bun]
bun add -d @decoyhq/cli @decoyhq/testplane
```

The setup is one `plugins` entry:

```ts title=".testplane.conf.ts"
import type { DecoyOptions } from '@decoyhq/testplane'
import type { ConfigInput } from 'testplane'

export default {
  gridUrl: 'local',
  baseUrl: 'http://127.0.0.1:4173',
  browsers: { chrome: { desiredCapabilities: { browserName: 'chrome' } } },

  plugins: {
    '@decoyhq/testplane': {
      command: 'decoy serve --config mocks/decoy.yaml',
      urls: '**/api/**', // browser requests sent to Decoy
      collection: 'happy-path', // each test's Session starts here
    } satisfies DecoyOptions,
  },
} satisfies ConfigInput
```

Next, [switch responses in a test](/docs/testplane/responses/index.md).

## Options

| option                | default                       | meaning                                                   |
| --------------------- | ----------------------------- | --------------------------------------------------------- |
| `enabled`             | `true`                        | `false` turns the plugin off without removing it          |
| `url`                 | `http://127.0.0.1:8080`       | where Decoy serves                                        |
| `command`             | `decoy serve`                 | shell command the plugin runs when Decoy isn't up         |
| `cwd`                 | the config file's directory   | working directory for `command`                           |
| `reuseExistingServer` | `true` locally, `false` in CI | reuse a Decoy already answering health                    |
| `timeout`             | `60000`                       | ms the plugin waits for health                            |
| `urls`                | none                          | glob (`*` in a segment, `**` across) or RegExp, or a list |
| `collection`          | Decoy's default               | Collection each test's Session starts on                  |

A `urls` glob matches the full request URL, as in Playwright: `*` stays within a path segment,
`**` crosses them, and `{api,graphql}` matches either. It must start with `*` or a scheme
(`'**/api/**'`, `'http://localhost:3000/api/**'`). The plugin throws on load for a glob like
`'/api/**'`, which could never match. Requests that match nothing go to the real network.

`command` runs with `node_modules/.bin` (from `cwd` up) on PATH. At the end of the run the plugin
sends SIGTERM and, if Decoy hasn't exited after 8s, SIGKILL (Windows: `taskkill /T /F`).

## Limits

- Routing (`urls`) needs Chrome or Chromium: it uses CDP through `browser.getPuppeteer()`, in
  WebDriver Classic and BiDi (`webSocketUrl: true`) sessions alike. On other browsers each test
  fails with a clear error.
- Testplane reuses a browser for many tests, so a request still in flight when a test ends can
  reach the next test's Session. Wait for your page to settle before a test ends.

The runnable version of all this is
[`examples/testplane-ts-e2e`](https://github.com/decoyhq/decoy/tree/main/examples/testplane-ts-e2e).
