1 | import { MutantRunOptions, MutantRunResult, TestRunner } from '@stryker-mutator/api/test-runner';
|
2 |
|
3 | import { StrykerOptions } from '@stryker-mutator/api/core';
|
4 |
|
5 | import { TestRunnerDecorator } from './test-runner-decorator.js';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export class MaxTestRunnerReuseDecorator extends TestRunnerDecorator {
|
11 | public runs = 0;
|
12 | private readonly restartAfter;
|
13 |
|
14 | constructor(testRunnerProducer: () => TestRunner, options: Pick<StrykerOptions, 'maxTestRunnerReuse'>) {
|
15 | super(testRunnerProducer);
|
16 |
|
17 | this.restartAfter = options.maxTestRunnerReuse || 0;
|
18 | }
|
19 |
|
20 | public async mutantRun(options: MutantRunOptions): Promise<MutantRunResult> {
|
21 | this.runs++;
|
22 | if (this.restartAfter > 0 && this.runs > this.restartAfter) {
|
23 | await this.recover();
|
24 | this.runs = 1;
|
25 | }
|
26 |
|
27 | return super.mutantRun(options);
|
28 | }
|
29 |
|
30 | public dispose(): Promise<any> {
|
31 | this.runs = 0;
|
32 | return super.dispose();
|
33 | }
|
34 | }
|