npm package: @sqaline/playwright-reporter
Description: Playwright reporter that sends CI run results to SQAline Release Copilot
Latest version: 0.1.1

# @sqaline/playwright-reporter

Playwright custom reporter for [SQAline Release Copilot](https://sqaline.com). After each CI run it sends your test results to SQAline so you always know whether it's safe to ship.

## Installation

```bash
npm install --save-dev @sqaline/playwright-reporter
```

## Usage

```ts
// playwright.config.ts
import { defineConfig } from '@playwright/test';
import SQAlineReporter from '@sqaline/playwright-reporter';

export default defineConfig({
  reporter: [
    ['list'],
    [SQAlineReporter, {
      apiKey: process.env.SQALINE_API_KEY,
      tags: {
        checkout: ['tests/checkout/**', 'tests/payment/**'],
        signup:   ['tests/auth/signup*'],
        billing:  ['tests/billing/**'],
      },
    }],
  ],
});
```

## Configuration

| Option   | Type                          | Required | Default                      | Description                                       |
|----------|-------------------------------|----------|------------------------------|---------------------------------------------------|
| `apiKey` | `string`                      | No†      | —                            | Project API key; defaults to `SQALINE_API_KEY` env |
| `apiUrl` | `string`                      | No       | `https://api.sqaline.com`‡   | Override for self-hosted or local development     |
| `tags`   | `Record<string, string[]>`    | No       | `{}`                         | Map journey names to glob patterns for spec files |

† Either pass `apiKey` in config or set `SQALINE_API_KEY`. ‡ Default URL can be overridden with `SQALINE_API_URL`.

## Journey Tags

The `tags` option maps a logical journey name to one or more [minimatch](https://github.com/isaacs/minimatch) glob patterns. Every test result is labelled with the journeys whose patterns match its spec file path.

```ts
tags: {
  checkout: ['tests/checkout/**', 'tests/payment/**'],
  signup:   ['tests/auth/signup*'],
  billing:  ['tests/billing/**'],
}
```

## CI environment detection

The reporter automatically reads branch, commit SHA, PR number, and run ID from common CI providers:

| Variable               | Provider        |
|------------------------|-----------------|
| `GITHUB_REF_NAME`      | GitHub Actions  |
| `GITHUB_SHA`           | GitHub Actions  |
| `GITHUB_RUN_ID`        | GitHub Actions  |
| `GITHUB_PR_NUMBER`     | GitHub Actions  |
| `GITHUB_EVENT_NAME`    | GitHub Actions  |
| `GITLAB_CI_COMMIT_BRANCH` | GitLab CI    |
| `CI_COMMIT_SHA`        | GitLab CI       |
| `CI_PIPELINE_ID`       | GitLab CI       |
| `CI_MERGE_REQUEST_IID` | GitLab CI       |

Falls back to `git` CLI commands when environment variables are not present.

## Flaky test detection

A test is marked **flaky** when it eventually passes after one or more retries (`result.status === 'passed' && result.retry > 0`). Flaky results are stored with `status: 'flaky'` and contribute to the release readiness score separately from clean failures.

## Error handling

All network calls are wrapped in `try/catch`. The reporter will never throw or cause your test suite to fail. On a network-level error it retries once after 2 seconds. All failures are logged with `console.warn`.

## Local development

Set `apiUrl` to your local API server:

```ts
[SQAlineReporter, {
  apiKey: process.env.SQALINE_API_KEY,
  apiUrl: 'http://localhost:3001',
}]
```