Jest

A guide for generating Trunk-compatible test reports for Jest tests

1. Generate JUnit

Install the jest-junit package:

npm install --save-dev jest-junit

Update your Jest config to add jest-junit as a reporter:

jest.config.json
{
  "reporters": [
    [
      "jest-junit",
      {
        "outputDirectory": "./test_results",
        "outputName": "report.xml",
        "addFileAttribute": "true"
      }
    ]
  ]
}

2. Output Location

The outputDirectory and outputName specify the location of the JUnit test report. In the example above, the JUnit would be at ./test_results/report.xml.

Disable Retries

You need to disable automatic retries if you previously enabled them. Retries compromise the accurate detection of flaky tests.

If you have retries configured using the jest.retryTimes method, disable them for more accurate results.

Next Step

JUnit files generated with Jest are compatible with Trunk Flaky Tests. See CI Providers for a guide on how to upload test results to Trunk.

Last updated