Multiple testResultsProcessors with JEST

Published

Currently, "testResultsProcessor" option for JEST accepts only single module to process test results. Unfortunately this approach quickly becomes insufficient if you need code coverage remapping and junit reports for CircleCI.

Fortunately documentation for JEST is pretty good and says:

This option allows the use of a custom results processor. This processor must be a node module that exports a function expecting an object with the following structure as the first argument:

-- https://facebook.github.io/jest/docs/configuration.html#testresultsprocessor-string

So the final solution is very simple.

Create resultsProcessor.js file with the following content

module.exports = function () {
    require('../node_modules/ts-jest/coverageprocessor').apply(this, arguments);
    return require('../node_modules/jest-junit').apply(this, arguments);
    // add any other processor you need
};

Remember to update package.json too

{
  "jest": {
    "testResultsProcessor": "./resultsProcessor"
  }
}

UPDATE: I've added return for last function invocation. Without it JEST is unable to interpret test results and finish the JEST process with proper exit code.

Łukasz Kużyński - Wookieb
Thoughts, tips about programming and related subjects to make your job easier and more pleasant so you won't burnout quickly.
Copyright © Łukasz Kużyński - Wookieb 2023 • All rights reserved.