Jenkins integration with Jest

We will use Jest-junit test reporter to integrate jest results with Jenkins.

Installation

npm install -D jest jest-junit

Configuration

Add to package.json:

"scripts": {
  ...
  "test": "jest"
}

Add to Jenkinsfile:

stage ('tests') {
  withEnv(["JEST_JUNIT_OUTPUT=./jest-test-results.xml"]) {
    sh 'npm test -- --ci --testResultsProcessor="jest-junit"'
  }
  junit 'jest-test-results.xml'
}