# Playwright

Run the end-to-end tests of every package with a Playwright config.

The Playwright plugin gives every package that uses Playwright an `e2e` task, so its end-to-end tests run without a script or a line of `axle.toml`.

## Add it

```sh
axle add playwright
```

This writes it into the root `axle.toml`:

```toml
[plugins.playwright]
source = "npm:@axle-rs/plugin-playwright@0.1.0"
hash = "sha256-…"
```

## Tasks

A package or project with a `playwright.config.ts`, `.mts`, `.cts`, `.js`, `.mjs` or `.cjs` in its folder gets an `e2e` task, `playwright test`. The command runs through the repository's package manager, such as `pnpm exec playwright test`, so it uses the Playwright the package installs. `PLAYWRIGHT_*` variables, such as `PLAYWRIGHT_BROWSERS_PATH`, reach it without changing its hash.

## Not cached

End-to-end tests talk to a server, a browser and often the network, none of which Axle can hash, so a passing run says nothing certain about the next one. The task isn't cached unless the settings say `cache = true`, for tests that only use what the repository builds.

Its `outputs` are still the HTML report's folder, `outputFolder`, `playwright-report` by default, and the folder of traces and screenshots, `outputDir`, `test-results` by default. They're read from the config without running it, so with `cache = true` a report comes back from the cache with the result. When either is set to something other than a plain string, or to a folder outside the repository, the plugin leaves `outputs` out and Axle [finds the outputs](https://axlers.dev/docs/reference/cache.md#outputs) itself.

Tests that need the app running start it with `webServer` in the Playwright config, or wait for a persistent task in `axle.toml`:

```toml
[tasks.e2e]
dependsOn = ["web#preview"]
```

## Scripts the repository already has

A package's own script wins. When its `package.json` has an `e2e` script that runs something else, such as `playwright test --project chromium`, the plugin leaves the task alone and Axle runs the script. An `e2e` script of plain `playwright test` is replaced by the plugin's task.

## Settings

| Setting | Default | Meaning                                                     |
| ------- | ------- | ----------------------------------------------------------- |
| `e2e`   | `"e2e"` | the name of the task, or `false` to leave it out            |
| `cache` | `false` | `true` caches the tests' result and reports like any task's |

```toml
[plugins.playwright]
source = "npm:@axle-rs/plugin-playwright@0.1.0"
hash = "sha256-…"
e2e = "test:e2e"
cache = true
```

The plugin's answers are kept until a `playwright.config.*`, `package.json`, `pnpm-workspace.yaml` or lockfile changes.
