UNPKG

972 BPlain TextView Raw
1import { MutantRunOptions, MutantRunResult, TestRunner } from '@stryker-mutator/api/test-runner';
2
3import { StrykerOptions } from '@stryker-mutator/api/core';
4
5import { TestRunnerDecorator } from './test-runner-decorator.js';
6
7/**
8 * Wraps a test runner and implements the retry functionality.
9 */
10export 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}