Jest

Jest is a testing framework for Javascript and Typescript.

Enabling XML Output

Configure Jest to produce JUnit XML output.

npm install --save-dev jest-junit

Update your Jest config (jest.config.json or similar file) to add jest-junit as a reporter.

jest.config.json

{
  "reporters": [ "default", "jest-junit" ]
}

With this configuration, Jest runs with by default output a junit.xml file in the working directory. To further configure the reporter, consult the detailed documentation on GitHub.

Test Suite Naming

The jest-junit reporter will automatically fill in values for the and name and class attributes using the description parameters to the tests. The testsuites.name is set to jest tests by default.

To make it easier to debug, it is also useful to include the name of the file that the failing test is in. You can do this by adding this to the jest.config.json file.

       "addFileAttribute": "true"

For example, this test:

describe('addition', () => {
  describe('positive numbers', () => {
    it('should add up', () => {
      expect(1 + 2).toBe(3);
    });
  });
});

would produce output that looks like this:

<testsuites name="jest tests">
  <testsuite name="addition">
    <testcase classname="addition positive numbers should add up" 
              name="addition positive numbers should add up"
              file="src/math.test.js"
              >
    </testcase>
  </testsuite>
</testsuites>

The default attributes can be changed using jest-junit configuration settings.

Further Information

See an example of running Jest inside of a GitHub action here.

Jest is highly customizable. See more at the Jestjs.io homepage.

Last updated