Allure Reporter for Jest
jest-allure2-reporter is an idiomatic Jest reporter that integrates with the Allure Framework, enabling the generation of rich, interactive test reports. It is currently at version 2.3.0 and actively maintained with a regular release cadence, including frequent bug fixes and feature updates (e.g., support for Jest 30). Key differentiators include its ability to visualize detailed test execution flows with step-by-step breakdowns, attach various artifacts (screenshots, logs, JSON data) to tests, and provide comprehensive test metadata through both programmatic APIs and JSDocblock pragmas. The library offers robust TypeScript support and features like the `@Step` decorator for defining test steps and capabilities for visual regression testing, providing a more detailed and debuggable testing experience compared to standard Jest reporters.
Common errors
-
Error: Jest: a reporter 'jest-allure2-reporter' cannot be found.
cause The reporter string 'jest-allure2-reporter' is not resolvable by Jest, likely because the package is not installed or incorrectly referenced.fixEnsure `jest-allure2-reporter` is installed (`npm install --save-dev jest-allure2-reporter`) and correctly listed in `jest.config.js` reporters array. -
ReferenceError: allure is not defined
cause The `allure` object or `@Step` decorator is not available in the global scope or imported incorrectly, often due to an incorrect `testEnvironment` setting.fixVerify `jest.config.js` includes `testEnvironment: 'jest-allure2-reporter/environment-node'` (or `.../environment-jsdom`) and that `allure` or `Step` are imported from `'jest-allure2-reporter/api'`. -
Cannot find name 'allure'. Did you mean 'URL'?
cause When using TypeScript, the types for the `allure` object might not be correctly picked up by the compiler.fixEnsure you have imported `allure` from `'jest-allure2-reporter/api'` in your TypeScript files. Also, verify your `tsconfig.json` correctly includes `node_modules/@types` or relevant type declarations. -
Error: Allure commandline is not installed. Please install it globally `npm install -g allure-commandline`
cause The `allure generate` or `allure open` commands are not found because the Allure CLI tool is not installed or not in the system's PATH.fixInstall the Allure command line tool globally: `npm install -g allure-commandline`.
Warnings
- gotcha The Allure command line tool (`allure-commandline`) is a separate dependency and must be installed globally or locally to generate and serve reports after tests complete. This package only generates the raw Allure results.
- breaking Older versions of Jest (below 27.2.5) are not supported. This reporter requires Jest 27.2.5 or higher. Compatibility fixes for Jest 30 were introduced in v2.2.1.
- gotcha If using TypeScript decorators like `@Step`, ensure `experimentalDecorators` and `emitDecoratorMetadata` are enabled in your `tsconfig.json`.
- gotcha The `testEnvironment` must be explicitly set to either `jest-allure2-reporter/environment-node` (for Node.js tests) or `jest-allure2-reporter/environment-jsdom` (for browser-like tests). Failing to do so will result in Allure APIs not being available in your tests.
- breaking Node.js versions older than 16.20.0 are not supported by the package. Running on unsupported Node.js versions may lead to unexpected errors or failures.
Install
-
npm install jest-allure2-reporter -
yarn add jest-allure2-reporter -
pnpm add jest-allure2-reporter
Imports
- jest-allure2-reporter
import { AllureReporter } from 'jest-allure2-reporter';// jest.config.js module.exports = { reporters: [ 'default', 'jest-allure2-reporter' ] }; - environment-node
import { NodeEnvironment } from 'jest-allure2-reporter/environment-node';// jest.config.js module.exports = { testEnvironment: 'jest-allure2-reporter/environment-node' }; - allure
import allure from 'jest-allure2-reporter';
import { allure } from 'jest-allure2-reporter/api'; - Step
import { Step } from 'jest-allure2-reporter';import { Step } from 'jest-allure2-reporter/api';
Quickstart
/* jest.config.js */
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
reporters: [
'default',
'jest-allure2-reporter'
],
testEnvironment: 'jest-allure2-reporter/environment-node'
};
/* my-page.ts */
import { allure, Step } from 'jest-allure2-reporter/api';
export class MyPage {
@Step('Load user data for ID: {{userId}}')
async loadUserData(userId: string) {
const userData = { name: 'John Doe', id: userId };
allure.attachment('User Data', JSON.stringify(userData, null, 2), 'application/json');
return userData;
}
}
/* my.test.ts */
import { allure } from 'jest-allure2-reporter/api';
import { MyPage } from './my-page';
describe('User Profile', () => {
const page = new MyPage();
it('should load user data correctly', async () => {
allure.feature('Profile');
allure.severity('critical');
const userData = await page.loadUserData('user123');
expect(userData.name).toBe('John Doe');
});
});
// To generate and open reports after tests:
// npm install -g allure-commandline
// allure generate allure-results --clean
// allure open