1 | import { commonTokens, tokens } from '@stryker-mutator/api/plugin';
|
2 | import semver from 'semver';
|
3 | import { pluginTokens } from '../plugin-di.js';
|
4 | import { JestLessThan25TestAdapter } from './jest-less-than-25-adapter.js';
|
5 | import { JestGreaterThan25TestAdapter } from './jest-greater-than-25-adapter.js';
|
6 | export 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 | }
|
17 | jestTestAdapterFactory.inject = tokens(commonTokens.logger, pluginTokens.jestWrapper, commonTokens.options, commonTokens.injector);
|
18 | function 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 |
|
\ | No newline at end of file |