Make programming easier

Introduction
Multiple testResultsProcessors with JEST

Multiple testResultsProcessors with JEST

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.

Author

wookieb

Fullstack developer with 10 years of experience. Passionated about programming, computers and how things work.

View Comments
Next Post

AMQP retry message consumption with delay - when ACK and REJECT is not enough

Previous Post

Is Singleton pattern really that bad?