-
Notifications
You must be signed in to change notification settings - Fork 76
Configuration
The way to configure this plugin depends on how it is invoked by Jest - either it is run as a "custom reporter" using the reporters
-option, or as a testResultsProcessor
. The first mentioned method has all its configuration residing in the same file (jest.config.js
), while the latter requires a separate configuration file. Please refer to the examples below for further information.
Configuration may also be performed with environment variables for dynamic file saving paths in different environments.
Please note that all configuration options are optional.
Property | Type | Description | Default |
---|---|---|---|
pageTitle |
STRING |
The title of the document. This string will also be outputted on the top of the page. | "Test Suite" |
outputPath |
STRING |
The path to where the plugin will output the HTML report. The path must include the filename and end with .html | "./test-report.html" |
includeFailureMsg |
BOOLEAN |
If this setting is set to true, this will output the detailed failure message for each failed test. | false |
includeConsoleLog |
BOOLEAN |
If set to true, this will output all triggered console logs for each test suite. | false |
styleOverridePath |
STRING |
The path to a file containing CSS styles that should override the default styling.* | null |
customScriptPath |
STRING |
Path to a javascript file that should be injected into the test report | null |
theme |
STRING |
The name of the reporter themes to use when rendering the report. Available themes are found in Test Report Themes | "defaultTheme" |
logo |
STRING |
Path to a logo that will be included in the header of the report | null |
executionTimeWarningThreshold |
NUMBER |
The threshold for test execution time (in seconds) in each test suite that will render a warning on the report page. 5 seconds is the default timeout in Jest. | 5 |
dateFormat |
STRING |
The format in which date/time should be formatted in the test report. Have a look at this page for the available date format variables. | "yyyy-mm-dd HH:MM:ss" |
sort |
STRING |
Sorts the test results with the given method. Available sorting methods can be found here. | "default" |
executionMode |
STRING |
Defines the execution mode. Avaiable modes are: reporter , testResultsProcessor
|
"testResultsProcessor" |
*The plugin will search for the styleOverridePath from the root directory, therefore there is no need to prepend the string with
./
or../
. Have a look at the defaultTheme for a reference of the elements available for styling.
The environment variables below reflect the default configuration options. Please refer to the list above for detailed information. NOTE: Environment variables will take precedence over configurations set in jesthtmlreporter.config.json and package.json
JEST_HTML_REPORTER_PAGE_TITLE
JEST_HTML_REPORTER_OUTPUT_PATH
JEST_HTML_REPORTER_INCLUDE_FAILURE_MSG
JEST_HTML_REPORTER_STYLE_OVERRIDE_PATH
JEST_HTML_REPORTER_CUSTOM_SCRIPT_PATH
JEST_HTML_REPORTER_THEME
JEST_HTML_REPORTER_LOGO
JEST_HTML_REPORTER_EXECUTION_TIME_WARNING_THRESHOLD
JEST_HTML_REPORTER_DATE_FORMAT
JEST_HTML_REPORTER_SORT
Add your configuration to jest.config.js
in the following manner:
"reporters": [
"default",
"./node_modules/jest-html-reporter", {
"pageTitle": "Your test suite",
"outputPath": "test-report/index.html",
"includeFailureMsg": false,
"styleOverridePath": "src/teststyle.css"
}
]
When running as a testResultProcessor, the configuration needs to be put in a separate file named jesthtmlreporter.config.json
placed within the root folder of the project:
{
"pageTitle": "Your test suite",
"outputPath": "test-report/index.html",
"includeFailureMsg": false,
"styleOverridePath": "src/teststyle.css"
}
It is also possible to configure the plugin with package.json
(although this is not recommended). Add an entry named "jest-html-reporter"
to your package.json like so:
{
...
"jest-html-reporter": {
"pageTitle": "Your test suite",
"outputPath": "test-report.html",
"includeFailureMsg": true
}
}
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