---
description: Jest tests, mocks, reports, and environments for @contentstack/utils
globs:
  - __test__/**/*.ts
alwaysApply: false
---

# Testing — `@contentstack/utils`

## Framework

- **Jest 29** with **`ts-jest`** preset (`jest.config.ts`).
- **Environment:** **`jsdom`** (suitable for HTML string assertions and DOM-related behavior).

## Discovery and naming

- **Pattern:** `**/__test__/**/?(*.)+(spec|test).[jt]s?(x)` — this repo uses `*.test.ts` under **`__test__/`**.
- **Mocks / fixtures:** `__test__/mock/*.ts` — follow existing mock naming (`*-mock.ts`).

## Coverage and reports

- **Coverage** is collected from `src/**` excluding `src/index.ts` (`collectCoverageFrom`).
- Outputs: **`reports/coverage/`**, **`reports/html/`** (jest-html-reporters), **`reports/junit/`** (jest-junit), **`reports/report.json`** (from `npm test` script).

## Running tests

| Command | Behavior |
|---------|----------|
| `npm test` | Runs **`pretest` → build** then Jest (CI-aligned). |
| `npm run test:debug` | Watch mode, `--runInBand`. |

## Integration / live tests

- **None** in this repo. No `.env` or stack credentials required for **`npm test`**.

## Build dependency

- **`npm test` always builds first** (`pretest`). Ensure **`src/assets/regions.json`** exists or can be downloaded so `endpoints` tests pass.
