Adding a junit formatter to jest test results for a Node.js app on Azure Pipelines

Photo by Sergi Kabrera on Unsplash

If you're publishing a Node.js app on Azure pipelines you will want to publish the output of your tests. The publish tests task on Azure has limited format support so you have to convert the test results to XML for processing.

I use junit format to publish result. There is a jest formatter on npm

yarn add -D jest-junit

then you need to add or edit jest.config.js so that it configures the reporters

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  reporters: ["default", "jest-junit"],
  setupFiles: ["./jest.setup-file.ts"],

This will output a junit.xml file in your root directory. You can pass this to the Azure DevOps Publish Test Results task.