# Testing Guide

This document describes how to run and write tests for the groq-browserbase-client.

## Prerequisites

- Node.js and npm installed
- A Groq API key for integration tests

## Setup

1. Install dependencies:
```bash
npm install
```

2. Create a `.env.test` file in the project root with your Groq API key:
```bash
GROQ_API_KEY=your_groq_api_key_here
```

**Important:** Never commit your `.env.test` file to version control. It's already added to `.gitignore`.

## Running Tests

### Run all tests
```bash
npm test
```

### Run only integration tests
```bash
npm test -- test/integration
```

### Run a specific test file
```bash
npx jest test/integration/client.test.ts
```

### Run tests in watch mode (useful during development)
```bash
npm test -- --watch
```

## Test Structure

The tests are organized into two main categories:

- `test/integration/`: Integration tests that interact with the real Groq API
- `test/unit/`: Unit tests for utility functions and other isolated components

### Integration Tests

Integration tests verify that our client works correctly with the actual Groq API. These tests:

- Require a valid Groq API key in `.env.test`
- May take longer to run due to API calls
- Have increased timeouts to accommodate network latency
- Test real-world scenarios and error cases

### Code Coverage

Test coverage reports are automatically generated when running tests. You can find the coverage report in the `coverage/` directory after running the tests.

## Writing New Tests

When adding new tests:

1. Choose the appropriate directory (`integration/` or `unit/`)
2. Follow the existing test patterns
3. Include both success and error cases
4. Add appropriate timeouts for integration tests
5. Use descriptive test names that explain the scenario being tested

## Continuous Integration

The test suite is designed to run in CI environments. When setting up CI:

1. Configure the `GROQ_API_KEY` environment variable in your CI system's secrets
2. Use the same commands as documented above to run tests
3. Consider running integration tests only on specific branches to avoid API rate limits 