-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Support jests prerelease versions, like "30.0.0-alpha.6". --------- Co-authored-by: Nico Jansen <[email protected]>
- Loading branch information
Showing
4 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 18 additions & 10 deletions
28
packages/jest-runner/src/jest-test-adapters/jest-test-adapter-factory.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,52 @@ | ||
import { Logger } from '@stryker-mutator/api/logging'; | ||
import { StrykerOptions } from '@stryker-mutator/api/core'; | ||
import { commonTokens, Injector, tokens } from '@stryker-mutator/api/plugin'; | ||
import semver from 'semver'; | ||
import semver, { SemVer } from 'semver'; | ||
|
||
import { JestPluginContext, pluginTokens } from '../plugin-di.js'; | ||
import { JestWrapper } from '../utils/jest-wrapper.js'; | ||
|
||
import { JestLessThan25TestAdapter } from './jest-less-than-25-adapter.js'; | ||
import { JestGreaterThan25TestAdapter } from './jest-greater-than-25-adapter.js'; | ||
interface CoercedVersion { | ||
version: SemVer; | ||
raw: string; | ||
} | ||
|
||
function coerceVersion(version: string): CoercedVersion { | ||
return { version: semver.coerce(version)!, raw: version }; | ||
} | ||
|
||
export function jestTestAdapterFactory( | ||
log: Logger, | ||
jestWrapper: JestWrapper, | ||
options: StrykerOptions, | ||
injector: Injector<JestPluginContext>, | ||
): JestGreaterThan25TestAdapter | JestLessThan25TestAdapter { | ||
const version = jestWrapper.getVersion(); | ||
log.debug('Detected Jest version %s', version); | ||
guardJestVersion(version, options, log); | ||
const coercedVersion = coerceVersion(jestWrapper.getVersion()); | ||
log.debug('Detected Jest version %s', coercedVersion.raw); | ||
guardJestVersion(coercedVersion, options, log); | ||
|
||
if (semver.satisfies(version, '<25.0.0')) { | ||
if (semver.satisfies(coercedVersion.version, '<25.0.0')) { | ||
return injector.injectClass(JestLessThan25TestAdapter); | ||
} else { | ||
return injector.injectClass(JestGreaterThan25TestAdapter); | ||
} | ||
} | ||
jestTestAdapterFactory.inject = tokens(commonTokens.logger, pluginTokens.jestWrapper, commonTokens.options, commonTokens.injector); | ||
|
||
function guardJestVersion(jest: string, options: StrykerOptions, log: Logger) { | ||
if (semver.satisfies(jest, '<22.0.0')) { | ||
throw new Error(`You need Jest version >= 22.0.0 to use the @stryker-mutator/jest-runner plugin, found ${jest}`); | ||
} else if (semver.satisfies(jest, '<24')) { | ||
function guardJestVersion({ version, raw }: CoercedVersion, options: StrykerOptions, log: Logger) { | ||
if (semver.satisfies(version, '<22.0.0')) { | ||
throw new Error(`You need Jest version >= 22.0.0 to use the @stryker-mutator/jest-runner plugin, found ${raw}`); | ||
} else if (semver.satisfies(version, '<24')) { | ||
if (options.coverageAnalysis !== 'off') { | ||
throw new Error( | ||
`You need Jest version >= 24.0.0 to use the @stryker-mutator/jest-runner with "coverageAnalysis": "${options.coverageAnalysis}", you're currently using version 23.0.0. Please upgrade your jest version, or set "coverageAnalysis": "off".`, | ||
); | ||
} | ||
log.warn( | ||
'[DEPRECATED] Support for Jest version < 24 is deprecated and will be removed in the next major version of Stryker, please upgrade your jest version (your current version is %s).', | ||
jest, | ||
raw, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters