UNPKG

@stryker-mutator/core

Version:

The extendable JavaScript mutation testing framework

51 lines 1.66 kB
import { DryRunStatus, MutantRunStatus, } from '@stryker-mutator/api/test-runner'; import { ExpirableTask } from '@stryker-mutator/util'; import { TestRunnerDecorator } from './test-runner-decorator.js'; /** * Wraps a test runner and implements the timeout functionality. */ export class TimeoutDecorator extends TestRunnerDecorator { log; constructor(log, producer) { super(producer); this.log = log; } async dryRun(options) { const result = await this.run(options, () => super.dryRun(options)); if (result === ExpirableTask.TimeoutExpired) { return { status: DryRunStatus.Timeout, }; } else { return result; } } async mutantRun(options) { const result = await this.run(options, () => super.mutantRun(options)); if (result === ExpirableTask.TimeoutExpired) { return { status: MutantRunStatus.Timeout, }; } else { return result; } } async run(options, actRun) { this.log.debug('Starting timeout timer (%s ms) for a test run', options.timeout); const result = await ExpirableTask.timeout(actRun(), options.timeout); if (result === ExpirableTask.TimeoutExpired) { await this.handleTimeout(); return result; } else { return result; } } async handleTimeout() { this.log.debug('Timeout expired, restarting the process and reporting timeout'); await this.recover(); } } //# sourceMappingURL=timeout-decorator.js.map