stryker-mutator / stryker-js

Mutation testing for JavaScript and friends
https://stryker-mutator.io
Apache License 2.0
2.58k stars 248 forks source link

Stryker `jest-runner` fails with jest prerelease versions above v27 when `coverageAnalysis` is set to "perTest" #5015

Open rriski opened 5 days ago

rriski commented 5 days ago

Summary

Stryker jest-runner crashes with Cannot read properties of undefined (reading 'getEnv') at this line https://github.com/stryker-mutator/stryker-js/blob/2faded7848d67ec306e1f65a00586c5cd3f6604d/packages/jest-runner/src/jest-plugins/jasmine2-setup-coverage-analysis.cts#L2 with these options: "testRunner": "jest","coverageAnalysis": "perTest"` when running with a jest prerelease version (e.g. latest jest prerelease version at the time is 30.0.0-alpha.6.

The bug is triggered when coverageAnalysisis set to perTest as that invokes withCoverageAnalysis that in turn uses semver package to test the jest current version and checks if its >= 27. This check fails when using a prerelease version:

> semver.satisfies('30.0.0-alpha.6', '>=27')
false
> semver.satisfies(semver.coerce('30.0.0-alpha.6'), '>=27')
true

Stryker config

Relevant config options to trigger the bug are "testRunner": "jest" and "coverageAnalysis": "perTest" withCoverageAnalysis that in turn checks the jest version to set some configuration options. The version check doesn't coerce prerelease versions so the else branch is taken here for jest version 30.0.0-alpha.6.

{
  "$schema": "./node_modules/@stryker-mutator/core/schema/stryker-schema.json",
  "testRunner": "jest",
  "reporters": [
    "progress",
    "clear-text",
    "html"
  ],
  "dryRunTimeoutMinutes": 20,
  "timeoutMS": 1200000,
  "incremental": true,
  "coverageAnalysis": "perTest",
  "logLevel": "trace",
  "checkerNodeArgs": ["--max-old-space-size=8192"],
  "testRunnerNodeArgs": ["--max-old-space-size=8192"],
  "plugins": ["@stryker-mutator/jest-runner"],
  "jest": {
    "projectType": "custom",
    "configFile": "jest.config.js",
    "enableFindRelatedTests": false
  },
  "ignorePatterns": [
    "index.html"
  ]
}

Test runner config

No relevant

Stryker environment

+-- @stryker-mutator/core@^8.5.0
+-- @stryker-mutator/jest-runner@^8.5.0
+-- jest@30.0.0-alpha.6

Test runner environment

Not relevant

Your Environment

Not relevant

rriski commented 5 days ago

PR with the fix: https://github.com/stryker-mutator/stryker-js/pull/5016