Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rriski opened this issue Sep 17, 2024 · 1 comment
Labels
🐛 Bug Something isn't working

Comments

@rriski
Copy link
Contributor

rriski commented Sep 17, 2024

Summary

Stryker jest-runner crashes with Cannot read properties of undefined (reading 'getEnv') at this line

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 rriski added the 🐛 Bug Something isn't working label Sep 17, 2024
rriski added a commit to rriski/stryker-js that referenced this issue Sep 17, 2024
Previously, stryker failed `jasmine2-setup-coverage-analysis.cts`

    runTest ... node_modules/jest-runner/build/index.js:340:7), Cannot read
    properties of undefined (reading 'getEnv') TypeError: Cannot read properties
    of undefined (reading 'getEnv')

When using the latest jest prerelease version (30.0.0-alpha.6)

This commit fixes the error by using `semver.coerce`:

    > semver.satisfies('30.0.0-alpha.6', '>=27')
    false
    > semver.satisfies(semver.coerce('30.0.0-alpha.6'), '>=27')
    true
@rriski
Copy link
Contributor Author

rriski commented Sep 17, 2024

PR with the fix: #5016

nicojs added a commit that referenced this issue Sep 29, 2024
Support jests prerelease versions, like "30.0.0-alpha.6".

---------

Co-authored-by: Nico Jansen <jansennico@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant