# aerostack test

> Run Vitest tests in the Cloudflare Workers runtime pool. Your tests run in the same edge environment as production — no platform mocking.

Run your project's tests using Vitest with the Cloudflare Workers runtime pool. Tests run in an environment that matches your production edge runtime.

## Usage

```bash
aerostack test [flags]
```

## Flags

| Flag | Description |
|------|-------------|
| `--coverage` | Generate a coverage report |

## Examples

```bash
# Run all tests
aerostack test

# Run with coverage
aerostack test --coverage
```

## How it works

1. Auto-generates `.aerostack/wrangler.test.toml` with test bindings
2. Builds `dist/worker.js`
3. Runs Vitest with `@cloudflare/vitest-pool-workers`

Tests have access to all D1, KV, and other bindings, running in the actual Workers runtime.

## Writing tests

```ts
// src/__tests__/auth.test.ts

describe('auth', () => {
  it('registers a new user', async () => {
    const response = await fetch('http://localhost/v1/public/projects/my-app/auth/register', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ email: 'test@example.com', password: 'securepass' })
    })

    expect(response.status).toBe(201)
    const body = await response.json()
    expect(body.user.email).toBe('test@example.com')
  })
})
```

## Configuration

Tests read your `aerostack.toml` for bindings. The test environment uses local D1 and KV, isolated per test run.

Add `aerostack test` to your CI pipeline to catch regressions before deploying.
