1 | import { StrykerOptions } from '@stryker-mutator/api/core';
|
2 | import { commonTokens, PluginKind, tokens } from '@stryker-mutator/api/plugin';
|
3 | import {
|
4 | TestRunner,
|
5 | DryRunOptions,
|
6 | MutantRunOptions,
|
7 | MutantRunResult,
|
8 | DryRunResult,
|
9 | DryRunStatus,
|
10 | MutantRunStatus,
|
11 | TestRunnerCapabilities,
|
12 | } from '@stryker-mutator/api/test-runner';
|
13 | import { errorToString } from '@stryker-mutator/util';
|
14 |
|
15 | import { coreTokens, PluginCreator } from '../di/index.js';
|
16 |
|
17 | export class ChildProcessTestRunnerWorker implements TestRunner {
|
18 | private readonly underlyingTestRunner: TestRunner;
|
19 |
|
20 | public static inject = tokens(commonTokens.options, coreTokens.pluginCreator);
|
21 | constructor({ testRunner }: StrykerOptions, pluginCreator: PluginCreator) {
|
22 | this.underlyingTestRunner = pluginCreator.create(PluginKind.TestRunner, testRunner);
|
23 | }
|
24 |
|
25 | public async capabilities(): Promise<TestRunnerCapabilities> {
|
26 | return this.underlyingTestRunner.capabilities();
|
27 | }
|
28 |
|
29 | public async init(): Promise<void> {
|
30 | if (this.underlyingTestRunner.init) {
|
31 | await this.underlyingTestRunner.init();
|
32 | }
|
33 | }
|
34 |
|
35 | public async dispose(): Promise<void> {
|
36 | if (this.underlyingTestRunner.dispose) {
|
37 | await this.underlyingTestRunner.dispose();
|
38 | }
|
39 | }
|
40 |
|
41 | public async dryRun(options: DryRunOptions): Promise<DryRunResult> {
|
42 | const dryRunResult = await this.underlyingTestRunner.dryRun(options);
|
43 | if (dryRunResult.status === DryRunStatus.Complete && !dryRunResult.mutantCoverage && options.coverageAnalysis !== 'off') {
|
44 |
|
45 | dryRunResult.mutantCoverage = global.__mutantCoverage__;
|
46 | }
|
47 | if (dryRunResult.status === DryRunStatus.Error) {
|
48 | dryRunResult.errorMessage = errorToString(dryRunResult.errorMessage);
|
49 | }
|
50 | return dryRunResult;
|
51 | }
|
52 | public async mutantRun(options: MutantRunOptions): Promise<MutantRunResult> {
|
53 | const result = await this.underlyingTestRunner.mutantRun(options);
|
54 | if (result.status === MutantRunStatus.Error) {
|
55 | result.errorMessage = errorToString(result.errorMessage);
|
56 | }
|
57 | return result;
|
58 | }
|
59 | }
|