npm package: @m00nsolutions/jest-reporter
Description: Jest test reporter for M00n Report dashboard - real-time test result streaming with retry support and full Jest 29+ API compatibility
Author: M00n Solutions
Latest version: 1.0.4

# @m00nsolutions/jest-reporter

Official Jest test reporter for [M00N](https://app.m00n.report) - a real-time test reporting dashboard.

## Features

- 🚀 **Real-time streaming** - Watch test results appear live in the dashboard
- 🔄 **Retry tracking** - Automatic tracking of test retries with attempt history
- 🏷️ **Tags & attributes** - Organize runs with custom metadata
- 🔒 **Secure** - API key authentication per project
- ✅ **Full Jest 29+ API** - Supports all reporter lifecycle hooks

## Installation

```bash
npm install @m00nsolutions/jest-reporter --save-dev
# or
yarn add @m00nsolutions/jest-reporter --dev
# or
pnpm add @m00nsolutions/jest-reporter --save-dev
```

## Quick Start

### 1. Get your API key

1. Log in to [M00N](https://app.m00n.report)
2. Navigate to your project settings
3. Generate or copy your project API key

### 2. Configure Jest

Add the reporter to your `jest.config.js`:

```javascript
module.exports = {
  reporters: [
    'default', // Keep default console output
    ['@m00nsolutions/jest-reporter', {
      serverUrl: 'https://app.m00n.report',        // Or your self-hosted URL
      apiKey: process.env.M00N_API_KEY,            // Your project API key
      launch: 'Unit Tests',                        // Optional: run title
      tags: ['unit', 'api'],                       // Optional: tags
      attributes: {                                // Optional: custom metadata
        environment: 'ci',
        nodeVersion: process.version,
      },
    }],
  ],
};
```

### 3. Run your tests

```bash
npx jest
```

That's it! Your test results will appear in the M00N dashboard.

## Configuration Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `serverUrl` | `string` | **required** | M00N ingest service URL |
| `apiKey` | `string` | **required** | Project API key (identifies org and project) |
| `launch` | `string` | `'Jest Run {date}'` | Title for this test run |
| `tags` | `string[]` | `[]` | Tags to categorize the run |
| `attributes` | `object` | `{}` | Custom key-value metadata |

## Environment Variables

You can also configure the reporter via environment variables:

```bash
M00N_SERVER_URL=https://app.m00n.report
M00N_API_KEY=m00n_xxxxxxxxxxxxx
M00N_LAUNCH="Nightly Build"
M00N_TAGS=unit,integration
```

## Usage Examples

### Basic Configuration

```javascript
reporters: [
  'default',
  ['@m00nsolutions/jest-reporter', {
    serverUrl: 'https://app.m00n.report',
    apiKey: process.env.M00N_API_KEY,
  }],
],
```

## Jest 29+ API Support

This reporter implements the full Jest reporter API:

### Lifecycle Hooks

| Hook | Description |
|------|-------------|
| `onRunStart` | Called when the test run begins |
| `onTestFileStart` | Called when a test file starts executing |
| `onTestCaseStart` | Called before each individual test runs |
| `onTestCaseResult` | Called after each individual test completes |
| `onTestResult` | Called when a test file finishes |
| `onRunComplete` | Called when the entire run completes |

### Reporter Context (Jest 28+)

The reporter receives context about:
- `firstRun` - Whether this is the first run in watch mode
- `previousSuccess` - Whether the previous run succeeded
- `changedFiles` - Files that changed since last run

## Retry Support

The reporter automatically tracks test retries when using Jest's retry feature:

```javascript
// jest.config.js
module.exports = {
  // Enable retries for flaky tests
  retryTimes: 2,
  // Only retry in CI
  ...(process.env.CI && { retryTimes: 3 }),
};
```

Each retry attempt is tracked separately in the dashboard with:
- Attempt number
- Retry reasons
- Individual timing

## License

MIT License - see [LICENSE](LICENSE) for details.