测试用例失败且includeFailureMsg=true时jest-html-reporter无法生成报告
I've dealt with this exact bug in jest-html-reporter v2.3.0 before—here's what's going on and how to fix it:
The Root Cause
Version 2.3.0 has a known issue where enabling includeFailureMsg: true alongside failed test cases causes the reporter to crash mid-execution, resulting in no HTML report being generated at all.
Solution 1: Upgrade the Package (Recommended)
This bug was fixed in later releases of jest-html-reporter. Upgrading to the latest version will resolve the issue without any configuration changes. Run this command in your project:
npm install jest-html-reporter@latest --save-dev
Once upgraded, your existing setup (with includeFailureMsg: true) will generate the test report correctly, even when tests fail.
Solution 2: Temporary Workaround (If You Can't Upgrade)
If you're stuck on v2.3.0 for dependency reasons, you can disable the includeFailureMsg option to get the report working again:
"jest-html-reporter": { "pageTitle": "Your test suite", "outputPath": "test-report.html", "includeFailureMsg": false // Disable this temporarily }
This will let the report generate, though you'll lose the detailed failure messages in the output.
Quick Configuration Sanity Check
Just to rule out other issues: confirm your testResultsProcessor path in the jest config is correct. Your current path "./node_modules/jest-html-reporter" is valid, and since it works when tests pass, this isn't the problem—but it's always good to double-check for typos!
内容的提问来源于stack exchange,提问作者DevArti

