UNPKG

1.72 kBJavaScriptView Raw
1import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
2import semver from 'semver';
3import { pluginTokens } from '../plugin-di.js';
4import { JestLessThan25TestAdapter } from './jest-less-than-25-adapter.js';
5import { JestGreaterThan25TestAdapter } from './jest-greater-than-25-adapter.js';
6export function jestTestAdapterFactory(log, jestWrapper, options, injector) {
7 const version = jestWrapper.getVersion();
8 log.debug('Detected Jest version %s', version);
9 guardJestVersion(version, options, log);
10 if (semver.satisfies(version, '<25.0.0')) {
11 return injector.injectClass(JestLessThan25TestAdapter);
12 }
13 else {
14 return injector.injectClass(JestGreaterThan25TestAdapter);
15 }
16}
17jestTestAdapterFactory.inject = tokens(commonTokens.logger, pluginTokens.jestWrapper, commonTokens.options, commonTokens.injector);
18function guardJestVersion(jest, options, log) {
19 if (semver.satisfies(jest, '<22.0.0')) {
20 throw new Error(`You need Jest version >= 22.0.0 to use the @stryker-mutator/jest-runner plugin, found ${jest}`);
21 }
22 else if (semver.satisfies(jest, '<24')) {
23 if (options.coverageAnalysis !== 'off') {
24 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".`);
25 }
26 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);
27 }
28}
29//# sourceMappingURL=jest-test-adapter-factory.js.map
\No newline at end of file