Make programming easier

Multiple testResultsProcessors with JEST

Introduction

Łukasz Kużyński

Łukasz Kużyński

Frontend and backend developer with almost 10 year of experience. Passionated about programming, computers and how things work.


Multiple testResultsProcessors with JEST

Posted by Łukasz Kużyński on .
Featured

Multiple testResultsProcessors with JEST

Posted by Łukasz Kużyński on .

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

Łukasz Kużyński

Frontend and backend developer with almost 10 year of experience. Passionated about programming, computers and how things work.

View Comments...