UNPKG

@stryker-mutator/core

Version:

The extendable JavaScript mutation testing framework

41 lines 1.49 kB
import { PluginKind, tokens, commonTokens } from '@stryker-mutator/api/plugin'; import { StrykerError } from '@stryker-mutator/util'; import { coreTokens } from '../di/index.js'; export class CheckerWorker { innerCheckers; static inject = tokens(commonTokens.options, coreTokens.pluginCreator); constructor(options, pluginCreator) { this.innerCheckers = new Map(options.checkers.map((name) => [ name, pluginCreator.create(PluginKind.Checker, name), ])); } async init() { for (const [name, checker] of this.innerCheckers.entries()) { try { await checker.init(); } catch (error) { throw new StrykerError(`An error occurred during initialization of the "${name}" checker`, error); } } } async check(checkerName, mutants) { return this.perform(checkerName, (checker) => checker.check(mutants)); } async group(checkerName, mutants) { return this.perform(checkerName, (checker) => checker.group?.(mutants) ?? // Group one by one by default mutants.map(({ id }) => [id])); } perform(checkerName, act) { const checker = this.innerCheckers.get(checkerName); if (checker) { return act(checker); } else { throw new Error(`Checker ${checkerName} does not exist!`); } } } //# sourceMappingURL=checker-worker.js.map