Search code examples
javascriptnode.jsjenkinsstryker

Jenkins build fail for reason stryker score


The goal is to fail the build of the pipeline when the stryker scores lower than X. How it can be configured in the Jenkins file or some other approach?

The stryker conf:

  config.set({
    mutator: "javascript",
    mutate: [...],
    testRunner: "jest",
    jest: {
      projectType: "node",
      config: require("jest.config.js"),
      enableFindRelatedTests: true,
    },
    loglevel: "trace",
    packageManager: "yarn",
    reporters: ["html", "clear-text", "progress", "dashboard"],
    transpilers: [],
    coverageAnalysis: "off",
  });

The piece of Jenkins file:

 "Stryker test": {
stage('Mutation') {
node("${containerName}") {
container("${containerName}") {
unstash name: 'myApp'
dir("./my") {
sh '''hostname
./node_modules/.bin/stryker run
'''
}

Solution

  • You can achieve this using the thresholds configuration. For example, Stryker will error (exit-code 1) on scores below 40 with the following configuration:

      config.set({
        thresholds: { high: 80, low: 60, break: 40 }
        ...
      });
    

    This means the result for your mutation score will be:

    • mutation score >= 80: Awesome! Reporters should color this green and happy.
    • high > mutation score >= 60: Warning! Reporters should color this orange/yellow. Watch yourself! Nothing will break, however.
    • mutation score < 60: Danger! Reporters should color this in red. You're in danger, but still exit-code 0
    • mutation score < 40: Error! Stryker will exit with exit code 1, indicating a build failure. No consequence for reporters, though.