README.md

July 7, 2025 ยท View on GitHub

๐Ÿ“œ

jest-html-reporter

A Jest test results processor for generating a summary in HTML.



Inspired by karma-htmlfile-reporter



Installation

npm:

$ npm install jest-html-reporter --save-dev

yarn:

$ yarn add jest-html-reporter --dev

Usage

Configure Jest to process the test results by adding the following entry to the Jest config (jest.config.json):

"reporters": [
	"default",
	["./node_modules/jest-html-reporter", {
		"pageTitle": "Test Report"
	}]
]

As you run Jest from within the terminal, a file called test-report.html will be created within your root folder containing information about your tests.

There are multiple configuration options available. Read more about these further down in this document.

Alternative Usage as a Test Results Processor

To run the reporter as a test results processor (after Jest is complete instead of running in parallel), add the following entry to the Jest config (jest.config.json):

{
	"testResultsProcessor": "./node_modules/jest-html-reporter"
}

Note: When running as a testResultsProcessor, the configuration needs either to be placed within a new file named jesthtmlreporter.config.json residing in the root folder

{
	"pageTitle": "Test Report",
}

or via adding a key to package.json named "jest-html-reporter":

{
	...
	"jest-html-reporter": {
		"pageTitle": "Test Report",
	}
}

๐Ÿ“Œ Configuration Options (All Optional)

OptionTypeDefaultDescription
additionalInformationArray<{ label: string; value: string; }>nullA list of additional information to be added to the top of the report.
appendbooleanfalseAppend test results to an existing report.
boilerplatestringnullPath to an HTML boilerplate file. The {jesthtmlreporter-content} variable will be replaced with test results.
collapseSuitesByDefaultbooleanfalseCollapse test suites (accordions) by default.
customScriptPathstringnullPath to an external script file injected into the report.
dateFormatstringyyyy-mm-dd HH:MM:ssDate format for timestamps. See documentation for available formats.
executionTimeWarningThresholdnumber5Warn if a test suite exceeds this execution time (in seconds).
hideConsoleLogOriginbooleanfalseHide console.log origin (stack trace) in the report (requires --verbose=false).
includeConsoleLogbooleanfalseInclude console.log outputs in the report (requires --verbose=false).
includeFailureMsgbooleanfalseShow detailed error messages for failed tests.
includeStackTracebooleantrueShow stack traces for failed tests.
includeSuiteFailurebooleanfalseShow detailed errors for entire failed test suites.
includeObsoleteSnapshotsbooleanfalseShow obsolete snapshot names.
logostringnullPath to an image file to display in the report header.
outputPathstring./test-report.htmlFull path for the output report file (must end in .html).
pageTitlestring"Test Report"Title of the document and top-level heading.
sortstringnullSort test results by a specific method. Available values:
โžค status โ†’ Sorts by test status (pending โ†’ failed โ†’ passed).
โžค status:{custom-order} โ†’ Custom status order (e.g., "status:failed,passed,pending").
โžค executionasc โ†’ Sorts by execution time ascending.
โžค executiondesc โ†’ Sorts by execution time descending.
โžค titleasc โ†’ Sorts by suite filename/test name ascending.
โžค titledesc โ†’ Sorts by suite filename/test name descending.
statusIgnoreFilterstringnullComma-separated list of statuses to exclude: "passed", "pending", "failed".
styleOverridePathstringnullPath to a CSS file to override default styles.
useCssFilebooleanfalseLink to the CSS file instead of inlining styles.
themestringdefaultThemeTheme that you are able to set to report (defaultTheme or darkTheme)

Continuous Integration

All the configuration options provided in the table above are available via environment variables and follows the pattern of snake case in uppercase prepended with JEST_HTML_REPORTER_

Example: customScriptPath -> JEST_HTML_REPORTER_CUSTOM_SCRIPT_PATH

*NOTE: Environment variables will take precedence over configurations set in jesthtmlreporter.config.json and package.json*

CI Example

Here is an example of dynamically naming your output file and test report title to match your current branch that one might see in a automated deployment pipeline before running their tests.

export BRANCH_NAME=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`
export JEST_HTML_REPORTER_OUTPUT_PATH=/home/username/jest-test-output/test-reports/"$BRANCH_NAME".html
export JEST_HTML_REPORTER_PAGE_TITLE="$BRANCH_NAME"\ Test\ Report