Skip to content

Commit

Permalink
fix: jest prerelease support (stryker-mutator#5015)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rriski committed Sep 17, 2024
1 parent 2faded7 commit 04ed6d9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const jestEnvironmentGenericFileName = fileURLToPath(new URL('./jest-environment
*/
function getJestDefaults(jestWrapper: JestWrapper) {
// New defaults since 27: https://jestjs.io/blog/2021/05/25/jest-27
if (semver.satisfies(jestWrapper.getVersion(), '>=27')) {
if (semver.satisfies(semver.coerce(jestWrapper.getVersion()), '>=27')) {
return {
testRunner: 'jest-circus/runner',
testEnvironment: 'node',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function jestTestAdapterFactory(
options: StrykerOptions,
injector: Injector<JestPluginContext>,
): JestGreaterThan25TestAdapter | JestLessThan25TestAdapter {
const version = jestWrapper.getVersion();
const version = semver.coerce(jestWrapper.getVersion());
log.debug('Detected Jest version %s', version);
guardJestVersion(version, options, log);

Expand Down

0 comments on commit 04ed6d9

Please sign in to comment.