Creating an HTML test report for all unit tests in your Angular v17 + Nx v17.1.2 monorepo is a great idea — especially if you're using Jest as the test runner and need to provide evidence (e.g., for compliance or QA purposes). You can achieve this by leveraging well-known Jest reporters that generate HTML output.
Here's how to do it step-by-step:
✅ Goal
Generate an HTML test report covering all apps and libs in your Nx workspace after running Jest unit tests.
🧰 Tools
jest-html-reporter – popular reporter for generating HTML reports.
- OR
jest-html-reporters – another modern alternative with more features.
- Nx's ability to run tests across multiple projects via
nx run-many.
We'll go with jest-html-reporters since it supports multi-project reporting better and allows custom output paths.
🔧 Step 1: Install Required Package
Install the reporter package:
npm install --save-dev jest-html-reporters
or with yarn:
yarn add --dev jest-html-reporters
📁 Step 2: Configure Jest Global Reporter
In your Nx workspace, Jest configs are usually inside each project’s jest.config.ts, but you can centralize configuration in jest.config.ts at the root or use Nx presets.
You want to configure Jest to include the HTML reporter globally.
Option A: Modify Root jest.config.ts (if used)
If you have a root jest.config.ts that applies to all projects (via Nx presets), update it:
// jest.config.ts
export default {
// ... existing config ...
reporters: [
"default",
[
"jest-html-reporters",
{
publicPath: "__reports__",
filename: "unit-test-report.html",
openReport: false,
inlineAssets: true,
},
],
],
};
Option B: Update Each Project's Jest Config (less ideal)
If you don't have a centralized Jest config, you’ll need to manually update each project's jest.config.ts file to include the reporter.
Example:
// apps/my-app/jest.config.ts
const nxPreset = require('@nrwl/jest/preset').default;
export default {
...nxPreset,
reporters: [
"default",
[
"jest-html-reporters",
{
publicPath: "__reports__",
filename: "unit-test-report.html",
openReport: false,
inlineAssets: true,
},
],
],
};
Repeat this for all relevant apps/libs or use a shared preset.
🏃♂️ Step 3: Run Tests Across All Projects
Use Nx’s run-many command to run tests on all apps and libs:
nx run-many --target=test --all
This will execute all Jest unit tests across your workspace.
After completion, the HTML report will be generated at:
__reports__/unit-test-report.html
This file aggregates results from all executed Jest test runs.
📁 Optional: Customize Output Path
You can change the output folder (publicPath) and filename:
[
"jest-html-reporters",
{
publicPath: "__reports__/jest",
filename: "test-report.html",
},
]
Make sure the directory exists or the reporter creates it automatically.
🧪 Optional: Generate JSON + HTML Reports Together
If you want to also keep machine-readable JSON output for CI tools:
reporters: [
"default",
[
"jest-html-reporters",
{
publicPath: "__reports__/jest",
filename: "test-report.html",
jsonPath: "__reports__/jest/test-results.json",
},
],
],
🧼 Clean Reports Before Running (Optional)
To ensure old data isn’t mixed in:
rm -rf __reports__/
nx run-many --target=test --all
Or create a script in package.json:
"scripts": {
"clean-reports": "rm -rf __reports__/",
"test:report": "npm run clean-reports && nx run-many --target=test --all"
}
Then just run:
npm run test:report
✅ Final Output
You’ll get a consolidated HTML report like this:
__reports__/unit-test-report.html
Open it in any browser to view detailed results from all apps and libs:
- Test suites
- Passed/failed cases
- Execution time
- Error traces (for failed tests)
🧩 Bonus: Add Report to CI Pipeline
In CI (like GitHub Actions, GitLab CI, etc.), make sure to:
- Archive or attach the
__reports__/unit-test-report.html file.
- Fail the pipeline if any test fails (ensure Jest exits with non-zero code).
✅ Summary
| Step | Description |
|---|
| 1 | Install jest-html-reporters |
| 2 | Add it to Jest reporters config |
| 3 | Run tests with nx run-many --target=test --all |
| 4 | View HTML report at __reports__/unit-test-report.html |
Let me know if you'd like to integrate this into a CI/CD workflow (GitHub Actions, Jenkins, etc.) or combine it with coverage reports too!