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.

Hey! Are you a developer?

🚀 Set Up Your Dev Environment in Minutes, Not Hours!

Tired of spending hours setting up a new development machine? I used to be, too—until I automated the entire process!

Now, I just run a single script, grab a coffee, and let my setup take care of itself.

Save 30+ hours configuring a new Mac or Windows (WSL) development environment.
Ensure consistency across all your machines.
Eliminate tedious setup and get coding faster!
Get Instant Access →