For generating HTML reports from Jest tests in an Nx monorepo, you have several excellent options. Here are the most reliable approaches:
Option 1: jest-html-reporters (Recommended)
This is one of the most popular and feature-rich HTML reporters for Jest.
Installation:
npm install --save-dev jest-html-reporters
Configuration in your jest.config.js (or individual project configs):
module.exports = {
// ... your existing config
reporters: [
'default',
[
'jest-html-reporters',
{
publicPath: './coverage/html-report',
filename: 'test-report.html',
openReport: false,
expand: true,
hideIcon: false,
pageTitle: 'Test Report',
logoImgPath: './assets/logo.png', // optional
includeFailureMsg: true,
includeSuiteFailure: true
}
]
]
};
Option 2: jest-html-reporter
A simpler, lightweight alternative:
Installation:
npm install --save-dev jest-html-reporter
Configuration:
module.exports = {
// ... your existing config
reporters: [
'default',
[
'jest-html-reporter',
{
pageTitle: 'Test Report',
outputPath: './coverage/test-report.html',
includeFailureMsg: true,
includeSuiteFailure: true,
theme: 'lightTheme' // or 'darkTheme'
}
]
]
};
For Nx Monorepo Setup
Since you have multiple apps/libs, you'll want to configure this at the workspace level or create aggregated reports.
Option A: Workspace-level configuration
Create or modify your root jest.config.js:
module.exports = {
projects: [
'<rootDir>/apps/*/jest.config.js',
'<rootDir>/libs/*/jest.config.js'
],
collectCoverageFrom: [
'apps/**/*.{ts,tsx}',
'libs/**/*.{ts,tsx}',
'!**/*.d.ts',
'!**/node_modules/**'
],
reporters: [
'default',
[
'jest-html-reporters',
{
publicPath: './dist/coverage/html-report',
filename: 'all-tests-report.html',
expand: true,
pageTitle: 'All Apps & Libs Test Report'
}
]
]
};
Option B: Run tests with custom script
Add to your package.json:
{
"scripts": {
"test:all": "nx run-many --target=test --all --parallel=false",
"test:report": "jest --config=jest.config.js --coverage --coverageReporters=html lcov text",
"test:html-report": "jest --config=jest.config.js --reporters=default --reporters=jest-html-reporters"
}
}
Option 3: Using Nx Test Reports with Custom Reporter
You can also leverage Nx's built-in test orchestration:
Create a custom Jest configuration for reporting:
// jest.report.config.js
const baseConfig = require('./jest.config');
module.exports = {
...baseConfig,
collectCoverage: true,
coverageDirectory: './coverage/combined',
reporters: [
'default',
[
'jest-html-reporters',
{
publicPath: './coverage/combined',
filename: 'test-report.html',
expand: true,
pageTitle: 'Combined Test Report - Release Evidence'
}
]
]
};
Then run:
npx jest --config=jest.report.config.js --passWithNoTests
Advanced: Multiple Report Formats
For comprehensive release documentation, you might want multiple formats:
module.exports = {
// ... other config
reporters: [
'default',
[
'jest-html-reporters',
{
publicPath: './reports/html',
filename: 'test-report.html',
expand: true
}
],
[
'jest-junit',
{
outputDirectory: './reports/junit',
outputName: 'junit.xml'
}
]
]
};
Recommended Workflow
- Install jest-html-reporters (most feature-complete)
- Configure at workspace level to capture all projects
- Add npm script for easy execution
- Include in CI/CD pipeline to generate reports automatically
The generated HTML report will include test results, coverage information, and failure details - perfect for release documentation. The report is self-contained and can be easily attached to release notes or stored in artifact repositories.