UNPKG

2.43 kBPlain TextView Raw
1import { TestRunner } from '@stryker-mutator/api/test-runner';
2import { FileDescriptions, StrykerOptions } from '@stryker-mutator/api/core';
3import { tokens, commonTokens } from '@stryker-mutator/api/plugin';
4import { LoggerFactoryMethod } from '@stryker-mutator/api/logging';
5
6import { LoggingClientContext } from '../logging/index.js';
7import { coreTokens } from '../di/index.js';
8import { Sandbox } from '../sandbox/sandbox.js';
9
10import { IdGenerator } from '../child-proxy/id-generator.js';
11
12import { RetryRejectedDecorator } from './retry-rejected-decorator.js';
13import { TimeoutDecorator } from './timeout-decorator.js';
14import { ChildProcessTestRunnerProxy } from './child-process-test-runner-proxy.js';
15import { CommandTestRunner } from './command-test-runner.js';
16import { MaxTestRunnerReuseDecorator } from './max-test-runner-reuse-decorator.js';
17import { ReloadEnvironmentDecorator } from './reload-environment-decorator.js';
18
19createTestRunnerFactory.inject = tokens(
20 commonTokens.options,
21 commonTokens.fileDescriptions,
22 coreTokens.sandbox,
23 coreTokens.loggingContext,
24 commonTokens.getLogger,
25 coreTokens.pluginModulePaths,
26 coreTokens.workerIdGenerator
27);
28export function createTestRunnerFactory(
29 options: StrykerOptions,
30 fileDescriptions: FileDescriptions,
31 sandbox: Pick<Sandbox, 'workingDirectory'>,
32 loggingContext: LoggingClientContext,
33 getLogger: LoggerFactoryMethod,
34 pluginModulePaths: readonly string[],
35 idGenerator: IdGenerator
36): () => TestRunner {
37 if (CommandTestRunner.is(options.testRunner)) {
38 return () => new RetryRejectedDecorator(() => new TimeoutDecorator(() => new CommandTestRunner(sandbox.workingDirectory, options)));
39 } else {
40 return () =>
41 new RetryRejectedDecorator(
42 () =>
43 new ReloadEnvironmentDecorator(
44 () =>
45 new MaxTestRunnerReuseDecorator(
46 () =>
47 new TimeoutDecorator(
48 () =>
49 new ChildProcessTestRunnerProxy(
50 options,
51 fileDescriptions,
52 sandbox.workingDirectory,
53 loggingContext,
54 pluginModulePaths,
55 getLogger(ChildProcessTestRunnerProxy.name),
56 idGenerator
57 )
58 ),
59 options
60 )
61 )
62 );
63 }
64}