Jest Integration
Installation
Configuration
Add the Prathya reporter and setup module to your jest.config.js:
module.exports = {
reporters: ['default', ['@intrigsoft/pratya-jest/reporter', {
contractPath: './CONTRACT.yaml',
outputDir: './pratya-report',
}]],
setupFilesAfterFramework: ['@intrigsoft/pratya-jest/setup'],
};
Important
The @intrigsoft/pratya-jest/setup entry is required. It installs an afterEach hook that flushes requirement annotations to disk so the reporter can read them.
Reporter Options
| Option | Default | Description |
|---|---|---|
contractPath |
./CONTRACT.yaml |
Path to the contract file |
outputDir |
./pratya-report |
Output directory for reports |
failOnViolations |
false |
Exit with error if any ERROR-level violations are found |
minimumRequirementCoverage |
0 |
Minimum coverage percentage threshold (0–100) |
excludeStatuses |
[] |
Requirement statuses to exclude from coverage |
Annotating Tests
Import requirement from @intrigsoft/pratya-jest and call it inside your test body:
const { requirement } = require('@intrigsoft/pratya-jest');
test('user login returns JWT', () => {
requirement('AUTH-001');
const result = login('user@example.com', 'password');
expect(result).toHaveProperty('token');
});
test('wrong password returns 401', () => {
requirement('AUTH-001-CC-001');
expect(() => login('user@example.com', 'wrong')).toThrow();
});
ES Modules
import { requirement } from '@intrigsoft/pratya-jest';
test('user login returns JWT', () => {
requirement('AUTH-001');
// ...
});
Multiple Requirements
test('invalid credentials handled uniformly', () => {
requirement(['AUTH-001-CC-001', 'AUTH-001-CC-002']);
// ...
});
How It Works
Unlike Vitest and Playwright, Jest has no built-in annotation mechanism. Prathya uses:
requirement()function — stores annotations in a global map keyed by test name@intrigsoft/pratya-jest/setup— anafterEachhook that flushes annotations to a JSON file on disk@intrigsoft/pratya-jest/reporter— reads the annotation files inonRunCompleteand builds trace entries
This design works correctly with Jest's worker-based parallelism — each worker writes to a unique file.